How to plot harmonic components of a sine wave

42 views (last 30 days)
I have a Sine wave signal as a column vector (this Sine signal was generated from another software 'LabVIEW' and then imported to Matlab and saved as a column vector). I want to find the magnitudes of specific harmonic components (such as 3rd and 5th harmonic) of this signal. At first I have tried to use the 'fft' function that converts my time domain signal to the frequency domain. This plots (barplot) frequency Vs. magnitude of the Sine signal. But, I want to plot(barplot) Harmonic order (X axis) Vs. magnitude (Y-axis) and see for example the magnitude of the 3rd harmonic component of the signal. I must be able to extract the value of H (harmonic order) which is not possible from the fft plot. I have attached here the .m file I am working on. I am not attaching the 'Sine' wave as it is okay if you use any sine wave with harmonics. I am more interested to know the plotting method to see harmonic orders with magnitudes (sample picture also attached).
Thanks a lot for your help. I really appreciate.
  7 Comments
magesh radha
magesh radha on 13 Sep 2015
Im doing DC to AC converter without using of filter, and i got 22% of THD . and i need to reduce the harmonics any one can help me to do..
Marcelo Vinicius de Paula
Marcelo Vinicius de Paula on 18 Nov 2020
You can add a capacitor to the output of the inverter, also, try using a unipolar PWM.

Sign in to comment.

Accepted Answer

dpb
dpb on 3 Jun 2015
To plot versus the harmonic number you first must determine what the fundamental frequency of the signal is (either in Hz transforming the axes based on sample rate used or simply as the position number in the transform vector) . Once you have that, then the harmonics are at the ratios of that location accounting, of course, for rounding in that it's unlikely excepting for made-up inputs that the frequency of the signal will exactly match the frequency binning.
The PSD is generally easier than the straight FFT; see the
doc fft
for an example of building and normalizing a time history to a PSD in frequency domain.
  3 Comments
dpb
dpb on 3 Jun 2015
As noted above, if you have a given sampling frequency Fs and length of the fft, NFFT, then
f = Fs/2*linspace(0,1,NFFT/2+1);
is the frequency associated with the (one-sided) PSD. For a given base frequency F, then
fHar=f/F; % Standardize to harmonic reference
The n_th_ harmonic will be at the bin nearest the locations n*fix(fHar)==n*fHar; as noted unless you fix the sampling rate and times precisely there won't necessarily be a frequency bin at, say, 50 Hz identically.

Sign in to comment.

More Answers (1)

Honglei Chen
Honglei Chen on 3 Jun 2015
You can use thd for this, although it's not in the bar plot. But once you have the information, you can plot it yourself.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!