Para Mis Estudiantes de PDS
-
Upload
solano-naols -
Category
Documents
-
view
216 -
download
0
Transcript of Para Mis Estudiantes de PDS
-
8/12/2019 Para Mis Estudiantes de PDS
1/9
Para mis estudiantes de PDS.
Vamos a probar algunos ejercicios en MATLAB del libro PROCESAMIENTO DE
SEALES DIGITALES de Mitra MCGrawHill.
1) Son dos ejemplos que presentan la graficacin de seales exponenciales.
% Program 2_2
% Generation of complex exponential sequence
% Probar este ejemplo con a=-0.08, b=0.52, K=2, y N=40.
a = input('Type in real exponent = ');
b = input('Type in imaginary exponent = ');
c = a + b*i;
K = input('Type in the gain constant = ');
N = input ('Type in length of sequence = ');
n = 1:N;
x = K*exp(c*n);%Generate the sequence
stem(n,real(x));%Plot the real part
xlabel('Time index n');ylabel('Amplitude');
title('Real part');
disp('PRESS RETURN for imaginary part');
pause
stem(n,imag(x));%Plot the imaginary part
xlabel('Time index n');ylabel('Amplitude');
title('Imaginary part');
-
8/12/2019 Para Mis Estudiantes de PDS
2/9
% Program 2_3
% Generation of real exponential sequence
%
a = input('Type in argument = ');
K = input('Type in the gain constant = ');
N = input ('Type in length of sequence = ');
n = 0:N;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
title(['\alpha = ',num2str(a)]);
2) Relativos a la Convolucin y correlacin
% Program 2_6
% Illustration of Convolution
%
a = input('Type in the first sequence = ');
b = input('Type in the second sequence = ');
c = conv(a, b);
M = length(c)-1;
n = 0:1:M;
-
8/12/2019 Para Mis Estudiantes de PDS
3/9
disp('output sequence =');disp(c)
stem(n,c)
xlabel('Time index n'); ylabel('Amplitude');
% Program 2_7
% Computation of Cross-correlation Sequence
% Sea x=[ 1 3 -2 1 2 -1 4 4 2]
% Sea y=[2 -1 4 1 -2 3]
x = input('Type in the reference sequence = ');
y = input('Type in the second sequence = ');
% Compute the correlation sequence
n1 = length(y)-1; n2 = length(x)-1;
r = conv(x,fliplr(y));
k = (-n1):n2';
stem(k,r);
xlabel('Lag index'); ylabel('Amplitude');
v = axis;
axis([-n1 n2 v(3:end)]);
3) De las series de Fourier FFT
% Program 5_1
% Illustration of DFT Computation
% Probar con N=8 y M=16
-
8/12/2019 Para Mis Estudiantes de PDS
4/9
% Read in the length N of sequence and the desired
% length M of the DFT
N = input('Type in the length of the sequence = ');
M = input('Type in the length of the DFT = ');
% Generate the length-N time-domain sequence
u = [ones(1,N)];
% Compute its M-point DFT
U = fft(u,M);
% Plot the time-domain sequence and its DFT
t = 0:1:N-1;
stem(t,u)
title('Original time-domain sequence')
xlabel('Time index n'); ylabel('Amplitude')
pause
subplot(2,1,1)
k = 0:1:M-1;
stem(k,abs(U))
title('Magnitude of the DFT samples')
xlabel('Frequency index k'); ylabel('Magnitude')
subplot(2,1,2)
stem(k,angle(U))
title('Phase of the DFT samples')
xlabel('Frequency index k'); ylabel('Phase')
-
8/12/2019 Para Mis Estudiantes de PDS
5/9
% Program 5_2
% Illustration of IDFT Computation
%
% Read in the length K of the DFT and the desired
% length N of the IDFT
K = input('Type in the length of the DFT = ');
N = input('Type in the length of the IDFT = ');
% Generate the length-K DFT sequence
k = 0:K-1;
V = k/K;
% Compute its N-point IDFT
v = ifft(V,N);
% Plot the DFT and its IDFT
stem(k,V)
xlabel('Frequency index k'); ylabel('Amplitude')
title('Original DFT samples')
pause
subplot(2,1,1)
n = 0:N-1;
stem(n,real(v))
title('Real part of the time-domain samples')
xlabel('Time index n'); ylabel('Amplitude')
subplot(2,1,2)
stem(n,imag(v))
title('Imaginary part of the time-domain samples')
-
8/12/2019 Para Mis Estudiantes de PDS
6/9
xlabel('Time index n'); ylabel('Amplitude')
Escriba el siguiente cdigo en un archivo con extensin .m para obtener la serie de Fourier, el
espectro de Amplitud y el espectro de Potencia.
clear
T0= 2;
ep=1;
t0=0;
A=1;
w0=2*pi/T0;
nterm=100;
X0=A*ep/T0;
for kk=1:nterm
X(kk) = X0*(exp(-j*kk-w0*t0))*sin(kk*ep/T0);
end
Am=2*abs(X);
qm=angle(X);
t=linspace(-2*T0+ep/2,2*T0-ep/2,400);
x=X0*ones(size(t));
for jj=1:nterm
x =x + Am(jj)*cos(jj*w0*t+qm(jj));
end
Xt=abs(X);
Amp = [fliplr(Xt),X0,Xt]
-
8/12/2019 Para Mis Estudiantes de PDS
7/9
Pt=abs(X).^2;
Pwr=[fliplr(Pt),X0^2,Pt]
w=[-nterm:nterm]*w0;
subplot(221)
plot(t,x)
title('serie de Fourier')
xlabel('Tiempo')
subplot(222)
plot(w,Amp)
title('Espectro bilateral de amplitud')
xlabel('frecuencia,rad/s')
subplot(223)
plot(w,Pwr)
title('Espectro de potencia')
xlabel('frecuencia,rad/s')
Escriba el siguiente cdigo en un archivo con extensin .m y compruebe la FFT.
x=[1 1 0 0];
X=fft(x)
Escriba el siguiente cdigo en un archivo con extensin .m y compruebe la FFT.
nn=0:15;
xx=exp(j*nn/3);
-
8/12/2019 Para Mis Estudiantes de PDS
8/9
XX=fft(xx);
kk=nn;
subplot(221)
stem(kk, real(xx))
title('Real part of x[n]'), xlabel('index (n)')
subplot(223)
stem(kk, imag(xx))
title('Imag part of x[n]'), xlabel('index(k)')
subplot(222)
stem(kk, real(XX))
title('Real part of DFT'), xlabel('index(k)')
subplot(224)
stem(kk,imag(XX))
title('IMAG PART OF DFT'), xlabel('INDEX (k)')
% Program 5_4
% Linear Convolution Via the DFT
%
% Read in the two sequences
x = input('Type in the first sequence = ');
h = input('Type in the second sequence = ');
% Determine the length of the result of convolution
L = length(x)+length(h)-1;
% Compute the DFTs by zero-padding
-
8/12/2019 Para Mis Estudiantes de PDS
9/9
XE = fft(x,L); HE = fft(h,L);
% Determine the IDFT of the product
y1 = ifft(XE.*HE);
% Plot the sequence generated by DFT-based convolution and
% the error from direct linear convolution
n = 0:L-1;
subplot(2,1,1)
stem(n,y1)
xlabel('Time index n');ylabel('Amplitude');
title('Result of DFT-based linear convolution')
y2 = conv(x,h);
error = y1-y2;
subplot(2,1,2)
stem(n,error)
xlabel('Time index n');ylabel('Amplitude')
title('Error sequence')