lyl Lab Report1报告.docx

上传人:b****6 文档编号:7988555 上传时间:2023-01-27 格式:DOCX 页数:16 大小:97.68KB
下载 相关 举报
lyl Lab Report1报告.docx_第1页
第1页 / 共16页
lyl Lab Report1报告.docx_第2页
第2页 / 共16页
lyl Lab Report1报告.docx_第3页
第3页 / 共16页
lyl Lab Report1报告.docx_第4页
第4页 / 共16页
lyl Lab Report1报告.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

lyl Lab Report1报告.docx

《lyl Lab Report1报告.docx》由会员分享,可在线阅读,更多相关《lyl Lab Report1报告.docx(16页珍藏版)》请在冰豆网上搜索。

lyl Lab Report1报告.docx

lylLabReport1报告

 

LaboratoryReportofDigitalSignalProcessing

LabIII.FilterDesignandRealizationinMATLAB

 

Name:

岳成

No.:

5100309669

Date:

2013/4/24

 

SHANGHAIJIAOTONGUNIVERSITY

DepartmentofInstrumentScience&Engineering

Content

1Introduction1

2Exercises1

Ex.1Designaband-passEllipticfilter1

Ex.2AddechoestoMartinLutherKing’sspeech1

Ex.3Designadigitalequalizer2

3ResultsandDiscussion3

Ex.1Designaband-passEllipticfilter3

Ex.2AddechoestoMartinLutherKing’sspeech7

Ex.3Designadigitalequalizer9

4Summary11

5Reference11

1Introduction

ThislabconcentratesmainlyonthedesignandrealizationoffiltersinMATLAB.Theinfiniteimpulseresponse(IIR)filtersandfiniteimpulseresponse(FIR)filtersarecomparedtoeachotherforunderstandingtheircharacteristics.Besides,I/Odifferenceequationmethodiscarriedouttoconductfiltering.ApieceofpublicspeechofMartinLutherKingischosenasanexampletoshowtheeffectofechoesinonespeech.Inthefinal,adigitalequalizerisdesignedtochangeamusictodifferentstyle.Thislabincludesthefollowingexercises.

2Exercises

Ex.1Designaband-passEllipticfilter

1.1Referto‘IIRBUT.m’inthecourse,developananalogandadigitalband-passEllipticfilterwiththeMatlabfunction‘ellip’,respectively.Setthepropertiesofthefilter:

theordern=6,andthepassbandfrom400Hzto600Hz.ShowthefrequencyresponsesofMagnitudeandPhase.Providethecodesintheappendix.

1.2RefertotheMatlabfunction‘filter’,developasub-function‘myfilter’withtheinput/outputinterfaceof‘y=myfilter(b,a,x)’byusingtheI/Odifferenceequationmethod.Providethecodesof‘myfilter’inthereport.

1.3Createasignalcomposedofthreesinusoidsignalswithfrequenciesof100Hz,500Hzand1000Hz.Use‘myfilter’withthefiltercoefficientsoftheband-passfilterdevelopedin1.1toeliminatecomponentsof100Hzand1000Hz.Comparethesignalsbeforeandafterfilteringinboththetimedomainandthefrequencydomain.Providethecodesintheappendix.

Ex.2AddechoestoMartinLutherKing’sspeech

Aspeechcanbeheardmoreloudlyandstronglyinanemptyroomwithechoesthaninanopenareawithoutanyecho.However,iftheechoistoo‘strong’,thevoicewillbe‘blunt’andunclear.

ThegenerationofechoesisillustratedinFig.1,wheretheoutputsignalsoundy(t)isfedbackafteradelayTandscaledwithα.AndFig.1isthecorrespondingdiscrete-timesystemoftheechogeneration,wherethenumberofdelaysamplesis

andfsisthesamplingfrequencyofthesound.Typically,

assuccessiveechoesareattenuatednormally.

Fig.1Generatetheechointhecontinuous-anddiscrete-timesystems.

2.1AccordingtoFig.8,developthedifferenceequationofthesystemandcomparetheimpulseresponsesandthemagnitudesandphasesofthesystemwiththeparametersof

(1)

andk=5,10,100,respectively;

(2)k=10,and

respectively.

2.2Develop‘MyEcho.m’,importtheaudio‘dream.wav’andfilterthesoundwithadelaytimeT=0.5secandascale

.Thenplaythefilteredsoundtochecktheechoeffects.Providethecodesintheappendix.

