Programa para generar las grficas de la serie de Fourier as como su
espectro y componentes
%% Series de Fourier
clc
clear
close all
syms n t
Ao=0;
An=(4*(sin(pi*n/2))^2)/((pi)^2*n^2)
Bn=0;
T=2;
wo=2*pi/T;
Arm=20;
for n=1:Arm
f(n,:)=sum((An)*cos(n*wo*t)+((Bn)*sin(n*wo*t)));
end
t=linspace(0,5*T,1000);
f=subs(f,'t',t);
f(n+1,:)=zeros(1,1000);
plot(t,Ao+sum(f),'Linewidth',2); grid on
xlabel('\bf TIEMPO'); ylabel('\bf AMPLITUD');
title('\bf SERIES DE FOURIER');
%% SERIES DE FOURIER ANIMADA
clc
clear
close all
syms n t
Ao=0;
An=(4*(sin(pi*n/2))^2)/((pi)^2*n^2) ;
Bn=0;
T=2;
wo=2*pi/T;
Arm=10;
for n=1:Arm
syms t
f(n,:)=sum((An)*cos(n*wo*t)+(Bn)*sin(n*wo*t));
t=linspace(0,5*T,1000);
subplot(3,1,1);
plot(t, subs(f(n,:),'t',t)); grid on
xlabel('\bf TIEMPO'); ylabel('\bf AMPLITUD');
title('\bf COMPONENTE'); hold on
subplot(3,1,2);
plot(t, Ao+subs(sum(f),'t',t), 'r', 'Linewidth',1.5); grid on
xlabel('\bf TIEMPO'); ylabel('\bf AMPLITUD');
title('\bf SERIE DE FOURIER')
subplot(3,1,3);
Cn(n)=sqrt((An)^2+(Bn)^2);
stem(Cn,'fill'); grid on
xlim([1,Arm]);
xlabel('\bf ARMNICO'); ylabel('\bf AMPLITUD');
title('\bf ESPECTRO DE FRECUENCIA'); pause(0.5)
end
SERIE COMPLEJA DE FOURIER
close all
clc
syms t n
A=[0 1 2];
f=[t 1-t];
f=sym(f);
T=max(A)-min(A);
wo=2*pi/T;
p=complex(0,1);
Co=0;
for k=1:length(f)
Co=Co+int(f(k),'t',A(k),A(k+1));
end
Co=simple(Co/(T));
Cn=0;
for k=1:length(f)
Cn=Cn+int(f(k)*exp(-p*n*wo*t),A(k),A(k+1));
end
Cn=simple(Cn/T);
Cn = char(Cn);
Cn = simple(sym(strrep(char(Cn),'sin(pi*n)','0')));
Cn = simple(sym(strrep(char(Cn),'cos(pi*n)','(-1)^n')));
Cn = simple(sym(strrep(char(Cn),'sin(2*pi*n)','0')));
Cn = simple(sym(strrep(char(Cn),'cos(2*pi*n)','1')));
Cn = simple(sym(strrep(char(Cn),'exp(2*pi*n*p)','1')));
Cn = simple(sym(strrep(char(Cn),'1/p','-p')));
Cn = simple(sym(strrep(char(Cn),'p^2','-1')));
disp('Co')
pretty(Co)
disp('Cn')
pretty(Cn)
x=linspace(min(A),max(A),1000);
fx=0;
for i=1:length(A)-1
if mod(i,2)==1
fx=fx+((x>=A(i))&(x<=A(i+1))).*subs(f(i),x);
else
fx=fx+((x>A(i))&(x<A(i+1))).*subs(f(i),x);
end
end
plot(x,fx,'Linewidth',2); hold on
plot(x+max(x)-min(x),fx,'Linewidth',2)
plot(x-max(x)+min(x),fx,'Linewidth',2)
plot([max(x) max(x)],[fx(1) fx(end)],'Linewidth',2)
plot([min(x) min(x)],[fx(end) fx(1)],'Linewidth',2)
grid on
xlabel('\bf TIEMPO');
ylabel('\bf AMPLITUD');
title('\bf GRFICA DE LA FUNCIN');