0% found this document useful (0 votes)
42 views11 pages

Time Domain Analysis of Discrete Time Signals and Systems: Md. Rofi Uddin

This document discusses time domain analysis of discrete time signals and systems using MATLAB. It aims to generate functions for signal shifting, folding, addition, downsampling and autocorrelation. It provides the MATLAB code to plot sample signals and the results of applying the above operations on them. These include plotting shifted, folded and added versions of given signals.

Uploaded by

Jamil Rofi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views11 pages

Time Domain Analysis of Discrete Time Signals and Systems: Md. Rofi Uddin

This document discusses time domain analysis of discrete time signals and systems using MATLAB. It aims to generate functions for signal shifting, folding, addition, downsampling and autocorrelation. It provides the MATLAB code to plot sample signals and the results of applying the above operations on them. These include plotting shifted, folded and added versions of given signals.

Uploaded by

Jamil Rofi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Date of submission August 01, 2019

Digital Object Identifier

Time Domain Analysis of Discrete Time


Signals and Systems
MD. ROFI UDDIN1
Department Of Electrical and Electronic Engineering
Chittagong University Of Engineering and Technology.

ABSTRACT This experiment is about signal shifting, signal folding, signal addition, signal down-
sampling and auto-correlation processing method and visualization of the functioning of time domain
analysis of discrete time signals and systems using MATLAB.

I. OBJECTIVES B. SIGFOLD
1) Generating function sigshift, sigfold, sigadd in The MATLAB code for sigfold.m is given below:
MATLAB. (see section II) function [y,n]=sigfold(x,n)
2) Plotting y=fliplr(x);
a) y1 [n] = x1 [n − 4] n=-fliplr(n);
b) y2 [n] = x2 [−n]
c) y3 [n] = x1 [n] + x2 [n]
C. SIGADD
for given x1 [n] = {1, −2, 3, −1, 5} and x2 [n] =
The MATLAB code for sigadd.m is given below:
{2, 4, −1, 3, 5} (see section III)
3) Plotting y [n] = x [2n − 3] for given function function [y,n]=sigadd(x1,n1,x2,n2)
x [n] = {1, 2, −3, 2, 1, 3, −7,
 8}
n=min(n1(1),n2(1)):max(n1(end),n2(end));
4) Plotting y [n] = x n3 + 2 for given function y1=zeros(1,length(n));
x [n] = {1, 2, −3, 2, 1, 3, −7, 8} y2=y1;
5) Writing a function cov_m.m to calculate convolution y1((n>=n1(1))&(n<=n1(end)))=x1;
of two discrete sequences. y2((n>=n2(1))&(n<=n2(end)))=x2;
6) Given that x [n] = {−2, 1, 4, 3}. Plotting y[n] using y=y1+y2;
cov_m.m functions. i.
a) y [n] = x [n] ∗ x [n − 2] III. PLOTTING X1 [N ], X2 [N ], Y 1 [N ], Y 2 [N ] AND Y 3 [N ]
b) y [n] = x [n] ∗ x [−n] The MATLAB code for Plotting x1 [n], x2 [n], y1 [n], y2 [n]
c) y [n] = x [−2n + 1] and y3 [n] is given below:
y [n] = x − n2 + 3

d)
clear all;
e) y [n] = x [−2n + 1] ∗ x [n]
close all;
(1; 2) clc;

