Você está na página 1de 9

BO CO LAB 1

Mn: X l tn hiu s
Ging vin: Phm Vn Tun
Sinh vin : Trn Lc

Exercise 1
Scripts Now we are going to edit the dampedCosine.m le to create our own script le. At the top of the le, you will see the following commands diary 'your_name_Lab1.txt' disp('NAME: your name') disp('SECTION:your section') 1. Edit the dampedCosine.m (download from link above) script and enter your name and section where indicated. Save this new version of the script as yourName_dampedCosine.m 2. Edit the script to create a second signal where the cosine with twice the period (which gives half the frequency) of the first.

3. Add to the script the commands to plot these together with the first signal on nsecond on the bottom. In other words, you should have a single gure with two dierent plots, one on top and one on bottom. You will need to use subplot and plot. Save this plot as yourName_dampedCosine.fig. 4. Show the TA your dampedCosine plot. What is the period of the cosine? dampedCosine.m

CODE

cdiary your_nameex1 %INSERT your name and section into these display commands disp('NAME: your_name') disp('SECTION: your_section') datestr(cputime)

%dampedCosine.m produces a plot of a cosine with frequency 1 Hz, with amplitude % scaled by a decaying exponential figure x = -5:0.01:5; y2=exp(-abs(x)).*cos(pi*x); subplot(2,1,1); plot(x,y2); xlabel('time'); ylabel('amplitude'); title('f(x)=exp(-|x|)cos(pi*x)');

subplot(2,1,2); y1=exp(-abs(x)).*sin(0.5*pi*x); plot(x,y1); xlabel('time'); ylabel('amplitude'); title('f(x)=exp(-|x|)cos(0.5*pi*x)');

diary off

Exercise 2
Complex exponentials Download and run compexp.m2 , which includes a 3-D plot of a complex exponential, y (t) , as well as 2-D magnitude/phase and real/imaginary plots. You need 2 2-D plots to have the same information as the 3-D plot. How would you change the script to make the oscillation frequency lower by half? How would you change the script to make the decay faster? Show the TA your plots %compexp.m produces a 3D plot of a decaying complex exponential, % with subplots of magnitude and phase and of real and imaginary % components below it.

t = 0:0.01:5; y=3*exp(-(0.25+j*(2*pi))*t); subplot(3,1,1); plot3(t,real(y),imag(y)); grid xlabel('t'),ylabel('Re(y)'),zlabel('Im(y)'); title('3-D plot of a Complex Exponential'); %produce magnitude and phase plots; t vs |y(t)| and t vs. <y(t). subplot(3,2,3),plot(t,abs(y)),xlabel('t'), ylabel('Magnitude'),title('Magnitude - |y(t)|'); subplot(3,2,4),plot(t,angle(y)),xlabel('t'), ylabel('Angle'),title('Phase - Arg(y(t))'); %produce real and imag plots; t vs |y(t)| and t vs. <y(t). subplot(3,2,5),plot(t,real(y)),xlabel('t'), ylabel('Magnitude'),title('Re(y(t))'); subplot(3,2,6),plot(t,imag(y)),xlabel('t'), ylabel('Angle'),title('Im(y(t))');

function compexp(f,d) %compexp.m produces a 3D plot of a decaying complex exponential, % with subplots of magnitude and phase and of real and imaginary % components below it. figure t = 0:0.01:5; y=3*exp(-(d*0.25+j*(f*2*pi))*t); subplot(3,1,1); plot3(t,real(y),imag(y)); grid xlabel('t'),ylabel('Re(y)'),zlabel('Im(y)'); title('3-D plot of a Complex Exponential');

%produce magnitude and phase plots; t vs |y(t)| and t vs. <y(t). subplot(3,2,3),plot(t,abs(y)),xlabel('t'), ylabel('Magnitude'),title('Magnitude - |y(t)|'); subplot(3,2,4),plot(t,angle(y)),xlabel('t'), ylabel('Angle'),title('Phase - Arg(y(t))'); %produce real and imag plots; t vs |y(t)| and t vs. <y(t). subplot(3,2,5),plot(t,real(y)),xlabel('t'), ylabel('Magnitude'),title('Re(y(t))'); subplot(3,2,6),plot(t,imag(y)),xlabel('t'), ylabel('Angle'),title('Im(y(t))'); function compexp(f,d) %compexp.m produces a 3D plot of a decaying complex exponential, % with subplots of magnitude and phase and of real and imaginary % components below it. figure t = 0:0.01:5; y=3*exp(-(d*0.25+j*(f*2*pi))*t); subplot(3,1,1); plot3(t,real(y),imag(y)); grid xlabel('t'),ylabel('Re(y)'),zlabel('Im(y)'); title('3-D plot of a Complex Exponential'); %produce magnitude and phase plots; t vs |y(t)| and t vs. <y(t). subplot(3,2,3),plot(t,abs(y)),xlabel('t'), ylabel('Magnitude'),title('Magnitude - |y(t)|');

subplot(3,2,4),plot(t,angle(y)),xlabel('t'), ylabel('Angle'),title('Phase - Arg(y(t))'); %produce real and imag plots; t vs |y(t)| and t vs. <y(t). subplot(3,2,5),plot(t,real(y)),xlabel('t'), ylabel('Magnitude'),title('Re(y(t))'); subplot(3,2,6),plot(t,imag(y)),xlabel('t'), ylabel('Angle'),title('Im(y(t))');

Você também pode gostar