T = 3*(1/25);
fs = 1000;
t = 0:1/fs:T-1/fs;
x = sawtooth(2*pi*25*t,1/2);
x = (x + 1)*0.5;
grid on
xlabel('Time t (sec)')

My Signal

This is my code and my signal. I want to find its fifth and seventh harmonics. How can I do that ? I cannot find any source or any example for this. Can anybody help me ?


  • $\begingroup$ Harmonics are usually defined for periodic signals. The usual approach is to find the signal's Fourier Series; each term of the series is a harmonic. Can you clarify your definition of harmonic, and why do you need to do this in Matlab? $\endgroup$ – MBaz Apr 18 at 20:34
  • $\begingroup$ I am trying to learn Matlab. For example, I want to sum first harmonic and fifth harmonic. After that, I will sum first and ninth harmonic and I will compare these two with my original signal. $\endgroup$ – Oğuzhan Kırlar Apr 18 at 20:39
  • $\begingroup$ I would use Fourier Series to find the harmonics, then Matlab to generate them and add them. $\endgroup$ – MBaz Apr 18 at 21:20

Your sawtooth waveform is periodic with a time period of $T = 0.04s$, therefore basic frequency is $\frac{1}{T} = 25Hz$, so to find $5^{th}$ and $7^{th}$ harmonic, project this signal/correlate the signal over any period T with this harmonic. Let $tr(t)$ denote the trinagluar waveform over 1 period. For ex: $$a_5 = \frac{2}{T}\int_{t=0}^T tr(t)Cos(2\pi*5*25t)\,dt$$ similarly $$a_7 = \frac{2}{T}\int_{t=0}^Ttr(t)Cos(2\pi*7*25t)\,dt$$ where $a_5$, $a_7$ denote the coefficients of the $5^{th}$ and $7^{th}$ harmonic.

The $5^{th}$ harmonic would therefore be $a_5Cos(2\pi*5*25*t)$ and $7^{th}$ hamonic is $a_7Cos(2\pi*7*25*t)$

| improve this answer | |
  • $\begingroup$ f5 = @(t)t.*cos(2.*pi.*5.*25.*t); a5 = integral(f5,0,0.04); a55 = a5.*cos(2.*pi.*5.*25.*t); subplot(3,1,2) plot(t,a55) I write this code and output didn't seem right to me. Am I wrong or is it true ? (I am adding output to the question ) $\endgroup$ – Oğuzhan Kırlar Apr 19 at 12:18
  • $\begingroup$ Use sawtooth function in Matlab to generate the trinagluar waveform, fs = 1000; t = 0:1/fs:0.04; x = sawtooth(2*pi*25*t,1/2); to generate 1 period. Then define, tra=cos (2*pi*5*25*t), a5 = int(tra."x,0,0.04) $\endgroup$ – Dsp guy sam Apr 19 at 12:32
  • $\begingroup$ I just add the above code and take this output but okey i will try it now, thank you. $\endgroup$ – Oğuzhan Kırlar Apr 19 at 12:34
  • $\begingroup$ Just saw your sawtooth wave goes from 0 to 1 so scale the sawtooth function by 1/2 and add 1/2 to each samples i.e.x = 1/2.*sawtooth(2*pi*25*t,1/2) + 1/2.*ones(1, length (t)) $\endgroup$ – Dsp guy sam Apr 19 at 12:34

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.