Ex.3Designadigitalequalizer

In soundrecordingandreproduction, an equalizeriscommonlyusedtoalterthe frequencyresponse ofanaudiosystemusingagroupof linearfilters.An equalizer canbecircuitsforanalogsoundordigitalfiltersfordigitalsound.AsshowninFig.2,adigitalequalizerisaseriesoffilterswithdifferentgains.

3

3.1Constructanequalizerin‘myEQ.m’withasetoffilters.DesignthefilterseitherbyFDAtoolorbyMatlabfunctions.AgroupofanyIIRfiltersandagroupofanyFIRfiltersaredesignedtomeettherequirementsoftheequalizer,respectively.CutofffrequencyofeachfilterisillustratedinCht.1.

Cht.1Cut-offfrequencyofa5-filterequalizer

LPF1

BPF1

BPF2

BPF3

HPF1

fL(Hz)

60

250

1000

2000

fH(Hz)

60

250

1000

2000

3.2TunethegainofeachfilterandenjoydifferentsoundeffectwithparametersshowninCht.2.Chooseonesetofparametersanduseffttogetthefrequencyspectrumofboththeoriginalaudioandthetunedsignal.Plottheirspectrumtoseethedifference.Providethecodesintheappendix.

Cht.2Gainoptionsfordifferentstyles

α1

(dB)

α2

(dB)

α3

(dB)

α4

(dB)

α5

(dB)

Natural

0

0

0

0

0

Classic

0

80

80

40

0

Pop

30

10

0

-20

-40

Bass

80

60

0

-60

-80

Rock

-20

0

20

40

-20

3ResultsandDiscussion

Ex.1Designaband-passEllipticfilter

1.1

Fig.3ComparisonofFRFbetweendigitalandanalogfilter

 

labIII1_1.m

clc,clear,closeall

n=6;%order

Rp=0.5;Rs=20;

fl=400;wl=2*pi*fl;%lowband

fh=600;wh=2*pi*fh;%highband

df=0.001;

f=0:

df:

1000;w=2*pi*f;

%AnalogButterworthfilter(fHs)

[bs,as]=ellip(n,Rp,Rs,[wlwh],'s');

Hs=freqs(bs,as,w);

%DigitalButterworthfilter(fzHz)

fs=1500;

wnl=fl/(fs/2);

wnh=fh/(fs/2);

[bz,az]=ellip(n,Rp,Rs,[wnlwnh]);

[Hz,fz]=freqz(bz,az,1000,fs);

%showresults

figure

