%% serie de fourier clearvars; close all; clc; %% datos iniciales %intervalo de analisis Tini = -5*pi; Tfin = 5*pi; dt = pi/100; FTini = -0.5*pi; FTfin = 1.5*pi; %tiempo t = Tini:dt:Tfin; %tiempo (arreglo 1D) Nt = length(t); %longitud del arreglo tiempo %% procesamiento principal N = 10 ; %numero de elementos de la serie de fourier ft = zeros(1,Nt); %inicializacion con ceros %inicializacion de los coeficientes de la serie a0 = pi/4; ft(1:Nt) = a0; %insertamos el elemento a0 de la serie an = zeros(1,N); %inicializacion de an bn = zeros(1,N); %inicializacion de bn %figura del termino a0 figure(1) plot(t,ft) title('mi primera serie de fourier a0'); xlabel('tiempo t(s)'); ylabel('presion sonora p(Pa)'); legend(['f_n(t) n = ' int2str(0)]); axis([Tini Tfin FTini FTfin]); grid on; box on; pause(0.5) for n = 1:N %trabajaremos usando el concepto de variable acumulativa ft = ft + ( (1 - cos(n*pi))/(n^2*pi) )*cos(n*t) + (1/n)*sin(n*t); %figura de como se van agregando los terminos an y bn figure(1) plot(t,ft) title('mi primera serie de fourier an y bn'); xlabel('tiempo t(s)'); ylabel('presion sonora p(Pa)'); legend(['f_n(t) n = ' int2str(n)]); axis([Tini Tfin FTini FTfin]); grid on; box on; an(n) = ( (1 - cos(n*pi))/(n^2*pi) ); bn(n) = (1/n); %pausa cada 1 segundo pause(0.5) end; figure(2) plot(t,ft) title('mi primera serie de fourier final'); xlabel('tiempo t(s)'); ylabel('presion sonora p(Pa)'); legend('f(t)'); axis([Tini Tfin FTini FTfin]); grid on; box on; %% areglos de an y bn final an = [a0 an]; bn = [0 bn]; n = 0:N; figure(3) subplot(2,1,1) stem(n,an) title('coeficientes de fourier an'); xlabel('n'); ylabel('an'); legend('an'); axis([0 N -1.5*a0 1.5*a0]); grid on; box on; subplot(2,1,2) stem(n,bn) title('coeficientes de fourier bn'); xlabel('n'); ylabel('bn'); legend('bn'); axis([0 N -1.5*a0 1.5*a0]); grid on; box on;