0% found this document useful (0 votes)
52 views

Series de Fourier Matlab

This document contains MATLAB code for analyzing signals using Fourier series. Specifically, it: 1. Defines several periodic signals with different amplitudes, periods, and offsets. 2. Plots the original signals and calculates their Fourier series approximations up to various values of k. 3. Analyzes how changing properties of the original signals, such as amplitude and period, affects the Fourier series approximations. It also examines the effect of translating the original signals.

Uploaded by

Santiago Uribe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Series de Fourier Matlab

This document contains MATLAB code for analyzing signals using Fourier series. Specifically, it: 1. Defines several periodic signals with different amplitudes, periods, and offsets. 2. Plots the original signals and calculates their Fourier series approximations up to various values of k. 3. Analyzes how changing properties of the original signals, such as amplitude and period, affects the Fourier series approximations. It also examines the effect of translating the original signals.

Uploaded by

Santiago Uribe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Taller de Señales y Sistemas:

Series de Fourier
Ray Stevenson Amaya Maldonado -U00122486
Santiago Uribe Jaimes -U00122804
Parcial 2
 Código
%% Punto 4 Taller señales
% Asumiendo la Amplitud A, como 1
A = 1;
B = -1;
T = 2;
w0 = 2*pi/T

%% Definir la funcion x(t)


t = -4:0.01:4 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A) ;
xt_1 = (t> 0 & t< T/2)*(A);
xt_2 = (t> T/2 & t< T)*(B);

subplot(2,1,1)
plot(t,xt,'g','LineWidth',3);xlim([-4 4]);xlabel('t');title('x(t)');grid on;axis equal

sum_par = 0
sum_impar = 0

%% Serie de fourier
for k=1:1:700

subplot(2,1,2)
% Coeficientes
a_0 = 0
b_k = 0
c_k = ((2*A)/(k*pi))*(1-cos(k*pi))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (t>-3*T/2 & t<3*T/2).*(a_0 + sum_par + sum_impar)
plot(t,x_t);pause(0.02);ylim([-1.5 1.5]);xlim([-4 4]);grid on
title('x_t en series de fourier con k = 700')
end
 Código GRAFICAS GENERAL
clc
close all

a = [-5 5];
b = a-a;
subplot(2,3,1)
hold on
plot(a,b,'k')
plot(b,a,'k')
hold on
t = -3:0.01:3

% x(t) T = 2 ; A = 3 ; B = -3
xt1 = (t>= -1 & t<= 0).*(-3) + (t> 0 & t<= 1).*(3)
plot(t,xt1,'r','LineWidth',3); axis([-3 3 -4 4]); title('x(t) T = 2 ; A = 3 ; B = -3');
hold on

subplot(2,3,2)
hold on
plot(a,b,'k')
plot(b,a,'k')
hold on
% T = 2 ; A = 2 ; B = -2
xt2 = (t>= -1 & t<= 0).*(-2) + (t> 0 & t<= 1).*(2)
plot(t,xt2,'c','LineWidth',3); axis([-3 3 -4 4]); title('T = 2 ; A = 2 ; B = -2');
hold on

a = [-6 6];
b = a-a;
subplot(2,3,3)
hold on
plot(a,b,'k')
plot(b,a,'k')
hold on
% T = 2 ; A = 3 ; B = -3
xt3 = xt1 + 2
plot(t,xt3,'m','LineWidth',3); axis([-3 3 -2 6]); title('T = 2 ; A = 3 ; B = -3');
hold on

subplot(2,3,4)
hold on
plot(a,b,'k')
plot(b,a,'k')
hold on
% T = 2 ; A = 3 ; B = -3
xt4 = (t>= -1 & t<= 0).*(3) + (t> 0 & t<= 1).*(-3)
plot(t,xt4,'g','LineWidth',3); axis([-3 3 -4 4]); title('T = 2 ; A = 3 ; B = -3');
hold on

