lyl Lab Report1报告Word格式文档下载.docx
《lyl Lab Report1报告Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《lyl Lab Report1报告Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。
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)
3.2TunethegainofeachfilterandenjoydifferentsoundeffectwithparametersshowninCht.2.Chooseonesetofparametersanduseffttogetthefrequencyspectrumofboththeoriginalaudioandthetunedsignal.Plottheirspectrumtoseethedifference.Providethecodesintheappendix.
Cht.2Gainoptionsfordifferentstyles
α1
(dB)
α2
α3
α4
α5
Natural
Classic
80
40
Pop
30
10
-20
-40
Bass
-60
-80
Rock
20
3ResultsandDiscussion
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
m
ifkk==m
l=B(kk)*X(ii-kk+1);
l=B(kk)*X(ii-kk+1)-A(m-kk+1)*Y(ii-m+kk);
Y(ii)=Y(ii)+l;
%%outputresults
y=Y;
1.3
Fromthefigure,wecanseetheband-passfiltercandobetterinsignalprocessing,butthesignalwegetintimedomaindoesn’tlookwell.That’sbecausewecan’tfilterthesignalcompletelysothere’salsoalittleinterferenceinthesignal.
Fig.4FilteringaSignalswithEllipticFilter
abIII1_3.m
ord=6;
fs=10000;
wl=fl/(fs/2);
wh=fh/(fs/2);
[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:
%%showresults
subplot(3,2,1);
plot(t,x,'
%xintimedomain
title('
x(t)'
subplot(3,2,2);
plot(F_X,X,'
%xinfrequencydomain
xlim([0,2000]);
X(j\omega)'
subplot(3,2,3);
plot(t_imp,h_imp,'
%hintimedomain
h(n)'
subplot(3,2,4);
plot(fz,abs(Hz),'
%hinfrequencydomain
xlim([0,1000]);
H(\omega)'
subplot(3,2,5);
plot(t,h,'
%yintimedomain
y(t)'
Time(s)'
subplot(3,2,6);
plot(F_H,H,'
%yinfrequencydomain
Y(j\omega)'
Frequency(Hz)'
%%end
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
%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);
forii=k+1:
length(x_cut)
y(ii)=a*y(ii-k)+x_cut(ii);
sound(y);
3.2
Fig.11DifferentFilterandSignalsthroughEachFilter
Fig.12OriginalAudio(up)andTunedClassicSignal(down)
Fig.11showsthefiltersandsignalsthrougheachfilter,Fig.12showstheoriginalaudio(up)andthetunedClassicsignal(down).
myEQ.m
%%
[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