How to plot this sawtooth wave and its fourier approximation
40 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223696/Capture.png)
This is the wave I want to approximate:
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223697/Capture.png)
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:
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223698/Capture.png)
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.
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223699/Capture.png)
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223700/Capture.png)
0 comentarios
Respuestas (4)
Utkarsh Belwal
el 11 de Jun. de 2019
Editada: Utkarsh Belwal
el 11 de Jun. de 2019
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 comentarios
Aasha
el 10 de Sept. de 2022
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 comentarios
Aasha
el 10 de Sept. de 2022
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 comentarios
Aasha
el 10 de Sept. de 2022
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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!