Você está na página 1de 5

Lab01 Handout Elementary Signals

Lab 01 Handout : Elementary Signals


Generation of signals in MATLAB mostly require that we begin with the vector
representation of time t or n. To generate a vector t of time values with a sampling interval Ts
of 1 ms on the interval from 0 to 1 s, for example we use the command
t=0:0.001:1;

This vector encompasses 1000 time samples each second, or a sampling rate of 1000 Hz. To
generate a vector n of time values for discrete-time signals, say, from n= 0 to n= 1000, we use
the command
n=0:1000;

Given t or n, we may then proceed to generate the signal of interest.

1.1 PERIODIC SIGNALS


Consider first the generation of a square waves of amplitude A, fundamental frequency w0
(measured in radians per second), and duty cycle rho. That is, rho is the fraction of each
period for which the signal is positive. The square wave shown in Figure 1 was generated
with the following complete set of commands:
A=1;
w0=10*pi;
rho=50;
t=0:0.001:1;
sq=A*square(w0*t,rho);
plot(t,sq);
axis([0 1 -1.1 1.1]);

In the second command, pi is a built-in MATLAB function that returns the floating-point
number closest to . The plot command is used to view square wave. The command plot
draws lines connecting the successive values of the signal and thus gives the appearance of a
continuous-time signal. Try to vary the values of rho to rho=20 and rho=90.
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0

0.1

0.2

0.3

0.4

0.5

0.6

Figure 1
Page 1 of 5

0.7

0.8

0.9

Lab01 Handout Elementary Signals

To generate Triangular/Sawtooth wave, the MATLAB command sawtooth can be used.


Important parameters are fundamental frequency w0 (measured in radians per second), width
W and amplitude A.
The following description about sawtooth is extracted from MATLAB Help.
sawtooth(t, width) generates a modified triangle wave where width, a scalar parameter
between 0 and 1, determines the point between 0 and 2 at which the maximum occurs. The
function increases from -1 to 1 on the interval 0 to 2*width, then decreases linearly from 1
to -1 on the interval 2*width to 2. Thus a parameter of 0.5 specifies a standard triangle
wave, symmetric about time instant with peak-to-peak amplitude of 1. sawtooth(t,1) is
equivalent to sawtooth(t).

As mentioned previously, a signal generated in MATLAB is inherently of a discrete-time


nature. To visualize a discrete-time signal, we may use the stem command. Specifically,
stem(n,x) depicts the data contained in vector x as a discrete-time signal at the time values
defined by n. The vectors n and x must, of course have compatible dimensions.
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-10

-8

-6

-4

-2

10

Figure 3
Consider, for example, the discrete-time square wave shown in Figure 3. This signal is
generated by the following commands:
A=1;
omega=pi/4;
n=-10:10;
x=A*square(omega*n);
stem(n,x)

Page 2 of 5

Lab01 Handout Elementary Signals

1.2 EXPONENTIAL SIGNALS


The following commands were used to generate the decaying exponential signal shown in
Figure 4.
B=5;
a=6;
t=0:0.001:1;
x=B*exp(-a*t);
plot(t,x);

The growing exponential signal shown in Figure 5 was generated with these commands
B=1;
a=5;
t=0:0.001:1;
x=B*exp(a*t);
plot(t,x);

150

5
4.5
4
3.5

100

3
2.5
2
50

1.5
1
0.5
0

0
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Figure 4

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Figure 5

1.3 SINUSOIDAL SIGNALS


MATLAB also contains trigonometric functions that can be used to generate sinusoidal
signals. A cosine signal of amplitude A, frequency w0 (measured in radians per second), and
phase angle phi (in radians) is obtained by using the following commands and the signal is
shown in Figure 8:
A=4;
w0=20*pi;
t=0:0.001:0.2;
cosine=A*cos(w0*t);
plot(t,cosine);
axis([0 0.2 -6 6]);

Figure 9 is the discrete-time cosine signal generated using the following commands:

Page 3 of 5

Lab01 Handout Elementary Signals


A=1;
omega=2*pi/12;
n=-10:10;
y=A*cos(omega*n);
stem(n,y);
axis([-10 10 -2 2]);

2
1.5

0.5

0
-0.5

-1

-1.5

-2
-10

Figure 8

-8

-6

-4

-2

Figure 9

1.4 EXPONENTIALLY DAMPED/GROWING SINUSOIDAL SIGNALS


In all of the MATLAB signal-generation commands just described, we have generated the
desired amplitude by multiplying a scalar A by a vector representing a unit-amplitude signal
(e.g. cos(w0*t). This operation is described by using an asterisk. We next consider the
generation of a signal that requires the element-by-element multiplication of two vectors.
Suppose we multiply a sinusoidal signal by an exponential signal to produce an exponentially
damped/growing sinusoidal signal. With each signal component represented by a vector, the
generation of such a product signal requires the multiplication of one vector by another on an
element-by-element basis. MATLAB represents element-by-element multiplication by a dot
followed by an asterisk.
The equation for generating the exponentially damped/growing sinusoidal signal is given by
x(t ) = A sin(0t + )e at
a produces growing and decaying exponential respectively given positive value a.
The discrete-time exponentially damped/growing sinusoidal signal can be generated by
multiplying the sinusoidal sequence x[n] by the decaying/growing exponential sequence y[n].
Both sequences must be defined for same n range.

Page 4 of 5

10

Lab01 Handout Elementary Signals

1.5 RAMP, STEP AND IMPULSE FUNCTIONS


A ramp function is generated using following commands and Figure 15 shows the signal:
ramp=0:0.1:10;
t=0:0.1:10;
y=plot(t,ramp)

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

10

Figure 15

In MATLAB, ones(M,N) is an M-by-N matrix of ones, and zeros (M,N) is an M-by-N matrix
of zeros. We may use these two matrices to generate two commonly used signals:

 Discrete-time impulse
 Step function
A pair of step functions shifted in time relative to each other may be used to produce a
rectangular pulse.

Page 5 of 5

Você também pode gostar