




已阅读5页,还剩33页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Matlab Worksheet 2Part A (In-class room exercises)1. Using plot to display the following voltage with appropriate line type, title and labels. Also present the graph with suitable ranges of axis.where f=50 Hz.(Hint: time interval must be small enough, e.g. 0.001 seconds. Therefore, t=0:0.001:1 is appropriate);Answer:Home_work_2_A_1.m%lbs in-class-exercise1_1 2013/8/21%function Using plot to display the following voltage with appropriate line type, title and labels. Also present the graph with suitable ranges of axis. % v(t)=220sin(2?ft)% where f=50 Hz.%Comment/loop clear all; close all;t=0:0.001:1;v=220*sin(2*pi*50*t);plot(t,v,m,LineWidth,2)xlabel(t(sec)ylabel(v(voltage)title(v(t)=220sin(2?ft)axis(0 0.2 -260 260);grid on; 2. Using plot to display the following voltage with appropriate line type, title and labels. Also present the graph with suitable ranges of axis.where f=50 Hz.In addition, on the same graph, draw the envelope of the oscillation and add legends. Answer:home_work_2_A_2.m%lbs in-class-exercise1_2 2013/8/21%function Using plot to display the following voltage with appropriate line type, title and labels. Also present the graph with suitable ranges of axis.% v(t)=220exp(-5t)cos(2?ft)% where f=50 Hz.% In addition, on the same graph, draw the envelope of the oscillation and add legends. %Comment/loop clear all; close all;t=0:0.001:1;v=220*exp(-5*t).*sin(2*pi*50*t); plot(t,v,m,LineWidth,2);xlabel(t(sec)ylabel(v(voltage)title(v(t)=220exp(-5t)cos(2?ft)hold on;v1=220*exp(-5*t);plot(t,v1,b,LineWidth,2);hold on;plot(t,-v1,b,LineWidth,2);hold off;legend(the oscillation, the envelope of the oscillation);axis(0 1 -220 220);grid on; 3. Use subplot, draw a 2 by 2 array of plots for the following functions:Apply appropriate line type, title, labels and axis ranges for the graphs.Answer:home_work_2_A_3.m%lbs in-class-exercise1_3 2013/8/21%function Use subplot, draw a 2 by 2 array of plots for the following functions:% v1=cos(10*pi*t);v2=exp(-5*t).*v1;v3=exp(-10*t).*v1;v4=exp(-20*t).*cos(10*pi*t)% Apply appropriate line type, title, labels and axis ranges for the graphs.%Comment/loop t=0:0.001:1; v1=cos(10*pi*t); v2=exp(-5*t).*v1; v3=exp(-10*t).*v1; v4=exp(-20*t).*cos(10*pi*t);subplot(2,2,1)plot(t,v1,k,LineWidth,2)xlabel(t(sec)ylabel(v(voltage)title(v(t)=cos(10?t);axis(0 1 -1 1) subplot(2,2,2)plot(t,v2,r,LineWidth,2)xlabel(t(sec)ylabel(v(voltage)title(v(t)=exp(-5t)cos(10?t);axis(0 1 -1 1) subplot(2,2,3)plot(t,v3,g,LineWidth,2)xlabel(t(sec)ylabel(v(voltage)title(v(t)=exp(-10t)cos(10?t);axis(0 1 -1 1) subplot(2,2,4)plot(t,v4,m,LineWidth,2)xlabel(t(sec)ylabel(v(voltage)title(v(t)=exp(-20t)cos(10?t);axis(0 1 -1 1) 4. Use plot3 to plot 2 spiral curves like below with appropriate line width and colour.Answer:(1) home_work_2_A_4_1.mt=0:0.01:10;x=sin(2*pi*t).*exp(0.35*t-1);y=cos(2*pi*t).*exp(0.35*t-1);z=0.25*t;plot3(x,y,z,g,LineWidth,2);axis(-15 15 -15 15 0 3);grid on;(2)home_work_2_A_4_2.mt=0:0.01:10;x=1.5*t.*sin(2*pi*t);y=1.5*t.*cos(2*pi*t);z=0.2*t;plot3(x,y,z,r,LineWidth,3);axis(-15 15 -15 15 0 2);grid on;5. Display the surface using mesh and contour with a suitable resolution:Answer:home_work_2_A_5.mx,y = meshgrid(0:1:100, 0:1:100);z=exp(-0.005.*(x-50).2+(y-50).2);figure(1);mesh(x,y,z),xlabel(x), ylabel(y), grid on;figure(2);contour(x,y,z),xlabel(x), ylabel(y), grid on; 6. Load 2 of your photos into Matlab WorkSpace using imread. a) Change brightness locally or globally. b) Overlap them to produce a new photo. c) write a new photo into a file using imwrite. (Note: lower version of Matlab such as 6.5 is not allowed to do some direct image operations.) Answer:a) home_work_2_A_6_a.mclear all;close all;A=imread(lbs.jpg);figure(1); subplot(2, 2, 1);imshow(A),title(初始图像);size(A); subplot(2,2,2);B=histeq(A(:,:,1); % Enhance contrast using histogram equalization.imshow(B),title(对比度增大处理); subplot(2,2,3);C=imadjust(A,0.3,0.7,);imshow(C),title(亮度调节处理); subplot(2,2,4);D=imfilter(A,2);imshow(D),title(真彩色增强处理);b) home_work_2_A_6_b.mA=imread(lbs.jpg);B=imread(man.jpg);M,N,L=size(A);C(1:M,1:N,1:L)=B(1:M,1:N,1:L);figure(1);imshow(A);title(figure1);figure(2);imshow(C);title(figure2);figure(3);imshow(A+C);title(figure3);c) home_work_2_A_6_c.mA=imread(lbs.jpg);B=imadjust(A,0.2,0.6,);imwrite(B,lbs1.jpg);imshow(lbs1.jpg);7. For linear simultaneous equationsthe equation coefficients:A= 1 -1 4 3 -5 4 5 -6 0 7 -8 9 -1 3 -2 6; (M=N)a) Find the determinant of A,b) Find the inverse of A and check for matrix singularity,c) If B= 5; 1; -2; 3, find the unknown x in the equation. Answer:home_work_2_A_7.m A= 1 -1 4 3; -5 4 5 -6; 0 7 -8 9; -1 3 -2 6;disp(a) determinant of A);det(A)disp(b) the inverse of A and check for matrix singularity);inv(A)cond(A)B= 5; 1; -2; 3disp(c) the solution of the equation);x=inv(A)*Bresult: home_work_2_A_7a) determinant of Aans = -765.0000b) the inverse of Aand check for matrix singularityans = 0.3333 -0.0000 0.3333 -0.6667 0.2000 0.1176 0.2706 -0.3882 0.2000 0.0588 0.0353 -0.0941 0.0222 -0.0392 -0.0680 0.2183ans = 16.4186B = 5 1 -2 3c) the solution of the equationx = -1.0000 -0.5882 0.7059 0.86278. For linear simultaneous equations,MN, the equation coefficients:A= 1 -1 4 3 -5 4 5 -6 0 7 -8 9 -1 3 -2 6 1 -2 5 30 4 7 -3; a) Find the determinant of A*A,b) Find the inverse of A*A and check for matrix singularity,c) If B= 5; 1; -2; 3; 4; 0, find the solution of the equation.Answer:home_work_2_A_8.m A= 1 -1 4 3; -5 4 5 -6; 0 7 -8 9; -1 3 -2 6; 1 -2 5 3; 0 4 7 -3; disp(a) determinant of A*A);det(A*A)disp(b) the inverse of A*A and check for matrix singularity);inv(A*A)cond(A*A)B= 5; 1; -2; 3; 4; 0;disp(c) the solution of the equation);x=inv(A*A)*A*Bresult: home_work_2_A_8a) determinant of A*Aans = 2.1051e+07b) the inverse of A*A and check for matrix singularityans = 0.0884 0.0321 -0.0013 -0.0219 0.0321 0.0231 0.0002 -0.0099 -0.0013 0.0002 0.0085 0.0053 -0.0219 -0.0099 0.0053 0.0144ans = 32.5278c) the solution of the equationx = -0.8903 -0.4898 0.5755 0.70839. Data of 10 records are shown belowy=3.5 4.3 3.7 5.4 6.6 7.3 8.7 8.8 9.4 9.0 10.0 12.0 11.3 9.9 13.3,Use polyfit with different orders (from 1 to 3) of polynomials to find a curve of best fit. Check the total distance between the fitted curve z and records defined by.Answer:home_work_2_A_9.mclear all;close all;x=1:1:15;y=3.5 4.3 3.7 5.4 6.6 7.3 8.7 8.8 9.4 9.0 10.0 12.0 11.3 9.9 13.3;plot(x,y,ro); hold on; p=polyfit(x,y,1);z=polyval(p,x);plot(x,z,bx);hold on;disp(一阶拟合误差);s1=sqrt(sum(z-y).2) p=polyfit(x,y,2);z=polyval(p,x);plot(x,z,kx,Linewidth,1.5);hold on;disp(二阶拟合误差);s2=sqrt(sum(z-y).2) p=polyfit(x,y,3);z=polyval(p,x);plot(x,z,r-,linewidth,2);hold off;grid on;legend(point,polyfit 1,polyfit 2,polyfit 3);disp(三阶拟合误差);s3=sqrt(sum(z-y).2)result: home_work_2_A_9一阶拟合误差s1 = 3.2807二阶拟合误差s2 = 3.0399三阶拟合误差s3 = 3.039810. Create a set of 20 points from a curve by Matlab code:x=1:20;y=2*exp(-0.3*(x-5).2)+0.7*exp(-0.2*(x-12).2);Then interpolate the curve to 60 points using linear and spline options, respectively. See the quality of different types of interpolation.Answer:home_work_2_A_10.mclear all,close all;x=1:20;y=2*exp(-0.3*(x-5).2)+0.7*exp(-0.2*(x-12).2);plot(x,y,ro,LineWidth,2);hold on;xi=1:1/3:20;yi = interp1(x,y,xi,linear);plot(xi,yi,b*);hold on;yi = interp1(x,y,xi,spline);plot(xi,yi,m-);legend(point,linear,spline)hold off;Part B1. Using the plot and subplot functions create 4 plots on a 2 by 2 array of subplots, for the function exp(-t)sin(5t) showing in each plot the function in the corresponding intervals of t i.e. (-2, -1), (-1,0), (0,1) and (1,2). Answer:home_work_2_B_1.mt=-2:0.01:-1;v=exp(-t).*sin(5*t);subplot(2,2,1);plot(t,v,m,LineWidth,2); t=-1:0.01:0;subplot(2,2,2);plot(t,v,b,LineWidth,2); t=0:0.01:1;subplot(2,2,3);plot(t,v,r,LineWidth,2); t=1:0.01:2;subplot(2,2,4);plot(t,v,k,LineWidth,2);2. A three phase induction motor characteristic is given in terms of mechanical shaft output torque (NM Newton-meter) as a function of rotational speed (rad/s radian per second). This is approximated by 3 piece-wise linear equations as follows:This motor is directly coupled to a load , which can be represented as Write 2 separate Matlab function m-files in which: a) the motor characteristic, b) the load characteristic are defined only as functions of . Name them motor.m and sysload.m, respectively.Answer:a) motor.mfunction Tm = motor( w )for i=1:length(w);if w(i)=0 & w(i)=90*pi & w(i)=110*pi & w(i) motor(0)ans = 4 w=0:12*pi; motor(w)ans = Columns 1 through 10 4.0000 4.0035 4.0071 4.0106 4.0141 4.0177 4.0212 4.0248 4.0283 4.0318 Columns 11 through 20 4.0354 4.0389 4.0424 4.0460 4.0495 4.0531 4.0566 4.0601 4.0637 4.0672 Columns 21 through 30 4.0707 4.0743 4.0778 4.0813 4.0849 4.0884 4.0920 4.0955 4.0990 4.1026 Columns 31 through 38 4.1061 4.1096 4.1132 4.1167 4.1203 4.1238 4.1273 4.1309b) sysload.mfunction Tl = sysload( w )Tl=-50*(w/(120*pi).3+100*(w/(120*pi).2+4*w./(120*pi);endresult: sysload(0)ans = 0 w=0:12*pi; sysload(w)ans = Columns 1 through 10 0 0.0113 0.0240 0.0381 0.0536 0.0705 0.0888 0.1084 0.1294 0.1518 Columns 11 through 20 0.1755 0.2006 0.2270 0.2548 0.2839 0.3143 0.3461 0.3791 0.4135 0.4492 Columns 21 through 30 0.4862 0.5245 0.5640 0.6049 0.6470 0.6904 0.7351 0.7810 0.8282 0.8767 Columns 31 through 38 0.9264 0.9773 1.0295 1.0828 1.1375 1.1933 1.2503 1.30863. Write a Matlab scripgt-m file which calls your function m-files from Question 2. And plot the motor and load characterstics on the same figure, giving suitable labelling and title. Name this script m-file systemplot.mAnswer:home _work_2_B_3.mw=0:pi/20:120*pi;Tm=motor(w);plot(w,Tm,m,LineWidth,2);hold on;Tl=sysload(w);plot(w,Tl,r,LineWidth,2);hold off;xlabel(speed w(rad/s_);ylabel(torque(NM Newton-meter);title(the motor and load characterstics);legend(motor line,sysload line)4. Write a sript m-file which finds all the mathematicall possible points (values of ) where5. for the range 0 120 (rad/s) with the characteristic given in Question 2. The system could theoretically operate at a speed where Mathematically, this involves finding the roots of the equationGive a name to this m-file posspoints.m . Call posspoints.m in systemplot.m and show all of the points on a system plot using the o symbol.Answer:(1)subfun.mfunction sub = subfun( w )for i=1:length(w);if w(i)=0 & w(i)=90*pi & w(i)=110*pi & w(i) posspoints xx = 74.0177 307.6718 360.7836(3)systemplot.mw=0:pi/20:120*pi;Tm=motor(w);plot(w,Tm,m,LineWidth,2);hold on;Tl=sysload(w);plot(w,Tl,r,LineWidth,2);hold on;xlabel(speed w(rad/s_);ylabel(torque(NM Newton-meter);title(the motor and load characterstics);legend(motor line,sysload line)posspoints;Tl=-50*(x/(120*pi).3+100*(x/(120*pi).2+4*x/(120*pi)plot(x,Tl,ko,LineWidth,2);hold off;grid on; posspoints xx = 74.0177 307.6718 360.7836Part CIntroduction to DSP1. Basic digital signalsUnit impulse functionExercise 1-1: Display the unit impulse function with Matlab code. The code can be either typed under Matlab prompt or written into a script Matlab file, then run the file.n=-10:10;for k=1:21 x(k)=0;end;x(11)=1;stem(n, x);axis(-10 10 0 2);Problem 1-1: For the signal, write the Matlab code and copy the result figure into the following boxes.n=-10:10;for k=1:21 x(k)=0;end;x(9)=2;stem(n, x);axis(-10 10 0 2); Unit step functionExercise 1-2: Display the unit step function with Matlab code: n=-10:10;for k=1:10 x(k)=0;end; for k=11:21 x(k)=1;end;stem(n, x);axis(-10 10 0 2);Problem 1-2: For the signal , write the Matlab code, and display the corresponding signal into the following boxes.n=-10:10;for k=1:12 x(k)=0;end; for k=13:21 x(k)=-1;end;stem(n, x); axis(-10 10 -2 1); Sine wave where w - frequency (rad/second), T - sampling interval (seconds)Exercise 1-3: Let T=0.02, w =6.28. Using the following code, plot on the screen in the region 0 n 100.n=0:100;T=0.02;omega=6.28;for k=1:101 x(k)=sin(k-1)*omega*T);end;stem(n, x);Problem 1-3: Modify the above code to display the signal: , where T=0.02, w=6.28. Execute the code and plot the signal on the screen. Copy the code, then display the signal into the following boxes.n=0:100;T=0.02;omega=6.28; for k=1:101 x(k)=2*sin(k-1)*omega*T+pi/2);end;stem(n, x);Time shift, impulse and step responses Exercise 1-4For the unit impulse, and the unit stepwrite two Matlab functions and save as impseq.m and stepseq.m files, respectively.% impseq.m %Unit Impulse %n1:n2 simple number range%n0 - time shiftfunction x, n=impseq(n0,n1,n2)n=n1:n2;x=(n-n0)=0;%end;% stepseq.m % Unit Step%n1:n2 simple number range%n0 - time shiftfunction x, n= stepseq(n0, n1, n2)n=n1:n2;x=(n-n0)=0;%endGiven the following difference equation:a) Calculate and plot the impulse response at n=-20,120; andb) Calculate and plot the step response at n=-20,120, using the following codeb=1; a=1,-0.7, 0.9;x=impseq(0,-20, 120); n=-20:120;h=filter(b,a,x);subplot(2,1,1);stem(n,h);title(Impulse response);xlabel(n);ylabel(h(n); x=stepseq(0,-20, 120); n=-20:120;h=filter(b,a,x);subplot(2,1,2);stem(n,h);title(Step response);xlabel(n);ylabel(s(n);Problem 1-4 Solve the above a) and b) for the system:Display the responses in the boxes.b=1,2; a=1,-1.8 , 0.94;x=impseq(0,-20, 120); n=-20:120;h=filter(b,a,x);subplot(2,1,1);stem(n,h);title(Impulse response);xlabel(n);ylabel(h(n); x=stepseq(0,-20, 120); n=-20:120;h=filter(b,a,x);subplot(2,1,2);stem(n,h);title(Step response);xlabel(n);ylabel(s(n);2. ConvolutionIn the liner time-invariant (LTI) system, the response of the system can be calculated by a convolution between the input and its unit impulse response.Exercise 2-1 Write an Matlab function and save as conv_m.m. %convolution function %conv_m.mfunction y, ny=conv_m(x,nx,h,nh)nyb=nx(1)+nh(1);nye=nx(length(x)+nh(length(h);ny=nyb:nye;y=conv(x,h);%end;Compute the convolution for xn and hn using the following codes:x=3, 11, 7, 0, -1, 4, 2;nx=-3:3;h=2, 3, 0, -5, 2, 1;nh=-1:4;y, ny=conv_m(x,nx,h,nh);Subplot(3,1,1);stem(nx,x);ylabel(xn);axis(-6 10 -20 20);Subplot(3,1,2); stem(nh,h);ylabel(hn);axis(-6 10 -20 20);subplot(3,1,3);stem(ny,y);xlabel(n);ylabel(yn);axis(-6 1
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 城管招聘面试题及答案
- 汽车肇事测试题及答案
- ARDS考试题及答案
- 湖北省荆州市沙市区沙市中学2026届化学高三第一学期期末达标测试试题含解析
- 经验法则面试题及答案
- 好评制度面试题及答案
- 磨工技师试题及答案
- 任现职期间工作总结
- 认知障碍老人护理全解析
- 家电公司客户分类管理规章
- 风电场危险源辨识、风险评价和风险控制清单
- 儿童血压测量课件
- 医疗AI算法揭秘如何构建高效的疾病预测模型
- 电商外包客服合同协议
- 糖尿病性黄斑水肿护理查房
- 《铁路建设项目安全穿透式管理实施指南》知识培训
- 企业研究院管理制度
- 工业管道安全评估方法-全面剖析
- 施工现场排水方案
- 居家养老护理员技能培训计划
- 《国内外绩效考核指标体系研究现状文献综述》4200字
评论
0/150
提交评论