I want to approximate below signal using fourier series on Matlab.
My code is below
close all clear all clc a_0 = 0 t=-10:0.001:10 x_t = 2/5 T = 10; w0 = 2*pi/T numOfTerms = 100 plot(t, x_t); for k=1:numOfTerms-1 a_k = (1/(w0*i*k*T))*( exp(-1*i*k*w0)-exp(-3*i*k*w0)+ exp(-7*i*k*w0)- exp(-9*i*k*w0)) x_t = x_t + a_k * exp(i*k*w0*t) plot(t, x_t); title(['Number Of Terms = ',num2str(k+1)]); pause(0.1); end
You see that min point of this signal above zero and max point below 1. How can I solve this problem? Why it gives such result?