Upload
anhbon
View
8
Download
4
Embed Size (px)
DESCRIPTION
free
Citation preview
TRNG I HC CNG NGHIP TP.HCM
KHOA CNG NGH IN T
BO THC HNH TH NGHIM X L S TN HIU
GVHD : Thy L VN HNG
NHM: 1
Nguyn Trung Dng: 12066601
Nguyn c Anh: 12010011
Nguyn Ch Cng: 12026261
Nguyn Vn Sinh: 12015781
Trn Thanh Bnh: 12009821
Chng 3
S RI RC THEO MIN THI GIAN PHN TCH FOURIER
V D 3.3 : Tnh ( ) trong v d 3.1 ti 501 im ri rc trong khong
v v li n di dng bin , gc, phn thc v phn o .
Code:
Kt Qu
w=[0:1:500]*pi/500;
X=exp(j*w)./(exp(j*w)-0.5*ones(1,501));
magX=abs(X); angX=angle(X) ; realX=real(X);imagX=imag(X);
subplot(2,2,1); plot(w/pi,magX); grid
xlabel('frequency in pi units'); ylabel('Magnitude'); title('Magnitude Part');
subplot(2,2,3); plot(w/pi,angX);grid
xlabel('frequency in pi units'); title('Angle Part'); ylabel('Radians')
subplot(2,2,2); plot(w/pi,realX); grid
xlabel('frequency in pi units'); title('Real Part'); ylabel('Real')
subplot(2,2,4); plot(w/pi,imagX); grid
xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary')
V D 3.4 :
Code:
Kt qu:
n = -1:3; x = 1:5; k = 0:500; w = (pi/500)*k;
X = x * (exp(-j*pi/500)) .^ (n'*k);
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
subplot(2,2,1); plot(k/500,magX);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,3); plot(k/500,angX/pi);grid
xlabel('frequency in pi units'); title('Angle Part')
subplot(2,2,2); plot(k/500,realX);grid
xlabel('frequency in pi units'); title('Real Part')
subplot(2,2,4); plot(k/500,imagX);grid
xlabel('frequency in pi units'); title('Imaginary Part')
V D 3.5: Cho x(n) = (0.9 exp (j /3))n , 0 . Xc nh X( ) v tnh
tun hon ca n.
Code:
KT QU
n = 0:10; x = (0.9*exp(j*pi/3)).^n;
k = -200:200; w = (pi/100)*k;X = x * (exp(-j*pi/100)) .^ (n'*k);
magX = abs(X); angX =angle(X);
subplot(2,1,1); plot(w/pi,magX);grid
xlabel('frequency in units of pi'); ylabel('|X|')
title('Magnitude Part')
subplot(2,1,2); plot(w/pi,angX/pi);grid
xlabel('frequency in units of pi'); ylabel('radians/pi')
title('Angle Part')
V D 3.6 : Cho x(n) = 2n , 10 .Tm hiu tnh cht lin hp i xng
ca bin i Fourier ri rc thi gian
Code:
Kt qu:
KT QU
n = -5:5; x = (-0.9).^n;k = -200:200; w = (pi/100)*k;
X = x * (exp(-j*pi/100)) .^ (n'*k);
magX = abs(X); angX =angle(X);
subplot(2,1,1); plot(w/pi,magX);grid; axis([-2,2,0,15])
xlabel('frequency in units of pi'); ylabel('|X|')
title('Magnitude Part')
subplot(2,1,2); plot(w/pi,angX/pi);grid; axis([-2,2,-1,1])
xlabel('frequency in units of pi'); ylabel('radians/pi')
title('Angle Part')
V D 3.7 : Trong v d ny,chng ta s xc minh tnh cht tuyn tnh (3.5)
bng cch s dng gi tr thc trong chui thi gian hu hn. x1(n) v x2(n) l
2 chui ngu nhin thng nht c phn chia gia [0,1] vi 0 n 10. Sau
chng ta c th s dng s bin i Fourier thi gian ri rc theo
phng php nh sau :
Code:
V D 3.8 : Cho x(n) l mt chui ngu nhin phn b ng u gia [0,1] vi
0 n 10 v cho y(n) = x(n-2). Sau chng ta c th xc nh c tnh thay
i mu (3.6) nh sau :
x1 = rand(1,11); x2 = rand(1,11); n = 0:10;
alpha = 2; beta = 3; k = 0:500; w = (pi/500)*k;
X1 = x1 * (exp(-j*pi/500)).^(n'*k); % DTFT of x1
X2 = x2 * (exp(-j*pi/500)).^(n'*k); % DTFT of x2
x = alpha*x1 + beta*x2; % Linear combination of x1 & x2
X = x * (exp(-j*pi/500)).^(n'*k); % DTFT of x
% verification
X_check = alpha*X1 + beta*X2; % Linear Combination of X1 & X2
error = max(abs(X-X_check)) % Difference
error =
7.3241e-15
x = rand(1,11); n = 0:10;
k = 0:500; w = (pi/500)*k;
X = x * (exp(-j*pi/500)).^(n'*k); % DTFT of x
% signal shifted by two samples
y = x; m = n+2;
Y = y * (exp(-j*pi/500)).^(m'*k); % DTFT of y
% verification
Y_check = (exp(-j*2).^w).*X; % multiplication by exp(-j2w)
error = max(abs(Y-Y_check)) % Difference
error =
5.7756e-15
V D 3.9 : xc nh c tnh thay i tn s (3.7), chng ta s s dng
phng php th : X(n)= cos(
) , 0 n 100 v
y(n)= x(n)
Code:
Kt qu:
n = 0:100; x = cos(pi*n/2);
k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
%
y = exp(j*pi*n/4).*x; % signal multiplied by exp(j*pi*n/4)
Y = y * (exp(-j*pi/100)).^(n'*k); % DTFT of y
% Graphical verification
subplot(2,2,1); plot(w/pi,abs(X)); grid; axis([-1,1,0,60])
xlabel('frequency in pi units'); ylabel('|X|')
title('Magnitude of X')
subplot(2,2,2); plot(w/pi,angle(X)/pi); grid; axis([-1,1,-1,1])
xlabel('frequency in pi units'); ylabel('radiands/pi')
title('Angle of X')
subplot(2,2,3); plot(w/pi,abs(Y)); grid; axis([-1,1,0,60])
xlabel('frequency in pi units'); ylabel('|Y|')
title('Magnitude of Y')
subplot(2,2,4); plot(w/pi,angle(Y)/pi); grid; axis([-1,1,-1,1])
xlabel('frequency in pi units'); ylabel('radians/pi')
title('Angle of Y')
V D 3.10 : th li tnh cht kt hp ( ) ( ), cho x(n) l mt
chui ngu nhin cc gi tr phc t -5 n 10 vi thc v phn o u c
ph n phi gia 0,1 . im chng vi MATLAP nh sau :
Code:
V D 3.11 : xc nh thuc tnh 3.9. Cho x (n) l mt chui ngu nhin
trn -5 n 10 v phn b ng u gia [0,1] .
n = -5:10; x = rand(1,length(n)) + j*rand(1,length(n));
k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
% conjugation property
y = conj(x); % signal conjugation
Y = y * (exp(-j*pi/100)).^(n'*k); % DTFT of y
% verification
Y_check = conj(fliplr(X)); % conj(X(-w))
error = max(abs(Y-Y_check)) % Difference
error =
8.6764e-14
n = -5:10; x = rand(1,length(n));
k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
% folding property
y = fliplr(x); m = -fliplr(n); % signal folding
Y = y * (exp(-j*pi/100)).^(m'*k); % DTFT of y
% verification
Y_check = fliplr(X); % X(-w)
error = max(abs(Y-Y_check)) % Difference
error =
1.7902e-15
V D 3.12 : T ong bi ton ny chng ta th i tnh cht ph p i xng (
3.10 );
x(n) = sin(n/2), 5 n 10
n = -5:10; x = sin(pi*n/2);
k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
% signal decomposition
[xe,xo,m] = evenodd(x,n); % even and odd parts
XE = xe * (exp(-j*pi/100)).^(m'*k); % DTFT of xe
XO = xo * (exp(-j*pi/100)).^(m'*k); % DTFT of xo
% verification
XR = real(X); % real part of X
error1 = max(abs(XE-XR)) % Difference
error1 =
6.4862e-14
n = -5:10; x = sin(pi*n/2);
k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
% signal decomposition
[xe,xo,m] = evenodd(x,n); % even and odd parts
XE = xe * (exp(-j*pi/100)).^(m'*k); % DTFT of xe
XO = xo * (exp(-j*pi/100)).^(m'*k); % DTFT of xo
% verification
XR = real(X); % real part of X
error1 = max(abs(XE-XR)) % Difference
error1 =
6.4862e-14
XI = imag(X); % imag part of X
error2 = max(abs(XO-j*XI)) % Difference
error2 =
6.4492e-14
% graphical verification
subplot(2,2,1); plot(w/pi,XR); grid; axis([-1,1,-2,2])
xlabel('frequency in pi units'); ylabel('Re(X)');
title('Real part of X')
subplot(2,2,2); plot(w/pi,XI); grid; axis([-1,1,-10,10])
xlabel('frequency in pi units'); ylabel('Im(X)');
title('Imaginary part of X')
subplot(2,2,3); plot(w/pi,real(XE)); grid; axis([-1,1,-2,2])
xlabel('frequency in pi units'); ylabel('XE');
title('Transform of even part')
subplot(2,2,4); plot(w/pi,imag(XO)); grid; axis([-1,1,-10,10])
xlabel('frequency in pi units'); ylabel('XO' title('Transform of odd part')
EXAMPLE 3.13 : p ng tn s H( ) ca h thng c t ng bi , h(n) =
( ) ( ) .
Kt qu
w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points.
H = exp(j*w) ./ (exp(j*w) - 0.9*ones(1,501));
magH = abs(H); angH = angle(H);
subplot(2,1,1); plot(w/pi,magH); grid;
xlabel('frequency in pi units'); ylabel('|H|');
title('Magnitude Response');
subplot(2,1,2); plot(w/pi,angH/pi); grid
xlabel('frequency in pi units'); ylabel('Phase in pi Radians');
title('Phase Response');
EXAMPLE 3.15 Mt h thng LTI c a a cc phng t nh khc bit,
Y(n)=0.8y(n-1)+x(n)
a.xc inh H( ).
b. xc nh v v th ( ) x(n)=cos(0.05 ) ( )
vit li phng t nh khc nh y(n) -0.8y(n-1)=x(n)
KT QU
subplot(1,1,1)
b = 1; a = [1,-0.8];
n=[0:100];x = cos(0.05*pi*n);
y = filter(b,a,x);
subplot(2,1,1); stem(n,x);
xlabel('n'); ylabel('x(n)'); title('Input sequence')
subplot(2,1,2); stem(n,y);
xlabel('n'); ylabel('y(n)'); title('Output sequence')
EXAMPLE 3.16 : Y(n)=0.0181x(n) +0.0543x(n-1) + 0.0543x(n-2) +0.0181x(n-
3)+ 1.7y(n-1) 1.1829y(n-2) + 0.2781y(n-3) Biu din cc cng v p ng
pha ca b lc ny v chng minh n l mt b lc, chng ta s biu din trn
Malab
KT QU
b = [0.0181, 0.0543, 0.0543, 0.0181]; % filter coefficient array b
a = [1.0000, -1.7600, 1.1829, -0.2781]; % filter coefficient array a
m = 0:length(b)-1; l = 0:length(a)-1; % index arrays m and l
K = 500; k = 0:1:K; % index array k for frequencies
w = pi*k/K; % [0, pi] axis divided into 501 points.
num = b * exp(-j*m'*w); % Numerator calculations
den = a * exp(-j*l'*w); % Denominator calculations
H = num ./ den; % Frequency response
magH = abs(H); angH = angle(H); % mag and phase responses
subplot(2,1,1); plot(w/pi,magH); grid; axis([0,1,0,1])
xlabel('frequency in pi units'); ylabel('|H|');
title('Magnitude Response');
subplot(2,1,2); plot(w/pi,angH/pi); grid
xlabel('frequency in pi units'); ylabel('Phase in pi Radians');
title('Phase Response');
EXAMPLE 3.18 cho xa(t)=e-1000|t|
xc nh v v Fourier ca n bin i dng
Matlap
Kt Qu:
% Analog Signal
Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));
% Continuous-time Fourier Transform
Wmax = 2*pi*2000; K = 500; k = 0:1:K; W = k*Wmax/K;
Xa = xa * exp(-j*t'*W) * Dt; Xa = real(Xa);
W = [-fliplr(W), W(2:501)]; % Omega from -Wmax to Wmax
Xa = [fliplr(Xa), Xa(2:501)]; % Xa over -Wmax to Wmax interval
subplot(2,1,1);plot(t*1000,xa);
xlabel('t in msec.'); ylabel('xa(t)')
title('Analog Signal')
subplot(2,1,2);plot(W/(2*pi*1000),Xa*1000);
xlabel('Frequency in KHz'); ylabel('Xa(jW)*1000')
title('Continuous-time Fourier Transform')
EXAMPLE 3.19
Kt Qu
% Analog Signal
Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));
% Discrete-time Signal
Ts = 0.0002; n = -25:1:25; x = exp(-1000*abs(n*Ts));
% Discrete-time Fourier transform
K = 500; k = 0:1:K; w = pi*k/K;
X = x * exp(-j*n'*w); X = real(X);
w = [-fliplr(w), w(2:K+1)]; X = [fliplr(X), X(2:K+1)];
subplot(2,1,1);plot(t*1000,xa);
xlabel('t in msec.'); ylabel('x1(n)')
title('Discrete Signal'); hold on
stem(n*Ts*1000,x); gtext('Ts=0.2 msec'); hold off
subplot(2,1,2);plot(w/pi,X);
xlabel('Frequency in pi units'); ylabel('X1(w)')
title('Discrete-time Fourier Transform')
EXAMPLE 3.21
Kt Qu:
error =
0.0363
EXAMPLE 3.22
KT QU
error =
0.1852
% Discrete-time Signal x1(n)
Ts = 0.0002; n = -25:1:25; nTs = n*Ts; x = exp(-1000*abs(nTs));
Fs=1/Ts;
% Analog Signal reconstruction
Dt = 0.00005; t = -0.005:Dt:0.005;
xa = x * sinc(Fs*(ones(length(n),1)*t-nTs'*ones(1,length(t))));
% check
error = max(abs(xa - exp(-1000*abs(t))))
% Discrete-time Signal x2(n)
Ts = 0.001; n = -5:1:5; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Analog Signal reconstruction
Dt = 0.00005; t = -0.005:Dt:0.005;
xa = x * sinc(Fs*(ones(length(n),1)*t-nTs'*ones(1,length(t))));
% check
error = max(abs(xa - exp(-1000*abs(t))))
EXAMPLE 3.23
Kt Qu:
% Discrete-time Signal x1(n) : Ts = 0.0002
Ts = 0.0002; n = -25:1:25; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Plots
subplot(2,1,1); stairs(nTs*1000,x);
xlabel('t in msec.'); ylabel('xa(t)')
title('Reconstructed Signal from x1(n) using zero-order-hold'); hold on
stem(n*Ts*1000,x); hold off
%
% Discrete-time Signal x2(n) : Ts = 0.001
Ts = 0.001; n = -5:1:5; nTs = n*Ts; x = exp(-1000*abs(nTs));
% Plots
subplot(2,1,2); plot(nTs*1000,x);
xlabel('t in msec.'); ylabel('xa(t)')
title('Reconstructed Signal from x2(n) using zero-order-hold'); hold on
stem(n*Ts*1000,x); hold off
Phn Bi Tp Chng 3
P 3.11 : i vi mi tuyn tnh, h thng thay i bt bin c m t bi cc p
ng xung, xc nh chc nng p ng tn s H(ejw). V p ng bin |H(ejw)|
v p ng pha H(ejw) trn khong :
Dng hm dtft
% P3.11
colordef white; clear; clc;
M = 250; k = -M:M; w = (pi/M)*k; % [0, pi] axis divided into 501 points.
w0 = pi/2; figure(1);
n = -50:50;
%P3.11.1
h = (0.9).^(abs(n));
H = dtft(h,n,w);
subplot(3,2,1); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,2); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
%P3.11.2
h = sinc(0.2*n).*((stepseq(-20,-50,50)-stepseq(20,-50,50)));
H = dtft(h,n,w);
subplot(3,2,3); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,4); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
%P3.11.3
h = sinc(0.2*n).*((stepseq(0,-50,50)-stepseq(40,-50,50)));
H = dtft(h,n,w);
subplot(3,2,5); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,6); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
%P3.11.4
figure(2);
h = ((0.5).^n+(0.4).^n).*stepseq(0,-50,50);
H = dtft(h,n,w);
subplot(3,2,1); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,2); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
%P3.11.5
h = (0.5).^(abs(n)).*cos(0.1*pi*n);
H = dtft(h,n,w);
subplot(3,2,3); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,4); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
Khng dng hm dfft
% P3.11.2
k=-500:500;n = -20:20; w=(pi/500)*k
h = sinc(0.2*n);
H = h * (exp(-j*pi/500)) .^ (n'*k);
subplot(3,2,3); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,4); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
%P3.11.3
k=-500:500;n = 0:39; w=(pi/500)*k
h = sinc(0.2*n);
H = h * (exp(-j*pi/500)) .^ (n'*k);
subplot(3,2,3); plot(w/pi,abs(H),'k');
xlabel('frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
subplot(3,2,4); plot(w/pi,angle(H)/pi,'k');
xlabel('frequency in pi units'); ylabel('\Theta'); title('Phase Response');
Chng 4
Bin i Z- (Z ngc)
P4.2 Cho chui x(n) = (0.9)n cos( n/4)u(n) .
( ) { (
)
1. Chng t Z ngc Y(z) ca y(n) c biu din theo Z ngc X(z) ca x(n)
l Y(z) = X(z2)
2. Xc nh Y(z)
3. Dng Matlab kim chng rng dy y(n) c bin i Z ngc Y(z)
Bi lm
1. Ta c :
( ) ( )
( ) ( )
M, ( ) ( ) nn :
( ) ( )
( ) ( )
( )
2. Ta C: x(n) = (0.9)n cos( n/4)u(n)
suy ra : ( )
Hay: ( )
(do Y(z) = X(z2) )
Code
Kt qu:
%P4.2
b = [1,0,-0.9*sqrt(2)/2,0,0]; a=[1,0,-0.9*sqrt(2),0,0.81]; [R,p,C] = residuez(b,a)
w=[0:1:500]*pi/500; Y = freqz(b,a,w);
magY = abs(Y); phaY = angle(Y);
subplot(2,1,1); plot(w/pi,magY); grid
xlabel('frequency in pi units'); ylabel('Magnitude')
title('Magnitude Response')
subplot(2,1,2); plot(w/pi,phaY/pi); grid
xlabel('frequency in pi units'); ylabel('Phase in pi units')
title('Phase Response')
P4.21 Mt b lc k thut s c m t bi hm p ng tn s
( ) ( ) ( ) (
)
To 200 mu ca tn hiu x(n) = sin( n/2) + 5cos( n), v x l thng qua cc b
lc c c y(n) . So snh phn trng thi n nh y(n) vi x(n). bin v
pha b nh hng nhu the nao bi cc b lc .
Bi Lm
Ta c :
( )
Hay : y(n) = 3x(n) + 2x(n-1) + 6x(n-2) + 3x(n-3) + 5x(n-4) + 3x(n-5)
%P4.21
subplot(1,1,1)
b = [3,2,6,3,5,3]; a = [1]; n = [0:200];
x =sin(n*pi/2)+ 5*cos(n*pi); y = filter(b,a,x);
subplot(2,1,1); stem(n,x);
xlabel('n'); ylabel('x(n)'); title('Input sequence')
subplot(2,1,2); stem(n,y);
xlabel('n'); ylabel('y(n)'); title('Output sequence')
Chng 7
Thit k b lc FIR
V D 7.4 :
Cho h(n) = {-4, 1, -1, -2, 5, 6, 5, -2, -1, 1, -4}. Xc nh cc p ng bin
Hr v v tr cc cc khng ca H(z).
Bi lm
T M=11 l s l v t h(n) i xng ( ) = 5 , nn l b lc tuyn
tnh FIR Type-1
M :
( ) ( )
( )
Vi
( ) (
) ( ) (
)
Do :
( )
% Vi Du 7.4
h = [-4,1,-1,-2,5,6,5,-2,-1,1,-4];
M = length(h); n = 0:M-1;
[Hr,w,a,L] = Hr_Type1(h);
a,L;
amax = max(a)+1; amin = min(a)-1;
subplot(2,2,1); stem(n,h); axis([-1 2*L+1 amin amax])
xlabel('n'); ylabel('h(n)'); title('Impulse Response')
subplot(2,2,3); stem(0:L,a); axis([-1 2*L+1 amin amax])
xlabel('n'); ylabel('a(n)'); title('a(n) coefficients')
subplot(2,2,2); plot(w/pi,Hr);grid
xlabel('frequency in pi units'); ylabel('Hr')
title('Type-1 Amplitude Response')
subplot(2,2,4); zplane(h,1)% thay zplane cho pzplo
V D 7.8 :
Thit k mt b lc thng thp FIR k thut s vi cc thng s k thut sau
y :
Chn mt ca s chc nng thch hp t bng 7.1. Xc nh cc xung p ng
v cung cp mt th ca p ng tn s ca b lc thit k.
% Vi Du 7.8
wp = 0.2*pi; ws = 0.3*pi; tr_width = ws - wp;
M = ceil(6.6*pi/tr_width) + 1
n=[0:1:M-1];
wc = (ws+wp)/2, % Ideal LPF cutoff frequency
hd = ideal_lp(wc,M); w_ham = (hamming(M))'; h = hd .* w_ham;
[db,mag,pha,grd,w] = freqz_m(h,[1]); delta_w = 2*pi/1000;
Rp = -(min(db(1:1:wp/delta_w+1))); % Actual Passband Ripple
As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband attenuation
% plots
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2); stem(n,w_ham);title('Hamming Window')
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)')
subplot(2,2,4); plot(w/pi,db);title('Magnitude Response in dB');grid
axis([0 1 -100 10]); xlabel('frequency in pi units'); ylabel('Decibels')
CCS (Code Composer Studio)
Bi 1 : Thit k mt sng sin m thanh sao cho fton = 9,6k ( vi fs = 96k )
Bi lm
Ta c :
Li c :
( )
T : sine_table [10] = {0,588,951,951,588,0,-588,-951,-951,-588}
//Sine8_LED.c Sine generation with DIP switch control
#include "dsk6416_aic23.h" //support file for codec,DSK
Uint32 fs = DSK6416_AIC23_FREQ_96KHZ;//set sampling rate
short loop = 0;
short i=0; //table index
short gain = 10; //gain factor
short sine_table[10]={0,588,951,951,588,0,-588,-951,-951,-588};//sine values
#define BUFFSIZE 128
// Global Variables
short gBuffer[BUFFSIZE];
void main()
{
//comm_poll(); //init DSK,codec,McBSP
c6416_dsk_init();
DSK6416_LED_init(); //init LED from BSL
DSK6416_DIP_init(); //init DIP from BSL
while(1) //infinite loop
for (i=0; i< BUFFSIZE; i++)
{
if(DSK6416_DIP_get(0)==0) //=0 if DIP switch #0 pressed
{
DSK6416_LED_on(0);//turn LED #0 ON
for (loop=0; loop
Kt qu
Bi 2 Thit k FIR
Bi lm
Code
//Fir.c FIR filter with the C6416 DSK. Include coefficient file
#include "lp1500_256.cof" //coefficient file
#include "dsk6416_aic23.h" //codec-dsk support file
Uint32 fs=DSK6416_AIC23_FREQ_48KHZ; //set sampling rate
int yn = 0; //initialize filter's
output
short dly[N];
short gbuffer[200]; //delay samples
interrupt void c_int11() //ISR
{
short i;
dly[0]=input_sample(); //input newest sample
yn = 0; //initialize filter's output
for (i = 0; i< N; i++)
yn += (h[i] * dly[i]); //y(n) += h(i)* x(n-i)
for (i = N-1; i > 0; i--) //starting @ end of buffer
dly[i] = dly[i-1]; //update delays with data move
output_sample((short)(yn>>15)); //scale output filter sample
gbuffer[i]=((short)(yn>>15));
return;
}
void main()
{
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
}
Kt qu