信号处理仿真(MATLAB)实验指导书青岛大学自动化工程学院2006年4月MATLAB实验一一、实验目的:1. Be familiar with MATLAB Environment2. Be familiar with array and matrix3. Be familiar with MATLAB operations and simple plot function二、实验内容:1. Be familiar with Matlab 6.5Startup Matlab 6.5, browse the major tools of the Matlab desktop The Command WindowsThe Command History WindowsLaunch PadThe Edit/Debug WindowFigure WindowsWorkspace Browser and Array EditerHelp BrowserCurrent Directory Browser2. Give the answer of the following questions for the array 1)What is the size of array1?2)What is the value of array1(4,1)?3)What is the size and value of array1(:,1:2)?4)What is the size and value of array1([1 3], end)?3. Give the answer of the following commad1) a=1:2:5; 2) b=[a’ a’ a’]; 3) c=b(1:2:3,1:2:3);4) d=a+b(2,:) 5) w=[zeros(1,3) ones(3,1)’ 3:5’]4. Give the answer of the sub-arrays1) array1(3,:); 2) array1(:,3); 3) array1(1:2:3,[3 3 4]) 4) array1([1 1],:)5. Give the answer of the following operations1) a+b 2) a*d 3) a.*d 4) a*c5) a.*c 6)a\b 7) a.\b 8)a.^b6.Solve the following system of simultaneous equations for x 7.Edit & Run the m-file% test step response functionwn=6; kosi=[0.1:0.1:1.0 2];figure(1); hold onfor kos=kosinum=wn^2; den=[1,2*kos*wn,wn.^2]; step(num,den)endhold off;8.Edit & Run the m-file% test plot functionx=0:pi/20:3*pi; y1=sin(x); y2=2*cos(2*x); plot(x,y1,'rv:',x,y2,'bo--');title('Plot the Line of y=sin(2x) and its derivative'); xlabel('X axis'); ylabel('Y axis');legend('f(x)','d/dx f(x)'); grid on;9. Edit & Run the m-file% test subplot and loglog functionx=0:0.1:10; y=x.^2-10.*x+26;subplot(2,2,1); plot(x,y); grid on;subplot(2,2,2); semilogx(x,y); grid on;subplot(2,2,3); semilogy(x,y); grid on;subplot(2,2,4); loglog(x,y); grid on;10.Edit & Run the m-file% test max and plot functionvolts=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'); grid on;MATLAB实验二一、实验目的:1. Learn to design branch and loop statements program2. Be familiar with relational and logical operators3. Practice 2D plotting二、实验内容:PART I: (选择练习,不需提交实验报告)1. Hold command exercisen x=-pi:pi/20:pi;n y1=sin(x); y2=cos(x); plot(x,y1, 'b-'); hold on;n plot(x,y2, 'k--'); hold off;n legend ('sinx', 'cosx')2. Figure command exercisefigure(1);subplot(2,1,1);x=-pi:pi/20:pi; y=sin(x); plot(x,y); grid on;title('Subplot 1 Title');subplot(2,1,2);x=-pi:pi/20:pi; y=cos(x); plot(x,y); grid on;title('Subplot 2 Title');3. Polar Plots exerciseg=0.5;theta=0:pi/20:2*pi;gain=2*g*(1+cos(theta));polar(theta,gain,'r-');title('\fontsize{20} \bfGain versus angle \theta');4. Compare the 3 approaches follows (Loops and Vectorization)%A. Perform calculation by For Loop with pre-initialize arraytic;n square=zeros(1,10000) %pre-initialize arrayn for ii=1:10000n square(ii)=ii^2;n square_root(ii)=ii^(1/2);n cube_root(ii)=ii^(1/3);n endn toc; t1=toc%B. Perform calculation by For Loop without pre-initialize arrayn tic;n for ii=1:10000n square(ii)=ii^2;n square_root(ii)=ii^(1/2);n cube_root(ii)=ii^(1/3);n endn toc; t2=toc%C. Perform calculation with vectorsn tic;ii=1:10000n square(ii)=ii.^2;square_root(ii)=ii.^(1/2);cube_root(ii)=ii.^(1/3);n endn toc; n t3=tocPART II: (需提交实验报告)1. Assume that a,b,c, and d are defined, and evaluate the following expression.a=20; b=-2; c=0; d=1;(1) a>b; (2) b>d; (3) a>b&c>d; (4) a==b; (5) a&b>c; 6) ~~b;a=2; b=[1 –2;-0 10]; c=[0 1;2 0]; d=[-2 1 2;0 1 0];(7) ~(a>b) (8) a>c&b>c (9) c<=da=2; b=3; c=10; d=0;(10) a*b^2>a*c (11) d|b>a (12) (d|b)>aa=20; b=-2; c=0; d=’Test’;(13) isinf(a/b) (14) isinf(a/c) (15) a>b&ischar(d) (16) isempty(c)2. Write a Matlab program to solve the function, where x is a number <1. Usean if structure to verify that the value passed to the program is legal. If the value of x is legal, caculate y(x). If not ,write a suitable error message and quit.3. Write out m. file and plot the figures with gridsAssume that the complex function f(t) is defined by the equationf(t)=(0.5-0.25i)t-1.0Plot the amplitude and phase of function for4. Write the Matlab statements required to calculate y(t) from the equationfor value of t between –9 and 9 in steps of 0.5. Use loops and branches to perform this calculation.5. Write an m.file to evalue the equation for all values of x between 0.1 and 3,in steps of 0.1. Do this twice, once with a for loop and once with vectors.Plot the resulting function using a 4.0 thick dashed blue line.MATLAB实验三一、实验目的:1. Learn to write MATLAB functions2. Be familiar with complex data and character data3. Practice 2D plotting二、实验内容:1. Write three Matlab functions to calculate the hyperbolic sine, cosine, andtangent functions:then plot the shapes of hyperbolic sine, cosine, and tangent functions on one figure, .2. Write a program use the function and plot the line,and search for the minimum and maximum in 200 steps over the range of , mark the minimum and maximum on the line figure.3. Write a function to calculate the distance between two points and , that the points should begiven by ‘input’ function.4. Write a function complex_to that accept a complex number var, andreturns two output arguments containing the magnitude mag and angle theta of the complex number. The output angle should be in degrees.Write another function polar_to_complex that accepts two input arguments containing the magnitude mag and angle theta of the complex number in degrees, and returns the complex number var.5. Write a program that accepts a series of strings from a user with the inputfunction, sorts the strings into ascending order, and prints them out.MATLAB实验四一、实验目的:1. Practice 2D plotting and 3D plotting2. Learn to use fplot function3. Be familiar with cell arrays and structure arrays二、实验内容:1. Give the 3D plot figure of use plot3 function, , and grid on, linewidth is3.0.2. Plot the function , , step 0.1. Create the following plot types: (a) stem plot;(b) stair plot; (c) bar plot; (d) compass plot.3. Plot the function over the range using function fplot, and grid on.4. Create a cell arrays:5. Create a structure arrays and to calculate the mean billing of threepatients:MATLAB实验五一、实验目的:Be familiar with Input/Output functions二、实验内容:1. Write a m-file. The m-file creates an array containing random values,sorts the array into ascending order, opens a user-specified file for writing only, then writes the array to disk in 32-bit floating-point format , and close the file. It then opens the file and read the data back into array.2. Edit a file as data4_4.txt that contains square matrix, then import thearray use uiimport function, and calculate the inverse of the square matrix .3. Write a program to read a set of integers from an input data file, andlocate the largest and smallest values within the data file. Print out the largest and smallest values, together with the lines on which they were found in one figure.。