Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

EE 23352 Applied Programming in Signals and Systems

Lab 1: Introduction to Signals and Systems in MATLAB 21/10/2011

1
1.1

Generation of signals in MATLAB


Periodic signals

A periodic signal with period T repeats itself every T seconds, x(t) = x(t + T ), is integer

An example of these signals is the sinusoidal with period T and amplitude A, x(t) = A sin 2 2 t , = 0 , the fundamental angular frequyency T T

Amplitude

T =

2 0

0 t [seconds]

Figure 1: sine signal x(t) = A sin

2 t T

Periodic signals can be generated in MATLAB using time, t and signal x vectors according to the signal period, T . t = 0 : Incr : N*T; % Time vector x = A*sin(2*pi*t/T); % Signal vector plot(t,x) ; ylabel(x(t)) ; xlabel(t)

The increment is chosen as, Incr = to generate.

T 100

or smaller. The constant N is the number of cycles

1.2

Generation of nite duration signals

A nite duration signal x(t) is dened as x(t) = 0 , < t1 < t < t2 < . in MATLAB the signal is generated by dening a time and a signal vectors. First the signal is initialized to zero using zeros function, and then the dierent values in the signal are set using the relational operators. The increment in the time vector is chosen a small value (e.g. 0.01). t An example of these signals is x(t) = rect 2 which is a rectangular pulse in the duration 1 < t < 1. To generate this pulse in MATLAB t = -2:0.02:2; % Time vector chosen to cover the signal duration x = zeros(size(t)); % initialize signal to zeros, % the signal vector size has to be the same as the time vector size x(t>=-1 & t<=1)=1; % set the values in the time duration -1<t<1 to one plot(t,x);ylabel(x(t));xlabel(t [seconds]); The signal x(t) is shown in gure 2.
1

0.9

0.8

0.7

0.6 x(t)

0.5

0.4

0.3

0.2

0.1

0 2

1.5

0.5

0 t [seconds]

0.5

1.5

Figure 2: Rectangular pulse signal x(t) = rect

t 2

Signals time transformation

Given the signal x(t) we can nd the signal y(t) = x(at t0 ) which is a time transformed version of x(t). The signal y(t) is the signal x(t) shifted to the right by t0 and then scaled by

a. One way to nd the signal in MATLAB is to generate x(t) and then setting told = at t0 , +t t then solve for t = tolda 0 . For example x(t) = rect 2 , y(t) = x(2t + 3), t = told 3 . 2 t = -2:0.02:2; % Time vector chosen to cover the signal duration %(will become t_old at the transformation) x = zeros(size(t)); % initialize signal to zeros, % the signal vector size has to be the same as the time vector size x(t>=-1 & t<=1)=1; % set the values in the time duration -1<t<1 to one plot(t,x);ylabel(x(t));xlabel(t [seconds]); %transform the signal in time t=(t-3)/2; figure(2) plot(t,x);ylabel(x(2t +3));xlabel(t [seconds]);

Procedure
t 4

1. (10 points) (a) Write a MATLAB code to generate the signal x(t) = code:

(b) Use MATLAB to generate and plot 3 cycles of the signal x(t) = 3 cos(2 400t). Label the period and amplitude on the graph. Write down your codes:
3

x(t) = 3 cos(2 400t)

3 0 1 2 3 4 5 6 7 8 x 10 9
3

t[sec]

Figure 3: signal x(t) = 3 cos(2 400t)

code:

(c) Obtain the signal y(t) = x(3t + 2) for x(t) shown below. Write down the code to generate and plot the signal y(t). code:

1.5

x(t)

1 0.5

0 3

2.5

1.5

0.5

0.5

1.5

t[sec]

y(t) = x(3t + 2)

1.5

1 0.5 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

t[sec]

Figure 4: signals x(t) and x(3t + 2) for procedure (c)

You might also like