You are on page 1of 3

SIGNALS & SYSTEMS USING MATLAB

Lab 0---Basic Operations on Signals


Example 1.23
Generate and sketch in the same gure each of the following CT signals using
MATLAB. Do not use the for loops in your code. In each case, the horizontal
axis t used to sketch the CT should extend only for the range over which the
three signals are dened.
(a) x1(t) = 5 sin(2pi t) cos(pi t 8) for 5 t 5;
(b) x2(t) = e0.2t sin (2pi t) for 10 t 10;
(c) x3(t) = e (j4pi 05)t u(t) for 5 t 15.
Solution
The MATLAB code for the generation of signals (a)(c) is as follows:
>> %%%%%%%%%%%%
>> % Part(a) %
>> %%%%%%%%%%%%
>> clf % Clear any existing figure
>> t1 = [-5:0.001:5]; % Set the time from -5 to 5 with a sampling
% rate of 0.001s
>> x1 = 5*sin(2*pi*t1).*cos(pi*t1-8);
% compute function x1
>> % plot x1(t)
>> subplot(2,2,1); % select the 1st out of 4 subplots
>> plot(t1,x1); % plot a CT signal
>> grid on; % turn on the grid
>> xlabel(time (t)); % Label the x-axis as time
>> ylabel(5sin(2\pi t)
cos(\pi t - 8));
% Label the y-axis
>> title(Part (a)); % Insert the title
>> %%%%%%%%%%%%
>> % Part(b) %
>> %%%%%%%%%%%%
>> t2 = [-10:0.002:10]; % Set the time from -10 to 10 with a sampling
% rate of 0.002s
>> x2 = 5*exp(-0.2*t2).*sin(2*pi*t2); % compute function x2
>> % plot x2(t)
>> subplot(2,2,2); % select the 2 nd out of 4 subplots
>> plot(t2,x2); % plot a CT signal
>> grid on; % turn on the grid
>> xlabel(time (t)); % Label the x-axis as time
>> ylabel(5exp(-0.2t) sin(2\pi t)); % Label the y-axis

>> title(Part (b)); % Insert the title


>> %%%%%%%%%%%%
>> %Part(c)%
>> %%%%%%%%%%%%
>> t3 = [-5:0.001:15]; % Set the time from -5 to 15 with a sampling
% rate of 0.001s
>> x3 = exp((j*4*pi-0.5)*t3).*(t3>=0); % compute function x3
>> % plot the real component of x3(t)
>> subplot(2,2,3); % select the 3rd out of 4 subplots
>> plot(t3,real(x3)); % plot a CT signal
>> grid on; % turn on the grid
>> xlabel(time (t)) % Label the x-axis as time
>> ylabel(5exp[(j*4\pi-0.5)t]u(t)); % Label the y-axis
>> title(Part (c): Real Component); % Insert the title
>> subplot(2,2,4); % select the 4 th out of 4 subplots
>> plot(t3,imag(x3)); % plot the imaginary component of a CT signal
>> grid on; % turn on the grid
>> xlabel(time (t)); % Label the x-axis as time
>> ylabel(5exp[(j4\pi-0.5)t]u(t)); % Label the y-axis
>> title(Part (d): Imaginary Component);
% Insert the title

Example 2
Repeat Example 1 for the following DT sequences:
(a) f1[k] = 9.2 sin(0.1pi k 3 pi/4) for 10 k 20;
(b) f2[k] = 2.0(1.1)1.8k 2.1(0.9)0.7k for 5 k 25;
(c) f3[k] = (0.93)k e j pi k/ 350 for 0 k 50.
Solution
The MATLAB code for the generation of signals (a)(c) is as follows:
>> %%%%%%%%%%%%
>> % Part(a) %
>> %%%%%%%%%%%%
>> clf % clear any existing figure
>> k = [-10:20]; % set the time index from -10 to 20
>> f1 = -0.92 * sin(0.1*pi*k- 3*pi/4);>> % plot function 1
>> subplot(2,2,1), stem(k, f1, filled), grid
>> xlabel(k)
>> ylabel(-9.2sin(0.1\pi k-0.75\pi)
>> title(Part (a))
>> %%%%%%%%%%%%
>> % Part(b) %
>> %%%%%%%%%%%%
>> k = [-5:25];
>> f2 = 2 * 1.1.(-1.8*k) - 2.1 * 0.9.(0.7*k);
>> subplot(2,2,2), stem(k, f2, filled), grid
>> xlabel(k)
>> ylabel(2(1.1){-1.8k} - 2.1(0.9)0.7k)
>> title(Part (b))
>> %%%%%%%%%%%%
>> % Part(c) %
>> %%%%%%%%%%%%
>> k = [0:50];
>> f3 = (-0.93).k .* exp(j*pi*k/sqrt(350));
>> subplot(2,2,3), stem(k, real(f3), filled), grid
>> xlabel(k)
>> ylabel((-0.93)k exp(j\pi k/(350){0.5})
>> title(Part (c) - real part)
>> %
>> subplot(2,2,4), stem(k, imag(f3), filled), grid
>> xlabel(k)
>> ylabel((-0.93)k exp(j\pi k/(350){0.5})
>> title(Part (d) - imaginary part)
>> print -dtiff plot.tiff

You might also like