Hi Sanat
To calculate the Fourier series coefficients and plot the Fourier series approximation for the pulse waveform
- Define the sawtooth function and its range and period.
- Calculate the Fourier series coefficients (an and bn).
- Create a Fourier series approximation using the calculated coefficients.
- Plot and compare the original function with its Fourier series approximation.
Here's the code that follows this. I have takes the fundamental period and "A" both as 1
x = linspace(0, T, 1000);
f = @(x) (A/2*(x >= 0 & x <T/4) + -A/2*(x>=T/4 & x<3*T/4) + A/2*(x>=3*T/4 & x<=T));
a0 = (1/T) * integral(@(x) f(x), 0, T);
an(n) = (1/T) * integral(@(x) f(x).*cos(n*pi*x/2), 0, T);
bn(n) = (1/T) * integral(@(x) f(x).*sin(n*pi*x/2), 0, T);
F = F + an(n) * cos(n*pi*x/2) + bn(n) * sin(n*pi*x/2);
This gives me the following the optupt