96 C H A P T E R 1: Continuous-Time Signals
grid
axis([min(t) max(t) -1 5])
function [ye,yo] = evenodd(t,y)
% even/odd decomposition
% t: time
% y: analog signal
% ye, yo: even and odd components
% USE [ye,yo] = evenodd(t,y)
%
yr = fliplr(t,y);
ye = 0.5 * (y + yr);
yo = 0.5 * (y - yr);
The MATLAB functionfliplrreverses the values of the vectorygiving the reflected signal. n
nExample 1.18
Use symbolic MATLAB to generate the following analog signals.
(a) For the damped sinusoid signal
x(t)=e−tcos( 2 πt)
obtain a script to generatex(t)and its envelope.
(b) For a rough approximation of a periodic pulse generated by adding three cosines of
frequencies multiples of 0 =π/10—that is
x 1 (t)= 1 +1.5 cos( 2 0 t)−0.6 cos( 4 0 t)
write a script to generatex 1 (t).
Solution
The following script generates the damped sinusoid signal, and its envelopey(t)=±e−t.
%%%%%%%%%%%%%%%%%%%
% Example 1.18 --- damped sinusoid
%%%%%%%%%%%%%%%%%%%
t = sym(’t’);
x = exp(-t) * cos(2 * pi * t);
y = exp(-t);
ezplot(x,[-2,4])
grid
hold on
ezplot(y,[-2,4])