The MATLAB code defines a discrete-time signal x[n] and plots it along with shifted (x[n-2]), modulated (x[n]u[2-n]), and even/odd parts of the signal. The code generates the plots by: 1) defining x[n] on domain n=-6 to 6; 2) plotting the original and transformed signals using STEM; and 3) decomposing x[n] into its even and odd parts by adding/subtracting the signal with its time-reversed version. The plots generated include those for the problems (a), (d), (g), and (h).
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
Discrete time signals on MATLAB
1. DISCRETE – TIME SIGNALS PLOTTING ON MATLAB
EXAMPLE
Solution by: MartinWachiye Wafula
MultimediaUniversity of Kenya
wachiyem@gmail.com
Problem:
Using MATLAB, producethe plot for (a), (d), (g) and (h)
Solution:
The code on MATLAB is as shownbelow:
%DISCRETE-TIME SIGNALS
%Author: Martin Wachiye Wafula
% Multimedia University of Kenya
%Date: 15th February, 2017
n = -6:6;
%The original signal x[n]
xn =((n+1)==0)+ (n==0)+ ((n-1)==0)+ ((n-2)==0)+ ...
0.5*(((n-3)==0)+ ((n-4)==0));
subplot(3,2,1)
stem(n,xn,'filled'), xlabel('n'), ylabel('x[n]')
title('plot of x[n]'), grid
%x[n] could also be plotted using the code below
% xn1 = ((n+1)==0)+(n>=0)-((n-3)>=0)+0.5*(((n-3)>=0)-((n-5)>=0));
%stem(n,xn1,'filled')
%(a) signal x[n-2]
xn_a = (((n-2)+1)==0)+ ((n-2)==0) + (((n-2)-1)==0) + ...
(((n-2)-2)==0) + 0.5*((((n-2)-3)==0) + (((n-2)-4)==0) );
2. subplot(3,2,2)
stem(n,xn_a,'filled'), xlabel('n'), ylabel('x[n-2]')
title('plot(a) x(n-2)'),grid
%signal (d): x[n]u[2-n]
xn_d = xn .*((2-n)>=0);
subplot(3,2,3)
stem(n,xn_d,'filled'), xlabel('n'), ylabel('x[n]u[2-n]')
title('plot(d) x[n]u[2-n]'),grid
% to obtain odd and even part of the signal x[n]
xN = fliplr(xn); %reversed version of x[n] i.e x[-n]
xe = (xn + xN)/2; %computing the even part
xo = (xn - xN)/2; %computing the odd part
ver = xn - (xe + xo) % to verify our decomposition
subplot(3,2,4)
stem(n,xe,'filled'), xlabel('n'), ylabel('xe[n]'),axis([-6 6 -1 1.5])
title('(g) Even Part'), grid
subplot(3,2,5)
stem(n,xo,'filled'), xlabel('n'), ylabel('xo[n]'),axis([-6 6 -1 1.5])
title('(h) Odd Part'), grid
The plots obtainedfrom running the code are as depictedby the screenshot
below: