dsp机考参考Word文档下载推荐.docx
《dsp机考参考Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《dsp机考参考Word文档下载推荐.docx(26页珍藏版)》请在冰点文库上搜索。
:
%由于用freqz计算频点至少是2个,所以至少输入两个频点
w1=input('
请输入你要计算的频点w1='
w2=input('
请输入你要计算的频点w2='
w=[w1w2];
num=[25953];
den=[545211];
h=freqz(num,den,w)
(6)WriteaMATLABprogramtocomputeandplotthemagnituderesponseofacausalLTIdiscrete-timesystemwithatransferfunctiongivenby
num=0.15*[10-1];
den=[1-0.50.7];
[h,w]=freqz(num,den,512);
plot(w/pi,abs(h))
(7)ConsiderthefollowingFIRtransferfunction:
UsingMATLABtodetermineitszerolocationsandplotitsmagnitudeandphaseresponse.
h=[10.6.49-0.48-0.14-0.120.09];
figure
(1)
zplane(h,1);
[H,w]=freqz(h,1,512);
figure
(2)
plot(w/pi,abs(H))
figure(3)
plot(w/pi,angle(H))
(8)Givenasignal
whenusingasamplingfrequencyfT=20KHz,plotthemagnitudeandphasespectrumofthesampledsequence(givenlength-64).
fs=2e4;
n=(0:
63)/fs;
x=4*n+cos(0.1*pi*n);
h=fft(x,512);
2/511:
2,abs(h))
2,angle(h))
(9)designanIIRbutterworthdigitallowpassfilterwiththefollowingspecifications:
samplingrate
of40kHz,passbandedgefrequencyof4kHz,stopbandedgefrequencyof8kHz,passbandrippleof0.5dB,andaminimumstopbandattenuationof40dB,plotfrequency-magnitudeandcheckifyourdesignfitsthespecification.
fs=40;
wp=4*2/fs;
ws=8*2/fs;
ap=0.5;
as=40;
[n,wn]=buttord(wp,ws,ap,as);
[num,den]=butter(n,wn);
plot(w/pi,20*log10(abs(h)))
axis([01-500])
axis([0wp-0.50]);
title('
通带纹波'
)
axis([ws1-50-30])
阻带纹波'
(10)DesignaHanningFIRlowpassfiltermeetingthefollowingspecifications:
passbandedgefrequency=2kHz,stopbandedgefrequency=2.5kHz,passbandrippleδp=0.005,stopbandrippleδs=0.005,andsamplingrateof10kHz.Plotitsgainandphaseresponsesandcheckifitmeetsthespecifications?
ft=10;
fp=2;
fs=2.5;
wp=2*pi*fp/ft;
ws=2*pi*fs/ft;
ds=0.005;
ap=20*log10(1-ds);
as=20*log10(ds)
wc=(wp+ws)/2;
dw=ws-wp;
M=ceil(3.11*pi/dw);
N=2*M;
b=fir1(N,wc/pi,hann(N+1));
[h,w]=freqz(b,1,512);
plot(w/pi,20*log10(abs(h)));
magituderesponse'
plot(w/pi,unwrap(angle(h)));
phaseresponse'
axis([0wp/piap0])
axis([ws/pi1as0])
%从图中可以看出,通带和阻带中纹波都不满足要求,所以不满足指标
%as=-46.0206<
43.9所以不能用hanning窗设计
%应当用hamming或blackman窗设计
1.DFT定义,矩阵形式运算,循环运算1
2.fir1,kaiserord,Kaiser,freqz2
3.cheb1ord,cheb12
4.系统函数的二阶分解,tf2sos,tf2zp,sort,unique3
5.零极点形式到直接型的转换3
6.阶数估计(表10.2),hann,fir1,根据定义加窗4
7.freqz,real,imag,abs,angle,unwrap,phase4
8.fir1,hamming窗5
9.直接型转零极点型,tf2zp6
10.butter,buttord6
11.部分分式展开(逆),从传输函数计算冲击响应,residuez,impz7
12.freqz,real,imag,abs,phase,angle,unwrap7
13.ellipord,ellip,freqz8
14.fir1,hann,分贝转换9
15.信号能量计算9
16.各IIR阶数估计,buttord,cheb1ord,cheb2ord,ellipord9
17.square,freqz10
18.线性卷积,此处用fft实现11
19.圆周卷积,要求用基于DFT的方法实现11
20.部分分式展开,逆z变换,residuez12
21.freqz13
22.信号通过系统的输出,filter13
23.信号通过系统的输出,filter13
24.重要提示14
1.DFT定义,矩阵形式运算,循环运算
%WritingaMATLABprogramtocompute128-pointDFTof
%thefollowingsequence,youmustfirstlyuse
%DFTdefinition(directlycomputingDFT)tocompute
%anduseMATLABfunctiontotesttheresult.
%Plotthetworesultsinonefigure.
%g[n]=sin(pi*n/4),0<
=n<
=31
N=32;
M=128;
n=0:
(N-1);
m=0:
(M-1);
g=sin(pi*n/4);
%DFTdefinition%matrixexpressionofDFT
G1=g*exp(-2*j*pi/M).^(n'
*m);
%followingisthedirectconversion
%fromdefinitiontocode
%forii=0:
M-1
%G1(ii+1)=0;
%forjj=0:
N-1
%G1(ii+1)=G1(ii+1)+g(jj+1)*exp(-2*j*pi/M*ii*jj);
%end
%endsubplot(2,1,1);
plot(m,abs(G1));
%fftrealizedbyMATLAB
G2=fft(g,M);
subplot(2,1,2);
plot(m,abs(G2));
2.fir1,kaiserord,Kaiser,freqz
%Usingthefunctionfir1andwindowofKaiser,
%designalinear-phaseFIRlowpassfilter
%meetingthefollowingspecifications:
%passbandedgefrequency=2kHz,
%stopbandedgefrequency=2.5kHz,
%passbandrippleδp=0.005,
%stopbandrippleδs=0.005,
%andsamplingrateof10kHz.
%Plotitsgainandphaseresponses
%andcheckifitmeetsthespecifications?
fsamp=10000;
fcuts=[20002500];
mags=[10];
devs=[0.0050.005];
[n,Wn,beta,ftype]=kaiserord(fcuts,mags,devs,fsamp);
hh=fir1(n,Wn,kaiser(n+1,beta),'
noscale'
freqz(hh)
3.cheb1ord,cheb1
%DesignaType1ChebyshevIIRlowpassfiltermeeting
%thespecificationsasbelow:
%samplingrateof12kHz,
%passbandedgefrequencyof2.1kHz,
%stopbandedgefrequencyof2.7kHz,
%passbandrippleof0.6dB,
%andaminimumstopbandattenuationof45dB.
%Writedowntheexactexpressionfor
%thetransferfunctiongenerated.
%Doesyourdesignmeetthespecifications?
Fs=12000;
Fn=Fs/2;
%Nyquistcriterion
Wp=2100/Fn;
Ws=2700/Fn;
Rp=0.6;
Rs=45;
[n,Wn]=cheb1ord(Wp,Ws,Rp,Rs)
[b,a]=cheby1(n,Rp,Wn)
freqz(b,a,512,Fs);
%b=
%0.00010.00090.00320.0064...
%0.00800.00640.00320.00090.0001
%a=
%1.0000-4.681811.1095-16.8220...
%17.5480-12.83006.4101-2.00620.3038
4.系统函数的二阶分解,tf2sos,tf2zp,sort,unique
%UsingMATLABdeterminethesecond-orderfactoredform
%ofthefollowingz-transforms.Andshowtheirpole-zeroplots.
%ThendetermineallpossibleROCsofabovez-transform.
%4*z^4+15.6*z^3+6*z^2+2.4*z-6.4
%G1(z)=-----------------------------------------------
%3*z^4+2.4*z^3+6.3*z^2-11.4*z+6
num=[4,15.6,6,2.4,-6.4];
den=[3,2.4,6.3,-11.4,6];
[sosg]=tf2sos(num,den)
[zpk]=tf2zp(num,den);
pp=sort(unique([0,abs(p)'
inf]));
forii=1:
length(pp)-1
fprintf('
possibleROC%d:
(%f,%f)\n'
ii,pp(ii),pp(ii+1));
end
5.零极点形式到直接型的转换
%WriteaMATLABprogramtocomputeanddisplay
%therationalz-transformfromitszero,
%polesandgainconstant.IftheDTFTof
%thecausalsystemexists,trytoplot
%it'
smagnitudeandphasespectra.
%Usingthisprogramtodeterminetherationalform
%ofaz-transformwhosezeroareat
%ξ1=1.2,ξ2=2.3-j0.5,ξ3=-0.4+j0.2,ξ4=-0.4-j0.2,ξ5=2.3+j0.5;
%theploesareat
%λ1=0.5,λ2=-0.75+j0.2,λ3=0.6+j0.7,λ4=0.6-j0.7,λ5=-0.75-j0.2;
%andthegainconstantkis2.1.functionmainz=[1.2,2.3-j*0.5,-0.4+j*0.2,-0.4-j*0.2,2.3+j*0.5];
p=[0.5,-0.75,+j*0.2,0.6+j*0.7,0.6-j*0.7,-0.75-j*0.2];
k=2.1;
rzt(z,p,k);
return;
functionrzt(z,p,k)
%computeanddisplay
num=k*poly(z)
den=poly(p)
freqz(num,den);
6.阶数估计(表10.2),hann,fir1,根据定义加窗
%DesignanFIRhanningdigitallowpassfilter
%withthefollowingspecifications:
%passbandedgefrequency0.3*pi,
%stopbandedgefrequency0.4*pi,
%stopbandattenuation40dB.
%Pleaseplotfrequency-magnitituderesponse
%andcheckifyourdesignfitthespecification。
wp=0.3*pi;
ws=0.4*pi;
wn=(wp+ws)/2;
rs=40;
%choosehanningwindowaccordingtotable10.2%basicparameter
dw=ws-wp;
M=ceil(3.11*pi/dw);
N=M*2;
%lengthis(N+1)%designusingfir1
h=fir1(N,wn/pi,hann(N+1));
freqz(h,1);
figure;
%designaccordingtoCHAP10
wc=(wp+ws)/2;
n=-M:
M;
hd=wc/pi*sinc(n*wc/pi);
w=0.5+0.5*cos(2*pi*n/(N+1));
ht=hd.*w;
freqz(ht,1);
7.freqz,real,imag,abs,angle,unwrap,phase
%Givenasignal
%x(t)=sin(0.1*pi*t)+2*cos(0.3*pi*t)+3*sin(0.5*pi*t)
%whenusingasamplingfrequencyfT=20KHz,
%plotthemagnitudeandphasespectrumofthesampledsequence
%(givenlength-64).
N=64;
fT=20*1000;
N-1;
t=n/fT;
x=sin(0.1*pi*t)+2*cos(0.3*pi*t)+3*sin(0.5*pi*t);
[hw]=freqz(x,1);
subplot(2,1,1);
plot(w,abs(h));
Magnitude'
);
xlabel('
\omega/\pi'
ylabel('
plot(w,angle(h));
%angle()wraptheresultsto[-pi,pi]
Phase'
8.fir1,hamming窗
%Usingthefunctionfir1andwindowofHamming,
%stopbandedgefrequency=2.3kHz,
%passbandrippleδp=0.002,
%stopbandrippleδs=0.002
%andsamplingrateof20kHz.
rp=0.002;
%thetwoparameterisonlyusedto
%determinewhichwindowtochoose
%accordingtotable10.2
rs=0.002;
%=26.9897dB,hammingwindowcandofp=2*1000;
fs=2.3*100