clc; clf; clear; T = 2; t =0:0.01:T; y = funcion_rectangular(t); subplot(3,1,1); plot(t,y,"r","linewidth",2); grid on; xlabel("Eje X","fontsize",16); ylabel("Eje Y","fontsize",16); title("Señal Original","fontsize",20); set(gca,"fontsize", 20); f1 = @funcion_rectangular; w = 2*pi/T; q = quad (f1, 0, T);%Integral definida de f de [0 a T] a0 = (1/T)*q;% Cáculo del coeficiente a0 de la serie de fourier ncoeficientes = 5; An = zeros(ncoeficientes,1); Bn = zeros(ncoeficientes,1); for n=1:ncoeficientes fcos = @(t) f1(t).*cos(n*w*t);%Función anónima que multiplica f*cos(nwt) fsen = @(t) f1(t).*sin(n*w*t);%Función anónima que multiplica f*sin(nwt) subplot(3,1,2); plot(t,fcos(t),"r","linewidth",2); grid on; xlabel("Eje X","fontsize",16); ylabel("Eje Y","fontsize",16); title(["f*cos(nwt) n = " num2str(n)] ,"fontsize",20); subplot(3,1,3); plot(t,fsen(t),"r","linewidth",2); grid on; xlabel("Eje X","fontsize",16); ylabel("Eje Y","fontsize",16); title(["f*sin(nwt) n = " num2str(n)],"fontsize",20); q2 = quad(fcos,0,T);% Calcula la integral An(n) = (2/T)*q2;% Calcula el coeficiente an q3 = quad(fsen,0,T); Bn(n) = (2/T)*q3;% Calcula el coeficiente bn text(0.5,0.5,["a0 = " num2str(a0)],"fontsize",20); text(1.0,0.5,["a" num2str(n) "= " num2str(An(n))],"fontsize",20); text(1.5,0.5,["b" num2str(n) "= " num2str(Bn(n))],"fontsize",20); ginput(1); endfor nterminos = ncoeficientes; fresultante = crea_serie_Fourier(a0,An,Bn,t,nterminos,T); clf; subplot(2,1,1); plot(t,y,"r","linewidth",2); grid on; xlabel("Eje X","fontsize",16); ylabel("Eje Y","fontsize",16); title("Señal Original","fontsize",20); subplot(2,1,2); plot(t,fresultante,"r","linewidth",2); grid on; xlabel("Eje X","fontsize",16); ylabel("Eje Y","fontsize",16); title(["Serie de fourier de la señal original con " num2str(nterminos) " términos"],"fontsize",20);