subplot(2,3,5)
hold on
plot(a,b,'k')
plot(b,a,'k')
hold on
% T = 4 ; A = 3 ; B = -3
xt5 = (t>= -2 & t<= 0).*(-3) + (t> 0 & t<= 2).*(3)
plot(t,xt5,'y','LineWidth',3); axis([-3 3 -4 4]);title('T = 4 ; A = 3 ; B = -3');
hold on

subplot(2,3,6)
hold on
plot(a,b,'k')
plot(b,a,'k')
hold on
% T = 2 ; A =3 ; B = -3
xt6 = (t>= -1+0.6 & t<= 0+0.6).*(-3) + (t>0+0.6 & t<= 1+0.6).*(3)
plot(t,xt6,'b','LineWidth',3); axis([-3 3 -4 4]);title('T = 2 ; A =3 ; B = -3');
hold on

 Código Graficas individuales


clc
clear all
close all
%% Punto 5 Taller señales
%1ra
A = 3;
B = -3;
T = 2;
w0 = 2*pi/T

% Definir la funcion x(t)


t = -4:0.01:4 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A) ;
% xt_1 = (t> 0 & t< T/2)*(A);
% xt_2 = (t> T/2 & t< T)*(B);

figure(1)
subplot(2,1,1)
plot(t,xt,'b','LineWidth',3);xlim([-4 4]);xlabel('t');title('x(t)');grid on;ylim([-4 4]);

sum_par = 0
sum_impar = 0
% Serie de fourier
for k=1:1:50
figure(1)
subplot(2,1,2)
% Coeficientes
a_0 = 0
b_k = 0
c_k = ((2*A)/(k*pi))*(1-cos(k*pi))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (t>-3*T/2 & t<3*T/2).*(a_0 + sum_par + sum_impar)
plot(t,x_t);pause(0.02);ylim([-4 4]);xlim([-4 4]);grid on
title('x_t en series de fourier con k = 50')

end
%% 2da
A = 3;
B = -3;
T = 2;
w0 = 2*pi/T

% Definir la funcion x(t)


t = -4:0.01:4 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A) ;
xr = (2/3)*xt;
% xt_1 = (t> 0 & t< T/2)*(A);
% xt_2 = (t> T/2 & t< T)*(B);

figure(2)
subplot(2,1,1)
plot(t,xr,'m','LineWidth',3);xlim([-4 4]);xlabel('t');title('x(t)');grid on;ylim([-4 4]);

sum_par = 0
sum_impar = 0

% Serie de fourier
for k=1:1:50

figure(2)
subplot(2,1,2)
% Coeficientes
a_0 = 0
b_k = 0
c_k = ((2*A)/(k*pi))*(1-cos(k*pi))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (t>-3*T/2 & t<3*T/2).*(a_0 + sum_par + sum_impar)
xf = (2/3)*x_t
plot(t,xf);pause(0.02);ylim([-3 3]);xlim([-4 4]);grid on
title('x_t en series de fourier con k = 50')
end

%% 3ra
A = 3;
B = -3;
T = 2;
w0 = 2*pi/T

% Definir la funcion x(t)


t = -4:0.01:4 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A)
xr = xt +2
% xt_1 = (t> 0 & t< T/2)*(A);
% xt_2 = (t> T/2 & t< T)*(B);
figure(3)
subplot(2,1,1)
plot(t,xr,'g','LineWidth',3);xlim([-4 4]);xlabel('t');title('x(t)');grid on;ylim([-2 6]);

sum_par = 0
sum_impar = 0

% Serie de fourier

for k=1:1:50
figure(3)
subplot(2,1,2)
% Coeficientes
a_0 = 2
b_k = 0
c_k = ((2*A)/(k*pi))*(1-cos(k*pi))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (t>-3*T/2 & t<3*T/2).*(a_0 + sum_par + sum_impar)
plot(t,x_t);pause(0.02);ylim([-3 6]);xlim([-4 4]);grid on
title('x_t en series de fourier con k = 50')

end

%% 4ta

A = -3;
B = 3;
T = 2;
w0 = 2*pi/T

% Definir la funcion x(t)


