Fourier series of any function
Afficher commentaires plus anciens
Hello, I'm trying to build a simple script that finds the geometric fourier series of agiven function and a given period, everything seems to be good, but the plot is taking the absolute value, what do you think is the mistake?
f= input('ingrese la funcion, usando: @(t)LA_FUNCION: '); %ingresa la funcion como parametro
T= input('ingrese el periodo T: '); %ingresa el periodo como parametro
N= input('ingrese el numero de iteraciones N: '); %ingresa N como parametro
w0 = 2*pi/T;
suma=@(t) integral(f,-T/2,T/2)/2;
for k=1:N
fun_a=@(t) f(t).*cos(k*w0*t);
fun_b=@(t) f(t).*sin(k*w0*t);
a_k=2/T*integral(fun_a,-T/2,T/2); % calculo del coeficiente a
b_k=2/T*integral(fun_b,-T/2,T/2); %calculo del coeficiente b
suma= @(t) suma(t) +a_k*fun_a(t) + b_k*fun_b(t); %sumatoria de la serie de Fourier
end
t= -T/2:0.01:T/2;
x_t=f(t);
x_Nt=suma(t);
plot(t,x_t,t,x_Nt)
I tried several tests with square(t) and sawtooth(t) , wich period is 2*pi, but this is what I get: using n=1 and n=10

the Script somehow is doing the right thing, what do you think is wrong?,
thank you in advice
1 commentaire
VBBV
le 17 Sep 2020
Modifié(e) : Walter Roberson
le 17 Sep 2020
plot(t,x_t.*(180/pi),t,x_Nt.*(180/pi));
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!