FFT of a square wave

I'm generating a square wave as PWM whose frequency is set to 25 Hz. On the oscilloscope, I've got:

The data referred to the image above was stored and maniputed, then I plot it using jupyter notebook, as shown below:

Applying the FFT to that signal,I've got:

The main question is: wasn't the main peak (the 2.7 V) supposed to be near 25 Hz?

UPDATE: I just did the corrections that you tell and the visualization is better! I'm still obtaining the main peak in 0 Hz, but the second harmonic is in 25 Hz ( but the amplitude is low). I also didn't get the 13 V dc offset that Chris pointed out.

UPDATE 2: I subtracted the average dc level (1.35 V) from the signal as most of you told me and I got the result I believe it's correct now:

• AC couple the scope and you will lose a lot of the DC offset which is the strong component correctly shown a 0 frequency which is confusing you. Consider comparing the measurements to an all math simulation in order to inform your expectation. Dec 26 '19 at 20:18
• Try Mag/Phase and Log View then point at wave or draw falstad.com/fourier 25 Is your fundamental not 2nd harmonic Dec 26 '19 at 21:12
• There is no possibility for existence of any harmonic of 0Hz, because n * 0Hz is still 0Hz :) :) Dec 26 '19 at 22:06

Your signal is a square wave with its base at 0V and its peak at 2.7V or so. So it has an average voltage of 1.35V. In the frequency domain, the overall average of a signal is its content at DC or 0Hz -- so that's why there's a peak at 0Hz.

The FFT of a square wave that is centered on 0V has energy at every odd harmonic, starting at 1. So there's energy at 1f, 3f, 5f, etc.

I'd make this a comment, but I don't have enough points to do that yet.

You should plot your FFT data starting at 0 Hz and go up to, say, 500 Hz. That will give you 10 or so harmonics. You are probably zoomed too far out in the frequency domain(x-axis) to get much detail and realize what's going on here.

And yes, the fundamental should be at 25 Hz.

• @rafaelalencar There is also a zero Hz component (DC offset) of about 13 volts. I agree with CalMachine that you are probably zoomed out too far to see the details you are looking for. Dec 26 '19 at 19:54
• @ChrisK8NVH I'm affraid I didn't get tat 13 V dc offset :( Dec 26 '19 at 20:16
• I misread the graph; thought the original wave amplitude was 27 volts, not 2.7. My bad. Sorry for the confusion. Dec 27 '19 at 5:47

A DC offset will create a big spike at 0 Hz. Remove it to see the AC content (fundamental frequency and harmonics of your square wave).

You can remove the DC offset by subtracting the average level of the waveform before the DFT or FFT.

The fundamental will be at 0Hz because you have a DC offset. There is no negative component to your signal.

• I think this is incorrect. The fundamental frequency is the sinusoidal component with the lowest frequency . A DC offset is not a sinusoidal component. Dec 26 '19 at 21:30
• @Huisman While it is debatable if a DC offset counts as the fundamental frequency, a DC offset is a sinusoidal component (just at 0 Hz).
– jms
Dec 26 '19 at 22:34
• Whenever you compute a DFT from a real-valued signal, each negative frequency bin is just the complex conjugate of the corresponding positive frequency bin. Hence, there is a negative component in the result (and it can be seen in OP's first plot) but it's redundant information. Note that OP's plot is not the complex-valued raw output of the FFT algorithm, as what has been plotted is only the magnitude of each frequency bin, and the negative and positive frequencies have been swapped (0 Hz is in the middle) so that the result is more intuitive.
– jms
Dec 26 '19 at 22:47
• @jms I should have added: "A DC offset is not a sinusoidal component when describing a signal as a Fourier series $V_t = \dfrac{a_0}{2} + \displaystyle \sum_{i=1}^{\infty}[a_i sin(i \omega_0 t) + b_i cos(i \omega_0 t) ]$ . Next, if 0 Hz is the fundamental, what are the higher harmonics? 1*0Hz, 2*0Hz, 3*0Hz etc? Dec 27 '19 at 11:49