plot(fz,20*log10(abs(Hz)),f,20*log10(abs(Hs)),'r:

','linewidth',2);

legend('Digital','Analog','Location','northeast');

set(gca,'xscale','log')

xlim([1,1000])

ylim([-160,10])

xlabel('Frequency(Hz)')

ylabel('magnitude(dB)')

 

1.2

InI/Odifferenceequation,wecanuseexpression

togety[n].Beforethat,weshouldfirstgetx[i]andy[1]~y[n-1].

MyFilter.m

functionY=myfilter(b,a,x)

%%input

ifnargin<1

disp('NoInput!

');

return

end

B=b;

A=a;

X=x;

n=length(X);

m=length(A);

%%I/Odifferenceequation

l=0;

Y=zeros(1,n);

forjj=1:

m-1

forkk=1:

jj

ifkk==jj

l=B(kk)*X(jj-kk+1);

else

l=B(kk)*X(jj-kk+1)-A(jj-kk+1)*Y(kk);

end

Y(jj)=Y(jj)+l;

end

end

forii=m:

n

forkk=1:

m

ifkk==m

l=B(kk)*X(ii-kk+1);

else

l=B(kk)*X(ii-kk+1)-A(m-kk+1)*Y(ii-m+kk);

end

Y(ii)=Y(ii)+l;

end

end

%%outputresults

y=Y;

end

1.3

Fromthefigure,wecanseetheband-passfiltercandobetterinsignalprocessing,butthesignalwegetintimedomaindoesn’tlookwell.That’sbecausewecan’tfilterthesignalcompletelysothere’salsoalittleinterferenceinthesignal.

Fig.4FilteringaSignalswithEllipticFilter

abIII1_3.m

clc,clear,closeall

ord=6;%order

fs=10000;

Rp=0.5;Rs=20;

fl=400;wl=fl/(fs/2);%lowband

fh=600;wh=fh/(fs/2);%highband

[b,a]=ellip(ord,Rp,Rs,[wlwh]);

[Hz,fz]=freqz(b,a,1000,fs);

%%creatanimpulsesignal

fs_imp=100;

T_imp=1;

t_imp=0:

1/fs_imp:

T_imp;

imp=[1;zeros(length(t_imp)-1,1)];

%filterimpulsesignal

h_imp=MyFilter(b,a,imp);

%%createsignalswiththreedifferentfrequencies

f1=100;f2=500;f3=1000;

t=-1/f1:

1/fs:

1/f1;

n=length(t);

x1=sin(2*pi*f1*t);

x2=sin(2*pi*f2*t);

x3=sin(2*pi*f3*t);

x=x1+x2+x3;

%plot(t,x);

X=abs(fft(x)/(n/2));

F_X=fs*(0:

1/n:

1-1/n);

%%filterthesignal

h=MyFilter(b,a,x);

H=abs(fft(h)/(n/2));

F_H=fs*(0:

1/n:

1-1/n);

%%showresults

figure

subplot(3,2,1);plot(t,x,'linewidth',2);%xintimedomain

title('x(t)');

subplot(3,2,2);plot(F_X,X,'linewidth',2);%xinfrequencydomain

xlim([0,2000]);

title('X(j\omega)')

subplot(3,2,3);plot(t_imp,h_imp,'linewidth',2);%hintimedomain

title('h(n)')

subplot(3,2,4);plot(fz,abs(Hz),'linewidth',2);%hinfrequencydomain

xlim([0,1000]);

title('H(\omega)')

subplot(3,2,5);plot(t,h,'linewidth',2);%yintimedomain

title('y(t)')

xlabel('Time(s)')

subplot(3,2,6);plot(F_H,H,'linewidth',2);%yinfrequencydomain

xlim([0,2000]);

title('Y(j\omega)')

xlabel('Frequency(Hz)')

%%end

Ex.2AddechoestoMartinLutherKing’sspeech

2.1

Thefollowingsixfiguresshowstheresultsintheimpulseresponses,themagnitudesandphasesofthesystemwithdifferentparametersofkanda.Wewilltalkaboutthemrespectively.

Fig.5ImpulseResponsewithDifferentk

Thethreefiguresshowstheresultswithdifferentdelayk,inwhichFig.5showstheimpulseresponses,Fig.6showsthemagnitudesandFig.7showsthephases.

Fig.6MagnitudeswithDifferentk

Fig.7PhaseswithDifferentk

Thesethreefiguresshowstheresultswithdifferentscalea,inwhichFig.8showstheimpulseresponses,Fig.9showsthemagnitudesandFig.10showsthephases.Fromthesefigureswecanseethatdifferentaonlyaffecttheamplitudeinbothmagnitudesandphases,butthefrequencyisthesame.

Fig.8ImpulseResponsewithDifferenta

Fig.9MagnitudeswithDifferenta

Fig.10PhaseswithDifferenta

2.2

MyEcho.m

clc,clear,closeall

%getthewavefromdream.wav

[x_dream,fs,NBITS]=wavread('dream.wav');

x_cut=x_dream(1:

5*fs,1);

sound(x_cut);

%setparameters

T=0.5;

k=T*fs;

a=0.2;

%getthewavewithechoes

y=zeros(1,length(x_cut));

forii=1:

k

y(ii)=x_cut(ii);

end

forii=k+1:

length(x_cut)

y(ii)=a*y(ii-k)+x_cut(ii);

end

sound(y);

Ex.3Designadigitalequalizer

3.2

Fig.11DifferentFilterandSignalsthroughEachFilter

Fig.12OriginalAudio(up)andTunedClassicSignal(down)

Fig.11showsthefiltersandsignalsthrougheachfilter,Fig.12showstheoriginalaudio(up)andthetunedClassicsignal(down).

myEQ.m

clc,clear,closeall

%%

[x,fs,NBITS]=wavread('canon.wav');

x_cut=x(1:

10*fs,1);

%sound(x_cut);

%%somedefinition

Natural=[00000];

Classic=[08080400];

Pop=[30100-20-40];

Bass=[80600-60-80];

Rock=[-2002040-20];

style=cell(1,5);

style{1}=Natural;style{2}=Classic;

style{3}=Pop;style{4}=Bass;

style{5}=Rock;

filt=cell(1,5);

filt{1}='IIR_LPF.mat';filt{2}='IIR_BPF1.mat';

filt{3}='IIR_BPF2.mat';f

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1