0% found this document useful (0 votes)
28 views3 pages

Codigos

The document contains MATLAB code for analyzing and designing digital filters. It includes code to calculate the frequency response of a filter, analyze circular convolution, and design a Kaiser window finite impulse response (FIR) low-pass filter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

Codigos

The document contains MATLAB code for analyzing and designing digital filters. It includes code to calculate the frequency response of a filter, analyze circular convolution, and design a Kaiser window finite impulse response (FIR) low-pass filter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

close all;

clc
% inciso (b):
t1 = 0;
t2 = 2;
dF = 0.1;
F = -50:dF:50;
Xc = 100*pi./((20*pi)^2+(1i*2*pi*F+10).^2);
% inciso (c):
Fs = 100;
T = 1/Fs;
nT = t1:T:t2;
N = length(nT);
xn = 5*exp(-10*nT).*sin(20*pi*nT);
X = fftshift(fft(xn));
w = linspace(-pi,pi,N);
Xc_approx = T*X;
%Graficas:
figure(1)
subplot(121)
plot(F,abs(Xc))
xlabel('F (Hz)')
ylabel('|H_c(j2\pi F)|')
title('Respuesta en magnitud N°1')
subplot(122)
plot(w/T/2/pi,abs(Xc_approx))
xlabel('F (Hz)')
ylabel('|H_c(j2\pi F)|')
title('Respuesta en magnitud N°2')

figure(2)
subplot(121)
plot(F,angle(Xc))
xlabel('F (Hz)')
ylabel('\angle H_c(j2\pi F)')
title('Respuesta en Fase N°1')

subplot(122)
plot(w/T/2/pi,angle(Xc_approx))
xlabel('F (Hz)')
ylabel('\angle H_c(j2\pi F)')
title('Respuesta en Fase N°2')

close all;
clc
a = 1;
b = 2;
c = 3;
d = 4;
xn1 = [a, 0, b, c, 0, d, 0, 0];
xn2 = [d, 0, c, b, 0, a, 0, 0];
Xk1 = fft(xn1);
Xk2 = fft(xn2);
N = 8; %lenght (xn1)
k = 0:N-1;
% Graficas:
figure(1)
subplot(121)
stem(k,abs(Xk1),'filled'); hold on
stem(k,abs(Xk2),'filled','color','red');
xlim([0 N-1])
xlabel('k')
title('Respuesta en magnitud')
legend('|X_1[k]|','|X_2[k]|','location','northeast')
subplot(122)
stem(k,angle(Xk1),'filled');
title('Respuesta en fase')
hold on
stem(k,angle(Xk2),'filled','color','red');
xlim([0 N-1])
ylim([-pi pi])

close all;
clc
xn1 = [-2 1 -3 -5 6 8];
xn2 = 1:4;
N = 7;
% inciso (b):
xn = circonv([xn1 zeros(1,N-length(xn1))]',...
[xn2 zeros(1,N-length(xn2))]')'
% inciso (c):
Xk1 = fft(xn1,N)
Xk2 = fft(xn2,N)
Xk = Xk1.*Xk2
xn_dft = ifft(Xk)

% Diseño de filtro pasa-bajo: ventana Kaiser


wp = 0.2*pi;
ws = 0.3*pi;
As = 50;

tr_width = ws - wp;
M = ceil((As-7.95)/(14.36*tr_width/(2*pi))+1) + 1;
n=[0:1:M-1];
beta = 0.1102*(As-8.7);
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);
w_kai = (kaiser(M,beta))';
h = hd .* w_kai;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
As = -round(max(db(ws/delta_w+1:1:501))); % Atenuación mínima de la banda de parada

%Graficas
figure()
subplot(1,1,1)
subplot(2,2,1); stem(n,hd); title('Respuesta al impulso ideal')
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2); stem(n,w_kai);title('Ventaneo por Kaiser')
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Respuesta al impulso real')
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)')
subplot(2,2,4);plot(w/pi,db);title('Respuesta en magnitud dB');
grid
axis([0 1 -100 10]); xlabel('frecuencia *\pi');
ylabel('dB')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[-50,0])
set(gca,'YTickLabelMode','manual','YTickLabels',['50';' 0'])

You might also like