Professional Documents
Culture Documents
Laboratory 3 - Plotting Signals
Laboratory 3 - Plotting Signals
Student ID:
Instructions
Marking Scheme
1
Laboratory 3 - Plotting Signals
Contents
3.1 Plot and stem functions . . . . . . . . . . . . . . . . . . . . . 3
3.2 Student Task 1 - Plot and stem functions . . . . . . . . . . . . 5
3.3 Real exponential signals . . . . . . . . . . . . . . . . . . . . . 7
3.4 Student Task 2 - Plot a decaying exponential . . . . . . . . . . 8
3.5 Sinusoidals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.6 Student Task 3 - Plot sinusoidals . . . . . . . . . . . . . . . . 10
3.7 Complex exponentials . . . . . . . . . . . . . . . . . . . . . . 11
3.8 Student Task 4 - Plot complex exponential . . . . . . . . . . . 12
3.9 Plotting and saving a good quality figure . . . . . . . . . . . . 13
3.10 Student Task 5 - Saving a good quality figure . . . . . . . . . 14
2
3.1 Plot and stem functions
Say we want to generate a continuous-time function/signal x(t) = 3t. Time
t needs to start somewhere and end somewhere.
t=1:10;
x = 3*t;
Finally, the plot function allows us to see the plot of the function, as shown
in Figure 1. Note the labels and title of the figure.
plot(t,x);
xlabel('time - t');
ylabel('x(t)');
3
The stem function is very similar to the plot function. It is usually used to
represent discrete-time functions or signals.
Since t and x are already in the workspace, we can simply use the stem
function. We can make a new f igure and then use the stem function.
figure
stem(t,x);
Similar to plot, we can also add labels to the x − axis and y − axis.
xlabel('time');
ylabel('x[n]');
4
3.2 Student Task 1 - Plot and stem functions
Task 1. Plot the signal given by x(t) = 2t + 1 for 0 ≤ t ≤ 5. Add
appropriate label(s) and title(s). Write the code, print and paste the figure(s)
here.
It is a good practice to have the following piece of code before you start.
clear all
close all
clc
clear all clears all the variables from the workspace, close all closes all the
figures and clc clears the screen.
5
Task 2. Use stem to make x[n] = 4 for −10 ≤ n ≤ 10. Add appropriate
label(s) and title(s). Write the code, print and paste the figure(s) here.
6
3.3 Real exponential signals
A continuous-time real exponential signal is of the form x(t) = Ceat . Let us
plot this signal with C = 3 and a = 2.
clear all
close all
clc
t=-1.5:0.001:1.5;
x=3*exp(2*t) ;
plot(t,x)
axis([-2 2 -10 70 ])
The axis command is used to control the axis of the figure. The x-axis is
from −2 to 2 and y-axis is from −10 to 70.
7
3.4 Student Task 2 - Plot a decaying exponential
Task 3. Plot a continuous-time decaying (negative value of a) real expo-
nential of the form x(t) = Ceat . Add appropriate label(s) and title(s). Write
the code, print and paste the figure(s) here.
8
3.5 Sinusoidals
A continuous-time sinusoidal signal is of the form Acos(wo t + φ). Where A
is the amplitude, wo is the f requency, t is the time and φ is the phase. Such
a signal is generated by the following code and shown in Figure 4.
clear all
close all
clc
A=2;
w=pi/2;
t=-pi:pi/100:pi;
phi=pi;
x=A*cos(w*t+phi);
plot(t,x);
9
3.6 Student Task 3 - Plot sinusoidals
Task 4. Plot the continuous-time sinusoidal signals given by 3cos(πt + π2 ).
Add appropriate label(s) and title(s). Write the code, print and paste the fig-
ure(s) here. State the differences between the figure you plotted and Figure 4.
10
3.7 Complex exponentials
The real part of a complex exponential signal is of the form |C|ert cos(wo t+φ),
where |C|ert is the envelope of the signal, wo is the f requency, t is the time
and φ is the phase. Such a signal is generated by the following code and
shown in Figure 5. This signal is a sinusoidal signal multiplied with a growing
exponential. grid on places a grid on the figure.
clear all
close all
clc
t=-10:0.001:10 ;
x=3*exp(0.1*t).*cos(2*t+pi/4) ;
plot(t,x)
axis([-10 10 -10 10 ])
grid on
11
3.8 Student Task 4 - Plot complex exponential
Task 4. Plot the real part of a continuous-time complex exponential signal
given by |3|e−0.1t cos(2t + pi/4). Add appropriate label(s) and title(s). Write
the code, print and paste the figure(s) here. State the differences between
the figure you plotted and Figure 5.
12
3.9 Plotting and saving a good quality figure
We can plot a good quality figure of the real part of a complex exponential
signal of the form |C|ert cos(wo t + φ) plotted in the previous section. This
is done by increasing the LineW idth option and saving the figure in an
appropriate format and high resolution. The figure can be saved using the
print function, as a png file named gqrealce, with 600 dot per inch resolution.
This saved file is shown in Figure 6.
clear all
close all
clc
t=-10:0.001:10 ;
x=3*exp(0.1*t).*cos(2*t+pi/4) ;
plot(t,x,'-k','LineWidth',2);
axis([-10 10 -10 10 ]);
grid on
print('-dpng','-r600','gqrealce');
13
3.10 Student Task 5 - Saving a good quality figure
Task 5. Plot and save (good quality) the real part of a continuous-time
complex exponential signal given by |3|e−0.1t cos(2t + pi/4). Add appropriate
label(s) and title(s). Write the code, print and paste the figure(s) here.
14