'DSP'에 해당되는 글 4

  1. 2008.05.13 DSP_homework04
  2. 2008.05.13 DSP_homework03
  3. 2008.05.13 DSP_homework02
  4. 2008.05.13 DSP_homework01

DSP_homework04

clear all; close all;
warning('off','MATLAB:dispatcher:InexactMatch')
% 4th Homework 'DFT Examples'
%  (a). Find & draw |X(omega)|, |H(omega)|, |Y(omega)|

x = [ 1, 2, 2, 1];
h = [ 1, 2, 3];
y = conv (x, h);

magX1 = abs(hw4(x, length(x), 1));
magH1 = abs(hw4(h, length(h), 1));
magY1 = abs(hw4(y, length(y), 1));

figure('name', '(a) - |X(omega)|, |H(omega)|, |Y(omega)|', 'Position', [50, 350, 500, 300], 'MenuBar', 'none')
plot(magY1, 'DisplayName', 'magY1', 'YDataSource', 'magY1'); hold all; plot(magX1, 'DisplayName', 'magX1', 'YDataSource', 'magX1'); plot(magH1, 'DisplayName', 'magH1', 'YDataSource', 'magH1'); hold off; figure(gcf)

%  (b) Find & draw |X(k)|, |H(k)|, |Y(k)|
x = [x, zeros(1,4)];
h = [h, zeros(1,5)];
y = [y, zeros(1,2)];

magX2 = abs(hw4(x, length(x), 2));
magH2 = abs(hw4(h, length(h), 2));
magY2 = abs(hw4(y, length(y), 2));

figure('name', '(b) - |X(k)|, |H(k)|, |Y(k)|', 'Position', [100, 300, 500, 300], 'MenuBar', 'none')
plot(magY2, 'DisplayName', 'magY2', 'YDataSource', 'magY2'); hold all; plot(magX2, 'DisplayName', 'magX2', 'YDataSource', 'magX2'); plot(magH2, 'DisplayName', 'magH2', 'YDataSource', 'magH2'); hold off; figure(gcf)

'예외처리' 카테고리의 다른 글

DSP_homework03  (0) 2008.05.13
DSP_homework02  (0) 2008.05.13
DSP_homework01  (0) 2008.05.13

DSP_homework03

clear all; close all;
warning('off','MATLAB:dispatcher:InexactMatch')
% 3rd Homework 'Chebyshev & Butterworth FILTERS'
%  1. (a) Design a analog Chebyshev LPF with the following properties :
%   wc=10rad/s, Max 1dB ripple, N=4
%  (b) Verify the result you obtained by drawing |H(w)|

OmegaC = 10;
Rp = 1;
N = 4;
% ep      = sqrt(10^(Rp/10)-1);

cheby = mkfilter(OmegaC,N,'cheby',Rp);
[mag1, pha1] = bode(cheby);

figure('name', '#1 - Chebyshev Analog Filter', 'Position', [50, 350, 500, 300], 'MenuBar', 'none')
stem3 (mag1, 'DisplayName', 'mag1');
title('Magnitude Response')
xlabel('Analog frequency in pi units'); zlabel('|H|');

%  2. (a) According to the digital Butterworth LPF, draw |H(omega)| and
%  discuss whether the spectrum meets the requirements of the problem.
%  
%  (b)For input x[n]=cos(pi/6*n)+cos(pi/2*n), n=0,1,…23  plot y[n], and
%  |Y(omega)| and compare them with x[n] and |X(omega)| where y[n]=
%  x[n]*h[n]

butterw = mkfilter(OmegaC,N,'butterw',Rp);
[mag2, pha2] = bode(butterw);

figure('name', '#2 (a) - Butterworth Digital Filter', 'Position', [100, 300, 500, 300], 'MenuBar', 'none')
stem3 (mag2, 'DisplayName', 'mag2');
title('Magnitude Response')
xlabel('Analog frequency in pi units'); zlabel('|H|');

