How do I get rid of the sinusoidal wave in my output waveform for fourier series sawtooth waveform?
이전 댓글 표시
%%Please do not change the following code%%
fs = 44100; % Sampling frequency
Ts = 1/fs; % Time step.
t2 = -3 * pi : Ts : 3 * pi; % -3pi - 3pi s with time step Ts
% Original Sawtooth Waveform
x2 = (t2 + 2 * pi).*(t2 < -pi) + t2.*((-pi <= t2) & (t2 <= pi)) + (t2 - 2 * pi).*(t2 > pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
T0 = 2*pi; f0 = 1/T0;
y2 = 0;
for i = 1: 8
y2 = y2 + sin(k*f0*t2)/k;
end
figure(2);
plot(t2, x2, t2, y2);
This is my code for the sawtooth graph however it outputs this

I was wondering if there was something wrong with my code and how to get rid of the sinusoidal wave?
채택된 답변
추가 답변 (1개)
Paul
2023년 4월 28일
Hi Chaileen,
It looks like you're trying to use a summation like this:
for n = 1:8
y2 = y2 + B(n)*sin(2*pi*n*t2/(T0))
end
The code doesn't show the value of k, but even with k = 2*pi the argument to the sin() is still missing that factor of n.
Also, the code is assuming that B(n) = 1/k, which isn't correct. Suggest revisiting the derivation of that Fourier series coefficient, or rechecking the code against its equation if the equation was given to you.
카테고리
도움말 센터 및 File Exchange에서 Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


