0
\$\begingroup\$

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

enter image description here

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

enter image description here

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

enter image description here

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.

enter image description here

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:

enter image description here

\$\endgroup\$
3
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – Chris Stratton Dec 26 '19 at 20:18
  • 1
    \$\begingroup\$ Try Mag/Phase and Log View then point at wave or draw falstad.com/fourier 25 Is your fundamental not 2nd harmonic \$\endgroup\$ – Tony Stewart EE75 Dec 26 '19 at 21:12
  • 1
    \$\begingroup\$ There is no possibility for existence of any harmonic of 0Hz, because n * 0Hz is still 0Hz :) :) \$\endgroup\$ – VillageTech Dec 26 '19 at 22:06
5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – Chris K8NVH Dec 26 '19 at 19:54
  • \$\begingroup\$ @ChrisK8NVH I'm affraid I didn't get tat 13 V dc offset :( \$\endgroup\$ – Rafael Alencar Dec 26 '19 at 20:16
  • 1
    \$\begingroup\$ I misread the graph; thought the original wave amplitude was 27 volts, not 2.7. My bad. Sorry for the confusion. \$\endgroup\$ – Chris K8NVH Dec 27 '19 at 5:47
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ I think this is incorrect. The fundamental frequency is the sinusoidal component with the lowest frequency . A DC offset is not a sinusoidal component. \$\endgroup\$ – Huisman Dec 26 '19 at 21:30
  • 3
    \$\begingroup\$ @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). \$\endgroup\$ – jms Dec 26 '19 at 22:34
  • \$\begingroup\$ 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. \$\endgroup\$ – jms Dec 26 '19 at 22:47
  • \$\begingroup\$ @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? \$\endgroup\$ – Huisman Dec 27 '19 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.