PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

74 Practical MATLAB® Applications for Engineers


Create the script fi le even_odd that returns, using 201 points over the range − 10 ≤ t ≤ 10 ,
the following:

a. Plots of f(t) versus t, fe(t)* versus t, and fo(t) versus t
b. Verifi es graphically that f(t) = fe(t) + fo(t)
c. The energies of f(t), fe(t), and fo(t)
d. Verifi es that the energy {f(t)} = energy{fe(t)} + energy{fo(t)}

MATLAB Solution
% Script file: even _ odd
t = -10:0.1:10; % 201points
yzero = zeros(1,201);
y1 = [zeros(1,50) 10*ones(1,50)];
y2 = [10:-.1:0];
y = [y1 y2];

figure(1)
subplot(3,1,1)
plot(t,y);axis([-10 10 -5 13]);
title(‘ f(t) vs. t ’)
ylabel(‘Amplitude [f(t)]’);xlabel(‘time’);
flipft = fliplr(y);
feven =.5*(y+flipft);
fodd =.5*(y-flipft);
subplot(3,1,2);
plot(t,feven); axis([-10 10 -5 13]);
ylabel(‘Amplitude [feven(t)]’);xlabel(‘time’)
title(‘feven(t) vs.t’)
subplot(3,1,3)
plot(t,fodd,t,yzero);
ylabel(‘Amplitude [fodd(t)]’); xlabel(‘time’)
title(‘fodd(t) vs.t’)

figure(2)
check = feven+fodd;
ysquare = y.^2;
energyft = trapz(t,ysquare);
poweraveft = (1/200)*energyft;
fevensq = feven.^2;
energyfeven = trapz(t,fevensq);
foddsq = fodd.^2;
energyfodd = trapz(t,foddsq);
disp(‘*********************************************’)
disp(‘************ ENERGY ANALYSIS **************’)
disp(‘*********************************************’)
disp(‘The energy of f(t) =’)
disp(energyft)
disp(‘The energy of feven(t) =’)
disp(energyfeven)
disp(‘The energy of fodd(t) =’)


  • Recall that fo(t) stands for the odd portion of f(t), whereas fe(t) stands for the even portion of f(t).

Free download pdf