How to plot this sawtooth wave and its fourier approximation
97 ビュー (過去 30 日間)
古いコメントを表示
I am trying to plot this wave and its fourier approximation for first 5 harmonics. This is what I want the final result to be like (note the wave approximated in the picture is a square wave)

This is the wave I want to approximate:

I know how to plot a sawtooth wave using the sawtooth funciton I was confused by the delay between the sawtooths in the picture. I tried using a piecewise function repeated 3 times to generate the wave.
f = @(x)[.5*x.*(0<=x & x<=2) + 0.*(2<=x & x<=3) + ((.5*x)-1.5).*(3<=x & x<=5)];
x = linspace(0,3);
intvl = [-6 6];
pfx = repmat(f(x+1),1,diff(intvl)/3);
px = linspace(intvl(1),intvl(2),length(pfx));
figure(1)
plot(px, pfx)
grid
This code can generate the sawtooth wave with some problems as shown here:

Now my question is how to properly plot the function in the original question then plot a fourier transform for it. The fourier transform for this normal sawtooth below is given where L is half the length of the sawtooth.


0 件のコメント
回答 (4 件)
Utkarsh Belwal
2019 年 6 月 11 日
編集済み: Utkarsh Belwal
2019 年 6 月 11 日
freq = 1 ; % Sawtooth frequency 1Hz
T = 4 * freq ;
fs = 1000; % Sampling Rate
t = 0:1/fs:T-1/fs;
x = sawtooth(2*pi*freq*t);
plot(t,x)
acc = 0 ;
n = 3 ; % Number of harmonics.
for i = 1 : n
acc = acc + (1 / i) * sin((i * pi * t) / 0.5) ;
end
acc = 0.5 - (1 / pi)*(acc) ;
hold on
plot(t , acc)
hold off
grid on
0 件のコメント
Aasha
2022 年 9 月 10 日
TLAB Answers
Toggle Sub Navigation
Close Mobile Search
How to plot this sawtooth wave and its fourier approximation
Follow
79 views (last 30 days)
Tawhid Khan on 9 Jun 2019
⋮
Edited: Utkarsh Belwal on 11 Jun 2019
I am trying to plot this wave and its fourier approximation for first 5 harmonics. This is what I want the final result to be like (note the wave approximated in the picture is a square wave)
This is the wave I want to approximate:
I know how to plot a sawtooth wave using the sawtooth funciton I was confused by the delay between the sawtooths in the picture. I tried using a piecewise function repeated 3 times to generate the wave.
Theme
f = @(x)[.5*x.*(0<=x & x<=2) + 0.*(2<=x & x<=3) + ((.5*x)-1.5).*(3<=x & x<=5)];
x = linspace(0,3);
intvl = [-6 6];
pfx = repmat(f(x+1),1,diff(intvl)/3);
px = linspace(intvl(1),intvl(2),length(pfx));
figure(1)
plot(px, pfx)
grid
This code can generate the sawtooth wave with some problems as shown here:
Now my question is how to properly plot the function in the original question then plot a fourier transform for it. The fourier transform for this normal sawtooth below is given where L is half the length of the sawtooth.
0 Comments
Answer this question
Answers (1)
Utkarsh Belwal on 11 Jun 2019
⋮
Edited: Utkarsh Belwal on 11 Jun 2019
Theme
freq = 1 ; % Sawtooth frequency 1Hz
T = 4 * freq ;
fs = 1000; % Sampling Rate
t = 0:1/fs:T-1/fs;
x = sawtooth(2*pi*freq*t);
plot(t,x)
acc = 0 ;
n = 3 ; % Number of harmonics.
for i = 1 : n
acc = acc + (1 / i) * sin((i * pi * t) / 0.5) ;
end
acc = 0.5 - (1 / pi)*(acc) ;
hold on
plot(t , acc)
hold off
grid on
0 件のコメント
Aasha
2022 年 9 月 10 日
freq = 1 ; % Sawtooth frequency 1Hz T = 4 * freq ;
fs = 1000; % Sampling Rate t = 0:1/fs:T-1/fs;
x = sawtooth(2*pi*freq*t);
plot(t,x)
acc = 0 ; n = 3 ; % Number of harmonics.
for i = 1 : n acc = acc + (1 / i) * sin((i * pi * t) / 0.5) ; end
acc = 0.5 - (1 / pi)*(acc) ;
hold on plot(t , acc) hold off grid on
0 件のコメント
Aasha
2022 年 9 月 10 日
freq = 1 ; % Sawtooth frequency 1Hz T = 4 * freq ;
fs = 1000; % Sampling Rate t = 0:1/fs:T-1/fs;
x = sawtooth(2*pi*freq*t);
plot(t,x)
acc = 0 ; n = 3 ; % Number of harmonics.
for i = 1 : n acc = acc + (1 / i) * sin((i * pi * t) / 0.5) ; end
acc = 0.5 - (1 / pi)*(acc) ;
hold on plot(t , acc) hold off grid on
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!