N = 0:23;
input_x =   cos(pi/6*N)+cos(pi/2*N);
[db1,mag3,pha,grd,w] = freqz_m(input_x,1);
for p= 1:52
    ma2(p) = mag2(:,:,p);
    mag4(p) = mag3(p) .* ma2(p);
end
figure('name', '#2 (b) y[n], |Y[omega]|', 'Position', [150, 150, 600, 400], 'MenuBar', 'none')
subplot(2,2,1); stem(input_x); hold all;
subplot(2,2,2); plot(ma2);
subplot(2,2,3); plot(mag3);
subplot(2,2,4); plot(mag4); hold off; figure(gcf)

'예외처리' 카테고리의 다른 글

DSP_homework04  (0) 2008.05.13
DSP_homework02  (0) 2008.05.13
DSP_homework01  (0) 2008.05.13

DSP_homework02

clear all; close all;
warning('off','MATLAB:dispatcher:InexactMatch')
% 2nd Homework 'Make some of IIR filter'
% #1
% (a)For Ex 6-1, draw |H(Ω)| and |H(Ω)| [dB]
w= 0:0.001:pi;
z= exp(j*w);
N= 0:23;
% (b) For input x[n]= cos(pi*n/6) + cos(pi*n/2) , n=0,1,2,…..23
% Draw |X(Ω)|, |Y(Ω)| where Y(Ω)= X(Ω)*H(Ω)

[A_Y, A_in_H, DB, A_H] = hw2(2, z, cos((pi/6)*N)+cos((pi/2)*N), 3142);

figure('name', '#1', 'Position', [100, 150, 800, 600], 'MenuBar', 'none')
subplot(2,2,1); plot(A_H); title('Response H(Ω)'); hold on;
subplot(2,2,2); plot(DB); title('Response in dB'); grid; ylabel('Decibels');
subplot(2,2,3); plot(A_in_H); title('Response X(Ω)');
subplot(2,2,4); plot(A_Y); title('Response Y(Ω)');

% #2
% (a)Passband centered at Ω=pi/4 with a BW of pi/40 between -3dB points
% Peak gain is unity
% Perfect rejection at Ω=0 and Ω= pi/2
% (b) For input x[n]= cos(pi*n/6) + cos(pi*n/2) , n=0,1,2,…..23
% Draw |X(Ω)|, |Y(Ω)| where Y(Ω)= X(Ω)*H(Ω)
[A_Y, A_in_H, DB, A_H] = hw2(4, z, cos((pi/6)*N)+cos((pi/2)*N), 3142);

figure('name', '#2', 'Position', [150, 100, 800, 600], 'MenuBar', 'none')
subplot(2,2,1); plot(A_H); title('Response H(Ω)'); hold on;
subplot(2,2,2); plot(DB); title('Response in dB'); grid; ylabel('Decibels');
subplot(2,2,3); plot(A_in_H); title('Response X(Ω)');
subplot(2,2,4); plot(A_Y); title('Response Y(Ω)');

% % #3
% % Ex 6-2 draw |H1(Ω)|, |H2(Ω)|, |H(Ω)|
H1= 1./(z.^2-1.9476.*z*cos(pi/10)+0.9483);
H2= z.^2-2.*z*cos(pi/10)+1;
H3= H1.*H2;
figure('name', '#3 |H1(Ω)|, |H2(Ω)|, |H(Ω)|', 'Position', [200, 50, 800, 600], 'MenuBar', 'none')
subplot(2,2,1); plot(abs(H1)); title('Response H1(Ω)'); hold on;
subplot(2,2,2); plot(abs(H2)); title('Response H2(Ω)');
subplot(2,1,2); plot(abs(H3)); title('Response H(Ω)');

'예외처리' 카테고리의 다른 글

DSP_homework03  (0) 2008.05.13
DSP_homework01  (0) 2008.05.13
우사비치  (4) 2008.02.06

DSP_homework01

clear all; close all;
warning('off','MATLAB:dispatcher:InexactMatch')
% 1st Homework 'Using Window method'
% #1 For omega1 = pi / 2 and M = 10,

M=21;
n=-10:1:10;
wc=pi/2;
hd=ideal_lp(wc, M);

