信号处理仿真MATLAB实验.docx
《信号处理仿真MATLAB实验.docx》由会员分享,可在线阅读,更多相关《信号处理仿真MATLAB实验.docx(18页珍藏版)》请在冰豆网上搜索。
信号处理仿真MATLAB实验
信号处理仿真(MATLAB)
实验指导书
青岛大学自动化工程学院电子工程系
2006年4月
MATLAB实验一
一、实验目的:
1.BefamiliarwithMATLABEnvironment
2.Befamiliarwitharrayandmatrix
3.BefamiliarwithMATLABoperationsandsimpleplotfunction
二、实验内容:
1.BefamiliarwithMatlab6.5
StartupMatlab6.5,browsethemajortoolsoftheMatlabdesktop
⏹TheCommandWindows
⏹TheCommandHistoryWindows
⏹LaunchPad
⏹TheEdit/DebugWindow
⏹FigureWindows
⏹WorkspaceBrowserandArrayEditer
⏹HelpBrowser
⏹CurrentDirectoryBrowser
PARTI:
下列选择练习,不需提交实验报告
1.Givetheanswerofthefollowingquestionsforthearray
1)Whatisthesizeofarray1?
ans=
45
2)Whatisthevalueofarray1(4,1)?
ans=
1.4000
3)Whatisthesizeandvalueofarray1(:
1:
2)?
ans=
1.10000
01.1000
2.10000.1000
1.40005.1000
4)Whatisthesizeandvalueofarray1([13], end)?
ans=
6.0000
1.3000
2.Givetheanswerofthefollowingcommad
1)a=1:
2:
5;a=
135
2)b=[a’a’a’];b=
111
333
555
3)c=b(1:
2:
3,1:
2:
3);c=
11
55
4)d=a+b(2,:
)d=
468
5)w=[zeros(1,3) ones(3,1)’ 3:
5’]w=
000111345
3.Givetheanswerofthesub-arrays
1)array1(3,:
);ans=
2.10000.10000.30000.40001.3000
2)array1(:
3);ans=
2.1000
6.6000
0.3000
0
3)array1(1:
2:
3,[334])ans=
2.10002.10003.5000
0.30000.30000.4000
4)array1([11],:
)ans=
1.100002.10003.50006.0000
1.100002.10003.50006.0000
4.Givetheanswerofthefollowingoperations
1)a+bans=
33
14
2)a*dans=
22
12
3)a.*dans=
20
02
4)a*cans=
6
5
5)a.*cerror
6)a\bans=
1.0000-1.0000
-0.50001.5000
7)a.\bans=
0.50000.5000
01.0000
8)a.^bans=
22
14
PARTI:
下列选择练习,不需提交实验报告
1.Edit&Runthem-file
%teststepresponsefunction
wn=6;kosi=[0.1:
0.1:
1.02];
figure
(1);holdon
forkos=kosi
num=wn^2;den=[1,2*kos*wn,wn.^2];step(num,den)
end
holdoff;
2.Edit&Runthem-file
%testplotfunction
x=0:
pi/20:
3*pi;y1=sin(x);y2=2*cos(2*x);plot(x,y1,'rv:
',x,y2,'bo--');
title('PlottheLineofy=sin(2x)anditsderivative');xlabel('Xaxis');ylabel('Yaxis');
legend('f(x)','d/dxf(x)');gridon;
3.Edit&Runthem-file
%testsubplotandloglogfunction
x=0:
0.1:
10;y=x.^2-10.*x+26;
subplot(2,2,1);plot(x,y);gridon;
subplot(2,2,2);semilogx(x,y);gridon;
subplot(2,2,3);semilogy(x,y);gridon;
subplot(2,2,4);loglog(x,y);gridon;
4.Edit&Runthem-file
%testmaxandplotfunction
volts=120;rs=50;rl=1:
0.1:
100;
amps=volts./(rs+rl);pl=(amps.^2).*rl;[maxvol,index]=max(pl);
plot(rl,pl,rl(index),pl(index),'rh');gridon;
MATLAB实验二
一、实验目的:
1.Learntodesignbranchstatementsprogram
2.Befamiliarwithrelationalandlogicaloperators
3.Practice2Dplotting
二、实验内容:
PARTI:
(选择练习,不需提交实验报告)
1.Holdcommandexercise
x=-pi:
pi/20:
pi;
y1=sin(x);y2=cos(x);plot(x,y1,'b-');holdon;
plot(x,y2,'k--');holdoff;
legend('sinx','cosx')
2.Figurecommandexercise
figure
(1);
subplot(2,1,1);
x=-pi:
pi/20:
pi;y=sin(x);plot(x,y);gridon;
title('Subplot1Title');
subplot(2,1,2);
x=-pi:
pi/20:
pi;y=cos(x);plot(x,y);gridon;
title('Subplot2Title');
3.PolarPlotsexercise
g=0.5;
theta=0:
pi/20:
2*pi;
gain=2*g*(1+cos(theta));
polar(theta,gain,'r-');
title('\fontsize{20}\bfGainversusangle\theta');
4.Assumethata,b,c,anddaredefined,andevaluatethefollowingexpression.
a=20;b=-2;c=0;d=1;
(1)a>b;ans=1
(2)b>d;ans=0(3)a>b&c>d;ans=0(4)a==b;ans=0(5)a&b>c;ans=06)~~b;ans=1
a=2;b=[1–2;-010];c=[01;20];d=[-212;010];
(7)~(a>b)ans=
00
01
(8)a>c&b>cans=
10
01
(9)c<=derror
a=2;b=3;c=10;d=0;
(10)a*b^2>a*cans=0(11)d|b>aans=1(12)(d|b)>aans=0
a=20;b=-2;c=0;d=’Test’;
(13)isinf(a/b)ans=0(14)isinf(a/c)Warning:
Dividebyzero.
(Type"warningoffMATLAB:
divideByZero"tosuppressthiswarning.)
ans=
1
(15)a>b&ischar(d)ans=1(16)isempty(c)ans=0
5.WriteaMatlabprogramtosolvethefunction
wherexisanumber<1.Useanifstructuretoverifythatthevaluepassedtotheprogramislegal.Ifthevalueofxislegal,caculatey(x).Ifnot,writeasuitableerrormessageandquit.
x=input('Enterthevalueofx:
')
ifx<1
f=ln(1/(1-x))
disp(['thevalueoffis'num2str(f)])
else
disp('error')
end
PARTII:
(需提交实验报告)
1.
3.Writeoutm.fileandplotthefigureswithgrids
Assumethatthecomplexfunctionf(t)isdefinedbytheequation
f(t)=(0.5-0.25i)t-1.0
Plottheamplitudeandphaseoffunctionfor
4.WritetheMatlabstatementsrequiredtocalculatey(t)fromtheequation
forvalueoftbetween–9and9instepsof0.5.Useloopsandbranchestoperformthiscalculation.
MATLAB实验三
一、实验目的:
1.Learntodesignloopstatementsprogram
2.Befamiliarwithrelationalandlogicaloperators
3.Practice2Dplotting
二、实验内容:
PARTI:
(选择练习,不需提交实验报告)
4.Comparethe3approachesfollows(LoopsandVectorization)
%A.PerformcalculationbyForLoopwithpre-initializearray
tic;
square=zeros(1,10000)%pre-initializearray
forii=1:
10000
square(ii)=ii^2;
square_root(ii)=ii^(1/2);
cube_root(ii)=ii^(1/3);
end
toc;t1=toc
%B.PerformcalculationbyForLoopwithoutpre-initializearray
tic;
forii=1:
10000
square(ii)=ii^2;
square_root(ii)=ii^(1/2);
cube_root(ii)=ii^(1/3);
end
toc;t2=toc
%C.Performcalculationwithvectors
tic;
ii=1:
10000
square(ii)=ii.^2;
square_root(ii)=ii.^(1/2);
cube_root(ii)=ii.^(1/3);
end
toc;t3=toc
MATLAB实验四
一、实验目的:
1.LearntowriteMATLABfunctions
2.Befamiliarwithcomplexdataandcharacterdata
3.Practice2Dplotting
二、实验内容:
1.WritethreeMatlabfunctionstocalculatethehyperbolicsine,cosine,and
tangentfunctions:
thenplottheshapesofhyperbolicsine,cosine,andtangentfunctionsononefigure,
.
2.Writeaprogramusethefunction
andplottheline,
andsearchfortheminimumandmaximumin200stepsovertherangeof
marktheminimumandmaximumonthelinefigure.
3.Writeafunctiontocalculatethedistancebetweentwopoints
and
thatthepointsshouldbegivenby‘input’function.
4.Writeafunctioncomplex_tothatacceptacomplexnumbervar,andreturnstwooutputargumentscontainingthemagnitudemagandanglethetaofthecomplexnumber.Theoutputangleshouldbeindegrees.
Writeanotherfunctionpolar_to_complexthatacceptstwoinputargumentscontainingthemagnitudemagandanglethetaofthecomplexnumberindegrees,andreturnsthecomplexnumbervar.
4.Writeaprogramthatacceptsaseriesofstringsfromauserwiththeinputfunction,sortsthestringsintoascendingorder,andprintsthemout.
MATLAB实验五
一、实验目的:
1.LearntowriteMATLABfunctions
2.Befamiliarwithcomplexdataandcharacterdata
5.Practice2Dplotting
二、实验内容:
1.WritethreeMatlabfunctionstocalculatethehyperbolicsine,cosine,and
tangentfunctions:
thenplottheshapesofhyperbolicsine,cosine,andtangentfunctionsononefigure,
.
2.Writeaprogramusethefunction
andplottheline,
andsearchfortheminimumandmaximumin200stepsovertherangeof
marktheminimumandmaximumonthelinefigure.
3.Writeafunctiontocalculatethedistancebetweentwopoints
and
thatthepointsshouldbegivenby‘input’function.
4.Writeafunctioncomplex_tothatacceptacomplexnumbervar,andreturnstwooutputargumentscontainingthemagnitudemagandanglethetaofthecomplexnumber.Theoutputangleshouldbeindegrees.
Writeanotherfunctionpolar_to_complexthatacceptstwoinputargumentscontainingthemagnitudemagandanglethetaofthecomplexnumberindegrees,andreturnsthecomplexnumbervar.
5.Writeaprogramthatacceptsaseriesofstringsfromauserwiththeinputfunction,sortsthestringsintoascendingorder,andprintsthemout.
MATLAB实验六
一、实验目的:
1.Practice2Dplottingand3Dplotting
2.Learntousefplotfunction
3.Befamiliarwithcellarraysandstructurearrays
二、实验内容:
1.Givethe3Dplotfigureof
useplot3function,
andgridon,linewidthis3.0.
2.Plotthefunction
step0.1.Createthefollowingplottypes:
(a)stemplot;(b)stairplot;(c)barplot;(d)compassplot.
3.Plotthefunction
overtherange
usingfunctionfplot,andgridon.
4.Createacellarrays:
5.Createastructurearraysandtocalculatethemeanbillingofthreepatients:
MATLAB实验七
一、实验目的:
BefamiliarwithInput/Outputfunctions
二、实验内容:
1.Writeam-file.Them-filecreatesanarraycontaining
randomvalues,sortsthearrayintoascendingorder,opensauser-specifiedfileforwritingonly,thenwritesthearraytodiskin32-bitfloating-pointformat,andclosethefile.Itthenopensthefileandreadthedatabackinto
array.
2.Editafileasdata4_4.txtthatcontains
squarematrix,thenimportthearrayuseuiimportfunction,andcalculatetheinverseofthesquarematrix.
3.Writeaprogramtoreadasetofintegersfromaninputdatafile,andlocatethelargestandsmallestvalueswithinthedatafile.Printoutthelargestandsmallestvalues,togetherwiththelinesonwhichtheywerefoundinonefigure.
MATLAB实验八
一、实验目的:
1.Befamiliarwithhandlegraphics
2.LearnaboutGUI
3.LearntodesignPIDcontrolsystemwithSimulink
二、实验内容:
1.SecondOrderSystemGUIDesign
%SOSystem_GUI.m
set(gcf,'defaultuicontrolunits','normalized');
set(gcf,'defaultuicontrolfontsize',12);
str='SecondOrderSystemStepresponse';set(gcf,'name',str);
h_axes=axes('position',[0.05,0.2,0.6,0.7]);set(h_axes,'xlim',[0,15]);
str1='ZETA=';
t=0:
0.1:
10;z=0.5;y=step(1,[12*z1],t);
hline=plot(t,y);gridon;
htext=uicontrol(gcf,'style','text','position',[0.67,0.8,0.33,0.1],'string',[str1,sprintf('%1.4g\',z)]);
hslide