# Testing the accuracy of FFT analysis on a Rigol scope

- Take a square wave as exercise for fast Fourier spectrum analysis
- The Fourier analysis of a square wave
- How to interpret de FFT data from a scope?
- What is the accuracy of FFT analysis on a scope?
- What is dBV and how to calculate it back to Volt?
- How to choose the scope settings for FFT analysis?
- How to get the optimal time base setting for FFT analysis
- How to choose the optimal FFT window function?

I’m developing a fast battery charger and to check whether it meet the EMC limits for harmonic currents, I need to analyze the spectrum with FFT analysis. To do so, I had to find out how it works on my scope and to check if what I'm doing is correct. Strangely enough, I didn't find what I was looking for on the internet, that is why I wrote this article.

### Take a square wave as exercise for fast Fourier spectrum analysis

Understanding spectrum analysis is not that easy and certainly not if you have been out of school for 40 years like me. To be sure that you get reliable FFT results, you can first practice with a square wave from which the harmonics are known. If all goes well than the FFT results exactly match the theoretical values obtained with Fourier analysis. Then you know for sure that the measurements are correct and that you interpret the data correctly. Because I want to measure the mains current, which is 50Hz, I use a square wave of also 50Hz. I use a UNI-T UTG962 function generator for this. The amplitude is 5Vrms.

### The Fourier analysis of a square wave

See Wikipedia for the square wave.

Note that the amplitude of a square wave of 5Vrms is also 5V, so the whole formula has to be multiplied by 5.

With the formula above, the 5V square wave can be composed by the sum of the following series of sine voltages:

U(t) = 5*4/π (sin(2π50t) + 1/3sin(2π150t) + 1/5sin(2π250t) + 1/7sin(2π350t) + 1/9sin(2π450t)… )

### How to interpret de FFT data from a scope?

With FFT, the amplitudes of the harmonics are displayed in Vrms, but the amplitudes in the formula are the peak voltages. So, the amplitudes must be divided by √2 to get the rms values.

For instance, the values for harmonic 3 are calculated as follows:

f=3x50Hz=150Hz

Vpeak = 1/3 * 5V * 4/π = 2.12V

Vrms = 2,12 / √2= 1.5V

If we calculate all harmonics at the same way, we get this table:

Harmonic | Freq | Vtop | Vrms |

1 | 50 | 6.37 | 4.50 |

3 | 150 | 2.12 | 1.50 |

5 | 250 | 1.27 | 0.90 |

7 | 350 | 0.91 | 0.64 |

9 | 450 | 0.71 | 0.50 |

Thus, the harmonics measured with FFT analysis should be 4.5V, 1.5V etc.

### What is the accuracy of FFT analysis on a scope?

With FFT, the values are showed in dBV by default. But, for simplicity, I start with Vrms readings instead of dBV. Here you see how my Rigol MSO5104 performs the square wave FFT analysis:

Harmonic | Freq | Vtop | Vrms | Vrms scope | Error [%] |

1 | 50 | 6.37 | 4.50 | 4.54 | 0.9 |

3 | 150 | 2.12 | 1.50 | 1.55 | 3.3 |

5 | 250 | 1.27 | 0.90 | 0.928 | 3.1 |

7 | 350 | 0.91 | 0.64 | 0.646 | 0.5 |

9 | 450 | 0.71 | 0.50 | 0.514 | 2.8 |

As we can see, the Vrms values of the first 5 harmonics, are within 3% of the theoretical values. Note that, as we will see later, I have experimented beforehand to determine the optimal scope settings.

Here is the result with the more common unit dBV:

### What is dBV and how to calculate it back to Volt?

dBV is the logarithmical voltage relative to 1 volt, regardless of impedance.

dBV = 20log(V)

V = 10^(dBV/20)

For instance, the Vrms for harmonic 3 is calculated as follows:

FFT value = 3.809dBV

Vrms= 10^(3.81/20) = 1.55V

If we calculate all harmonics at the same way, we get this table:

Harmonic | Freq | Vtop | Vrms | dBV scope | Vrms scope | Error [%] |

1 | 50 | 6.37 | 4.50 | 13.1 | 4.52 | 0.4 |

3 | 150 | 2.12 | 1.50 | 3.81 | 1.55 | 3.3 |

5 | 250 | 1.27 | 0.90 | -0.655 | 0.93 | 3.0 |

7 | 350 | 0.91 | 0.64 | -3.81 | 0.64 | 0.3 |

9 | 450 | 0.71 | 0.50 | -5.79 | 0.51 | 2.7 |

As we can see, the values of the first 5 harmonics in dBV are within 3% of the theoretical values.

### How to choose the scope settings for FFT analysis?

The time base and the so-called window are the critical settings for FFT measurements. You can determine these as follow: Suppose you want to measure a signal of 50Hz. Then first measure a square wave of 50Hz as described above. Then play with the settings so that the measured values correspond as much as possible with the theoretical values. We can then assume that these settings are the best for all kinds of 50Hz signals.

### How to get the optimal time base setting for FFT analysis

The time base setting is critical for FFT analysis. For the 50Hz square wave signal, I tested the range 100ms to 1s. Only 200ms and 500ms are accurate, 100ms and 1s are not accurate:

### How to choose the optimal FFT window function?

Windowing is the kind of method used by the scope to correct the errors that are inherent with FFT.

The default window function of the Rigol scope is Hanning. However, this is not the best choice for our example. With Hanning, the 3th harmonic is not 1,5V as it should be but 1.352V:

So, I tried all window functions and came to the conclusion that the Flat top window has the most accurate readings for our 50Hz signal.