% (a) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of rect window
figure('name', 'Rectangular Window @ M=10', 'Position', [50, 420, 550, 300], 'MenuBar', 'none')
w_rect=(rectwin(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response'); hold on; axis([-(M-8) M-8 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h);
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (b) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of tri window
figure('name', 'Triangular Window @ M=10', 'Position', [250, 370, 550, 300], 'MenuBar', 'none')
w_rect=(triang(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response'); hold on; axis([-(M-8) M-8 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h);
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (c) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of hann window
figure('name', 'Hanning Window @ M=10', 'Position', [450, 330, 550, 300], 'MenuBar', 'none')
w_rect=(hann(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response'); hold on; axis([-(M-8) M-8 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h);
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (d) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of hamming window
figure('name', 'Hamming Window @ M=10', 'Position', [650, 280, 550, 300], 'MenuBar', 'none')
w_rect=(hamming(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response');  hold on; axis([-(M-8) M-8 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h)
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (e) Discuss the results

% #2 For omega1 = pi / 2 and M = 20,
M=41;
n=-20:1:20;
wc=pi/2;
hd=ideal_lp(wc, M);

% (a) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of rect window
figure('name', 'Rectangular Window @ M=20', 'Position', [50, 300, 550, 300], 'MenuBar', 'none')
w_rect=(rectwin(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response'); hold on; axis([-(M-18) M-18 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h);
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (b) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of tri window
figure('name', 'Triangular Window @ M=20', 'Position', [250, 250, 550, 300], 'MenuBar', 'none')
w_rect=(triang(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response'); hold on; axis([-(M-18) M-18 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h);
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (c) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of hann window
figure('name', 'Hanning Window @ M=20', 'Position', [450, 200, 550, 300], 'MenuBar', 'none')
w_rect=(hann(M));
h=hd.* w_rect';
[db,mag,pha,grd,w] = freqz_m(h,1);
[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response'); hold on; axis([-(M-18) M-18 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem(n,h);
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')

% (d) Draw w[n], W[omega] => dB scale  , h[n], H[omega] in case of hamming window
figure('name', 'Hamming Window @ M=20', 'Position', [650, 150, 550, 300], 'MenuBar', 'none')
w_rect=(hamming(M));
h=hd.* w_rect';

[db2,mag,pha,grd,w] = freqz_m(w_rect,1);
[db,mag,pha,grd,w] = freqz_m(h,1);
subplot(1,2,1); stem(n,w_rect, 'r');title('Response');  hold on; axis([-(M-18) M-18 -0.2 1.1]); xlabel('n'); ylabel('w(n)');
subplot(1,2,1); stem( n,h)
subplot(1,2,2); plot(w/pi,db2, 'r');title('Magnitude Response in dB');grid ; xlabel('frequency in pi units'); ylabel('Decibels'); hold on;
subplot(1,2,2); plot(w/pi,db); h = legend('W[Ω]','H[Ω]',1); set(h,'Interpreter','none')
% (e) Discuss the results

% #3 For input x[n]=cos(pi/6*n)+cos(pi/2*n),
% n=0, 1, ... , 23
M=24;
N=0:M-1;
input_n= cos((pi/6)*N)+cos((pi/2)*N);
% draw X(omega) and Y(omega) where Y(omega) = X(omega)H(omega)
[db1,mag1,pha,grd,w] = freqz_m(input_n,1);
[db2,mag2,pha,grd,w] = freqz_m(hamming(M),1);
mag3 = mag1 .* mag;
figure('name', 'cos((pi/6)*N)+cos((pi/2)*N) & n=0~23', 'Position', [300, 50, 600, 250], 'MenuBar', 'none')
plot(mag3); hold all; plot (mag); plot (mag1); hold off; figure(gcf)
h = legend('Y[Ω]','X[Ω]','H[Ω]',0); set(h,'Interpreter','none'); axis([0 500 0 24]);

'예외처리' 카테고리의 다른 글

DSP_homework02  (0) 2008.05.13
우사비치  (4) 2008.02.06
AVG 7.5 무료배포 이벤트!!  (0) 2008.01.07