t = -4:0.01:4 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A) ;
% xt_1 = (t> 0 & t< T/2)*(A);
% xt_2 = (t> T/2 & t< T)*(B);
figure(4)
subplot(2,1,1)
plot(t,xt,'b','LineWidth',3);xlim([-4 4]);xlabel('t');title('x(t)');grid on;ylim([-4 4]);

sum_par = 0
sum_impar = 0

% Serie de fourier
for k=1:1:50
figure(4)
subplot(2,1,2)
% Coeficientes
a_0 = 0
b_k = 0
c_k = ((2*A)/(k*pi))*(1-cos(k*pi))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (t>-3*T/2 & t<3*T/2).*(a_0 + sum_par + sum_impar)
plot(t,x_t);pause(0.02);ylim([-4 4]);xlim([-4 4]);grid on
title('x_t en series de fourier con k = 50')

end

%% 5ta
A = 3;
B = -3;
T = 4;
w0 = 2*pi/T

% Definir la funcion x(t)


t = -6:0.01:6 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A) ;
% xt_1 = (t> 0 & t< T/2)*(A);
% xt_2 = (t> T/2 & t< T)*(B);
figure(5)
subplot(2,1,1)
plot(t,xt,'r','LineWidth',3);xlim([-6 6]);xlabel('t');title('x(t)');grid on;ylim([-4 4]);

sum_par = 0
sum_impar = 0

% Serie de fourier
for k=1:1:50
figure(5)
subplot(2,1,2)
% Coeficientes
a_0 = 0
b_k = 0
c_k = ((2*A)/(k*pi))*(1-cos(k*pi))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (t>-3*T/2 & t<3*T/2).*(a_0 + sum_par + sum_impar)
plot(t,x_t);pause(0.02);ylim([-4 4]);xlim([-6 6]);grid on
title('x_t en series de fourier con k = 50')

end

%% 6ta
%Serie de fourier desplazada
A = 3;
B = -3;
T = 2;
w0 = 2*pi/T;
t0 = 0.6;
t = -4:0.01:4 ;
xt = (t> -3*T/2 & t< -T)*(B) + (t>-T & t< -T/2)*(A) + (t> -T/2 & t< 0)*(B) + (t> 0 & t<
T/2)*(A) + (t> T/2 & t< T)*(B) + (t> T & t< 3*T/2)*(A) ;

for k=1:1:25

subplot(3,1,3)
% Coeficientes
a_0 = 0
b_k = ((A)/(2*k*pi))*(-2*sin(k*w0*t0)-sin(k*w0((T/2)-t0))+sin(k*w0*((T/2)+t0)))
c_k = ((A)/(2*k*pi))*(-2*cos(k*w0*t0)+cos(k*w0((T/2)-t0))+cos(k*w0*((T/2)+t0)))

%Sumatorias
sum_par = sum_par + b_k*cos(k*w0*t)
sum_impar = sum_impar + c_k*sin(k*w0*t)

%Funcion
x_t = (a_0 + sum_par + sum_impar)
plot(t,x_t);pause(0.02);xlim([-4 4]);grid on
title('x_t en series de fourier con k = 25 y t0 = 0.6')
end
 Código
clc
clear all
N0 = 6;
W0 = 2 * pi /N0 ;
%Conjunto N
N = -2:3;
k = N;
ak = (1/N0)*(1+ 4*cos(pi.*k/3)-2*cos(2*pi.*k/3) );
ak'
%Señal en tiempo discreto
n = -10:10;
xn = zeros(1,length(n))
for i=1:length(ak)
xn = ak(i)*exp(j*k(i)*W0.*n)+xn;
end

figure(1)
stem(n,xn,'filled','r');ylim([-1.5
2.5]);xlabel('n');title('señal x[n]')
%Ak2 = AK*exp(j*k*T)
%% METODO 2
n = k'
%xn = [x[-2] x[-1] x[0] x[1] x[2] x[3]]
XN = [-1, 2 , 1, 2, -1, 0]'
Mcomp = exp(j.*n*W0.*k);
Syseq = [XN, zeros(N0,1), Mcomp];
AK = inv(Mcomp)*XN

You might also like