II. GENERATING MATLAB FUNCTIONS addpath('C:\Users\Jamil\Downloads\


A. SIGSHIFT Compressed\PlotPub-master\lib');
The MATLAB code for sigshift.m is given below:
x1=[1 -2 3 -1 5];
function [y,n]=sigshift(x,m,n0) %m is to n1=-2:2;
shift m sample figure
n=m+n0; stem(n1,x1)
y=x; opt.XLabel = 'Sample Number (n)'; %
xlabel

VOLUME 4, 2016 1
opt.YLabel = 'x1(n)'; %ylabel opt.LineStyle = {'--'};
opt.XLim=[-4,6]; opt.Markers = {'o'};
opt.YLim=[-10,12]; opt.Legend = {'discrete sequence of y2[n
opt.LineStyle = {'--'}; ]'};
opt.Markers = {'o'}; opt.BoxDim=[4,3];
opt.Legend = {'discrete sequence of x1(n opt.Colors = [.5, .22, .32;];
)'}; opt.LineWidth = [4];
opt.BoxDim=[4,3]; setPlotProp(opt);
opt.Colors = [.5, .22, .32;];
opt.LineWidth = [4]; [y3, n]=sigadd(x1,n1,x2,n2);
setPlotProp(opt); figure
stem(n,y3)
x2=[2 4 -1 3 5]; opt.XLabel = 'Sample Number (n)'; %
n2=-2:2; xlabel
opt.YLabel = 'y3(n)'; %ylabel
figure opt.XLim=[-3,3];
stem(n2,x2) opt.YLim=[-2,13];
opt.XLabel = 'Sample Number (n)'; % opt.LineStyle = {'--'};
xlabel opt.Markers = {'o'};
opt.YLabel = 'x2(n)'; %ylabel opt.Legend = {'discrete sequence of y3[n
opt.XLim=[-3,3]; ]'};
opt.YLim=[-3,8]; opt.BoxDim=[4,3];
opt.LineStyle = {'--'}; opt.Colors = [.5, .22, .32;];
opt.Markers = {'o'}; opt.LineWidth = [4];
opt.Legend = {'discrete sequence of x2[n setPlotProp(opt);
]'};
opt.BoxDim=[4,3];
opt.Colors = [.5, .22, .32;];
opt.LineWidth = [4]; 8
setPlotProp(opt); discrete sequence of x1(n)
6
[y1, n]=sigshift(x1,4,n1);
figure 4
x1(n)

stem(n,y1)
opt.XLabel = 'Sample Number (n)'; %
xlabel
2
opt.YLabel = 'y1(n)'; %ylabel
opt.XLim=[0,10]; 0
%%opt.YLim=[-3,8];
opt.LineStyle = {'--'}; -2
opt.Markers = {'o'};
opt.Legend = {'discrete sequence of y1[n -2 0 2
]'}; Sample Number (n)
opt.BoxDim=[4,3];
FIGURE 1. MATLAB plot of x1 [n]
opt.Colors = [.5, .22, .32;];
opt.LineWidth = [4];
setPlotProp(opt);
IV. PLOTTING MATLAB CODE
The MATLAB code for y [n] = x [2n − 3] is given below:
[y2, n]=sigfold(x2,n2);
figure clear all;
stem(n,y2) close all;
opt.XLabel = 'Sample Number (n)'; % clc;
xlabel
opt.YLabel = 'y2(n)'; %ylabel addpath('C:\Users\Jamil\Downloads\
opt.XLim=[-3,3]; Compressed\PlotPub-master\lib');
%%opt.YLim=[-3,8];
2 VOLUME 4, 2016
8 8
discrete sequence of x2[n] discrete sequence of y2[n]
6 6
4 4
x2(n)

y2(n)
2 2
0 0
-2 -2
-2 0 2 -2 0 2
Sample Number (n) Sample Number (n)
FIGURE 2. MATLAB plot of x2 [n] FIGURE 4. MATLAB plot of y2 [n]

8
discrete sequence of y1[n] discrete sequence of y3[n]
6 10
4
y3(n)
y1(n)

2 5

0
-2 0

0 5 10 -2 0 2
Sample Number (n) Sample Number (n)
FIGURE 3. MATLAB plot of y1 [n] FIGURE 5. MATLAB plot of y3 [n]

x=[1 2 -3 2 1 3 -7 8];
n=-2:5; n2=-10:10;
figure y=zeros(1,length(n2));
stem(n,x) for i=1:length(n2)
opt.XLabel = 'Sample Number (n)'; % kk=2*n2(i)-3;
xlabel z=x(kk==n);
opt.YLabel = 'x(n)'; %ylabel if(length(z))
opt.XLim=[-4,6]; y(i)=z;
opt.YLim=[-10,12]; end
opt.LineStyle = {'--'}; end
opt.Markers = {'o'}; figure;
opt.Legend = {'discrete sequence of x(n) stem(n2,y)
'}; grid on;
opt.BoxDim=[4,3]; opt.XLim=[-4,6];
opt.Colors = [.5, .22, .32;]; opt.YLim=[-10,12];
opt.LineWidth = [4]; opt.XLabel = 'Sample Number (n)'; %
setPlotProp(opt); xlabel
VOLUME 4, 2016 3
opt.YLabel = 'y(n)';
opt.LineStyle = {'--'}; x=[1 2 -3 2 1 3 -7 8];
opt.Markers = {'o'}; n=-2:5;
opt.Legend = {'discrete sequence'}; figure
opt.BoxDim=[4,3]; stem(n,x)
opt.Colors = [.5, .22, .32;]; opt.XLim=[-4,6];
opt.LineWidth = [4]; opt.YLim=[-10,12];
setPlotProp(opt); opt.XLabel = 'Sample Number (n)'; %
xlabel
opt.YLabel = 'x(n)'; %ylabel
opt.LineStyle = {'--'};
opt.Markers = {'o'};
10 discrete sequence of x(n) opt.Legend = {'discrete sequence of x(n)
'};
5 opt.BoxDim=[4,3];
opt.Colors = [.5, .22, .32;];
x(n)

opt.LineWidth = [4];
0 setPlotProp(opt);

n2=-10:10;
-5 y=zeros(1,length(n2));
for i=1:length(n2)
-10 if mod(n2(i),3)==0
-4 -2 0 2 4 6 kk=n2(i)/3+2;
z=x(kk==n);
Sample Number (n) if (length(z))
FIGURE 6. MATLAB plot of x [n] y(i)=z;
end
end
end
hfig=figure;
10 discrete sequence stem(n2,y)
opt.XLim=[-12,12];
5 opt.YLim=[-10,12];
opt.XLabel = 'Sample Number (n)'; %
y(n)

xlabel
0 opt.YLabel = 'y(n)'; %ylabel
opt.LineStyle = {'--'};
opt.Markers = {'o'};
-5 opt.Legend = {'discrete sequence'};
opt.BoxDim=[4,3];
-10 opt.Colors = [.5, .22, .32;];
-4 -2 0 2 4 6 opt.LineWidth = [4];
setPlotProp(opt);
Sample Number (n)
FIGURE 7. MATLAB plot of y [n]
VI. WRITING A FUNCTION COV_M.M TO CALCULATE
CONVOLUTION OF TWO DISCRETE SEQUENCES.
V. PLOTTING MATLAB CODE 
The MATLAB code for conv_m.m is given below:
The MATLAB code for y [n] = x − n2 + 3 is given below:


clear all; function [y ny]=conv_m(x,nx,h,nh)


close all; nyb=nx(1)+nh(1);
clc; nye=nx(length(x))+nh(length(h));
ny=[nyb:nye];
addpath('C:\Users\Jamil\Downloads\ y=conv(x,h);
Compressed\PlotPub-master\lib');
4 VOLUME 4, 2016
opt.XLabel = 'Sample Number (n)'; %
xlabel
10 discrete sequence of x(n) opt.YLabel = 'y(n)'; %ylabel
opt.LineStyle = {'--'};
opt.Markers = {'o'};
5 opt.Legend = {'discrete sequence'};
opt.BoxDim=[4,3];
x(n)

0 opt.Colors = [.5, .22, .32;];


opt.LineWidth = [4];
setPlotProp(opt);
-5

-10
-4 -2 0 2 4 6
discrete sequence
Sample Number (n) 20
FIGURE 8. MATLAB plot of y [n]

10

10 discrete sequence y(n) 0

5 -10
y(n)

0 0 2 4 6 8
Sample Number (n)
-5 FIGURE 10. MATLAB plot of y [n]

-10 clear all;


-10 -5 0 5 10 close all;
Sample Number (n) clc;
addpath('C:\Users\Jamil\Downloads\
FIGURE 9. MATLAB plot of y [n] Compressed\PlotPub-master\lib');

x=[-2,1,4,3];
VII. PLOTTING Y [N ]
nx=-1:2;
clear all; figure,stem(nx,x)
close all; opt.XLim=[-4,4];
clc; opt.XLabel = 'Sample Number (n)'; %
xlabel
addpath('C:\Users\Jamil\Downloads\ opt.YLabel = 'x(n)'; %ylabel
Compressed\PlotPub-master\lib'); opt.LineStyle = {'--'};
opt.Markers = {'o'};
x=[-2,1,4,3]; opt.Legend = {'discrete sequence'};
nx=-1:2; opt.BoxDim=[4,3];
m=4; opt.Colors = [.5, .22, .32;];
[y1,n1]=sigshift(x,m,nx); opt.LineWidth = [4];
[y1 ny1]=conv_m(x,nx,y1,n1); setPlotProp(opt);
hfig=figure;
stem(ny1,y1) [h,nh]=sigfold(x,nx);
figure,stem(h,nh)
opt.XLim=[0,9];
opt.YLim=[-17,28]; opt.XLim=[-4,6];
VOLUME 4, 2016 5
opt.XLabel = 'Sample Number (n)'; %
xlabel 1
opt.YLabel = 'x(n)(folded)'; %ylabel discrete sequence
opt.LineStyle = {'--'};
opt.Markers = {'o'};

x(n)(folded)
opt.Legend = {'discrete sequence'}; 0
opt.BoxDim=[4,3];
opt.Colors = [.5, .22, .32;];
opt.LineWidth = [4];
setPlotProp(opt); -1
[y ny]=conv_m(x,nx,h,nh);
hfig=figure;
stem(ny,y) -2
-4 -2 0 2 4 6
opt.XLim=[-4,4]; Sample Number (n)
opt.YLim=[-10,35];
FIGURE 12. MATLAB plot of x [n](folded)
opt.XLabel = 'Sample Number (n)'; %
xlabel
opt.YLabel = 'y(n)'; %ylabel
opt.LineStyle = {'--'};
opt.Markers = {'o'}; 30 discrete sequence
opt.Legend = {'discrete sequence'};
opt.BoxDim=[4,3];
opt.Colors = [.5, .22, .32;]; 20
y(n)

opt.LineWidth = [4];
setPlotProp(opt); 10

0
4
discrete sequence -10
-4 -2 0 2 4
2 Sample Number (n)
x(n)

FIGURE 13. MATLAB plot of y [n]

0 hfig=stem(nx,x)
opt.XLim=[-4,4];

opt.XLabel = 'Sample Number (n)'; %


-2 xlabel
-4 -2 0 2 4 opt.YLabel = 'x(n)'; %ylabel
Sample Number (n) opt.LineStyle = {'--'};
opt.Markers = {'o'};
FIGURE 11. MATLAB plot of x [n]
opt.Legend = {'discrete sequence'};
opt.BoxDim=[4,3];
clear all; opt.Colors = [.5, .22, .32;];
close all; opt.LineWidth = [4];
clc; setPlotProp(opt);
addpath('C:\Users\Jamil\Downloads\
Compressed\PlotPub-master\lib'); n2=-10:10;
y2=zeros(1,length(n2));
x=[-2,1,4,3]; for i=1:length(n2)
nx=-1:2; kk=-2*n2(i)+1;
6 VOLUME 4, 2016
z=x(kk==nx);
if(length(z))
y2(i)=z; discrete sequence
end
4
end
hfig=figure;
2
stem(n2,y2)

y(n)
opt.XLim=[min(n2),max(n2)+2]; 0
opt.YLim=[min(y2)-1,max(y2)+1];
opt.XLabel = 'Sample Number (n)'; %
xlabel -2
opt.YLabel = 'y(n)'; %ylabel
opt.LineStyle = {'--'};
opt.Markers = {'o'}; -10 -5 0 5 10
opt.Legend = {'discrete sequence'}; Sample Number (n)
opt.BoxDim=[4,3];
FIGURE 15. MATLAB plot of y [n]
opt.Colors = [.5, .22, .32;];
opt.LineWidth = [4];
setPlotProp(opt);
y3(i)=z;
end
end
hfig=figure;
4 stem(n3,y3);
discrete sequence
opt.XLim=[min(n3),max(n3)+2];
opt.YLim=[min(y3)-1,max(y3)+1];
2 opt.XLabel = 'Sample Number (n)'; %
x(n)

xlabel
opt.YLabel = 'y(n)'; %ylabel
0 opt.LineStyle = {'--'};
opt.Markers = {'o'};
opt.Legend = {'discrete sequence'};
opt.BoxDim=[4,3];
-2 opt.Colors = [.5, .22, .32;];
-4 -2 0 2 4 opt.LineWidth = [4];
setPlotProp(opt);
Sample Number (n)
FIGURE 14. MATLAB plot of x [n]
clear all;
close all;
clear all; clc;
close all; addpath('C:\Users\Jamil\Downloads\
clc; Compressed\PlotPub-master\lib');
addpath('C:\Users\Jamil\Downloads\
Compressed\PlotPub-master\lib');
x=[-2,1,4,3];
nx=-1:2;
x=[-2,1,4,3]; n2=-10:10;
nx=-1:2; y2=zeros(1,length(n2));
n3=-10:10; for i=1:length(n2)
y3=zeros(1,length(n3)); kk=-2*n2(i)+1;
for i=1:length(n3) z=x(kk==nx);
kk=-2^(-1)*n3(i)+3; if(length(z))
z=x(kk==nx); y2(i)=z;
if(length(z)) end
VOLUME 4, 2016 7
15
discrete sequence discrete
4
10 sequence

2 5
y(n)

y(n)
0 0

-2 -5

-10 -5 0 5 10 -10 -5 0 5 10
Sample Number (n) Sample Number (n)
FIGURE 16. MATLAB plot of y [n] FIGURE 17. MATLAB plot of y [n]

end opt.Markers = {'o'};


hfig=figure; opt.Legend = {'data'};
stem(n2,y2) opt.BoxDim=[4,3];
opt.Colors = [.5, .22, .32;];
opt.LineWidth = [.8];
[y3 ny3]=conv_m(y2,n2,x,nx); opt.XLim=[min(t),max(t)];
hfig=figure; opt.YLim=[min(x)-1,max(x)+1];
stem(ny3,y3) setPlotProp(opt);

opt.XLim=[min(ny3),max(ny3)+2];
opt.YLim=[min(y3)-1,max(y3)+1];
opt.XLabel = 'Sample Number (n)'; % rx=xcorr(x,x);
xlabel figure,plot(rx);
opt.YLabel = 'y(n)'; %ylabel SNR1=2;
opt.LineStyle = {'--'}; y1=awgn(x,SNR1,0);
opt.Markers = {'o'}; figure,plot(y1);
opt.Legend = {'discrete sequence'}; ry1=xcorr(y1,y1);
opt.BoxDim=[4,3]; figure,plot(ry1);
opt.Colors = [.5, .22, .32;]; SNR2=20;
opt.LineWidth = [4]; y2=awgn(x,SNR2,0);
setPlotProp(opt); figure,plot(y2);
ry2=xcorr(y2,y2);
figure,plot(ry2);
A. SNR SNR3=0.2;
y3=awgn(x,SNR3,0);
addpath('C:\Users\Jamil\Downloads\ figure,plot(y3);
Compressed\PlotPub-master\lib'); ry3=xcorr(y3,y3);
figure,plot(ry3)
Fs=1000;
f=10;
t=0:1/Fs:1;
x=sin(2*pi*f*t);
figure,plot(t,x);

opt.XLabel='Time,t';
opt.YLabel='Sine Wave';
opt.LineStyle = {'--'};
8 VOLUME 4, 2016
2 1200

data 1000

1 800
Sine Wave

600

400
0
200

0
-1
-200

-400
-2
0 0.5 1 -600
0 500 1000 1500 2000 2500

Time,t
FIGURE 18. Generating Sinewave FIGURE 21. Autocorrelation of y

600 1.5

400 1

200 0.5

0 0

-200 -0.5

-400 -1

-600 -1.5
0 500 1000 1500 2000 2500 0 200 400 600 800 1000 1200

FIGURE 19. Auto correlation of a sinwave FIGURE 22. Adding Additive white Gaussian Noise with x, SNR=20

4 600

3
400

200
1

0 0

-1
-200

-2

-400
-3

-4 -600
0 200 400 600 800 1000 1200 0 500 1000 1500 2000 2500

FIGURE 20. Adding Additive white Gaussian Noise with x, SNR=2 FIGURE 23. Autocorrelation of y

VOLUME 4, 2016 9
4

-1

-2

-3

-4
0 200 400 600 800 1000 1200

FIGURE 24. Adding Additive white Gaussian Noise with x, SNR=25

2000

1500

1000

500

-500

-1000
0 500 1000 1500 2000 2500

FIGURE 25. Autocorrelation of y

10 VOLUME 4, 2016
MD. ROFI UDDIN born in Sylhet, Bangladesh
in 1997. He received the S.S.C degree from
Blue Bird School & College and H.S.C from
M.C College in science group. From 2016 he
started his Bachelor at CHITTAGONG UNIVER-
SITY OF ENGINEERING AND TECHNOLOGY
in Electrical and Electronic Engineering Depart-
ment.Now he is a Level-4 Term-1 student.

REFERENCES
[1] J. Proakis, Digital signal processing(4th Edition), 1975.
[2] A. V. Oppenheim, “Discrete-Time Signal Processing,” in
Electronics and Power, 1999.

VOLUME 4, 2016 11

You might also like