How do I get rid of the sinusoidal wave in my output waveform for fourier series sawtooth waveform?
Mostrar comentarios más antiguos
%%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?
Respuesta aceptada
Más respuestas (1)
Paul
el 28 de Abr. de 2023
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.
Categorías
Más información sobre Waveform Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


