You are on page 1of 13

Experiment No.

3
Aim: Write MATLAB Codes for generating and plotting
various combinations of the two signals and perform time
scaling, time shifting, time reversal and multiple
Transformations.

Theory:
When a signal is processed, the signal undergoes many
manipulations involving the independent variable and the
dependent variable. Some of these manipulations include:
• Shifting the signal in the time domain.
• Folding the signal
• Scaling in the time-domain
A brief introduction of these manipulations is given below.

Shifting
In the case of discrete-time signals, the independent variable
is the time, n. A signal x(n)may be shifted in time, i.e. the
signal can be either advanced in the time axis or delayedin the
time axis. The shifted signal is represented by x(n-k), where k
is an integer. If ‘k’ ispositive, the signal is delayed by k units
of time and if k is negative, the time shift results
in an advance of signal by k units of time.

Folding
This operation is done by replacing the independent variable n
by –n. This results infolding of the signal about the origin, i.e.
n=0. Folding is also known as the reflection of the signal
about the time origin n=0. Folding of a signal is done while
convoluting the signal with another.

Time scaling
This involves replacing the independent variable n by kn,
where k is an integer. Thisprocess is also called as down
sampling. If x(n) is the discrete-time signal obtained by
sampling the analog signal, x(t), then x(n) = x (nT), where T is
the sampling period. If time–scaling is done, then the time-
scaled signal, y[n]=x(kn)=x(knT). This implies that the
sampling rate is changed from 1/T to 1/kT.

Implementation:
Steps for converting continuous time signal to the discrete
time signal are as follows:
1). Assign the value of sampling time, T .
2). Vary the time integer ‘n’ between two integer points with
an increment of 1.
3). The discrete version can be obtained as: y(n) = y(nT).

Useful Commands in MATLAB:


Stem: stem (n, y); plots the data sequence Y as stems from the
x axis terminated withcircles for the data value. If Y is a
matrix then each column is plotted as a separate series.
Subplot : subplot(m ,n, p); plots the data sequences by
dividing the main figure window. In m×n sub- windows and
total m×n subplots can be plotted either in continuous time
domain by adding simple plot in addition with subplot or in
discrete time domain by addition of stem.
In lab Questions:
Q. 1. Write MATLAB Codes for generating and plotting the
following combinations of the two signals over the range,
-20< n < 20.
Let x1 [n] = 2sin( 2πn/8)u[n] and x2 [n] = −4e-(n/6)(n/6).
(a) x [n ]=x1 [n ]x2 [n]
n=-24:1:24;
x1=2.*sin(2*pi*n./8).*(1*(n>0)+0*(n<0));
x2=-4.*exp(-((n./6).^2));
stem(n,x1.*x2)
title('week 3 q1.a')

(b) x[n]= 4x1 [n] + 2x2 [n]


n=-20:1:20;
x1=2.*sin(2*pi*n./8).*(1*(n>0)+0*(n<0));
x2=-4.*exp(-((n./6).^2));
stem(n,4.*x1+2.*x2)
title('week 3 q1.b')
(c) x[n]=x1 [2 n]x2 [3n ]
n=-20:1:20;
x1=2.*sin(2*pi*2.*n./8).*(1*(2.*n>0)+0*(2.*n<0));
x2=-4.*exp(-((3.*n./6).^2));
stem(n,x1.*x2)
title('week 3 q1.c')
(d) x [n ]=x1 [2 n]/x2 [-n ]
n=-20:1:20;
x1=2.*sin(2*pi*2.*n./8).*(1*(2.*n>0)+0*(2.*n<0));
x2=-4.*exp(-((-n./6).^2));
stem(n,x1./x2)
title('week 3 q1.d’)

(e) x [n]= 3x1 [n /2] + 2x2 [n / 3]


n=-20:1:20;
x1=2.*sin(pi*n./8).*(1*(n./2>0)+0*(n./2<0));
x2=-4.*exp(-((n./18).^2));
stem(n,3.*x1+2.*x2)
title('week 3 q1.e')
2.Write MATLAB Codes for generating the following
sequences:

-4, n<-6
x[n] = n, -6<=n<3
2/n, 3<=n

Sketch x [-n], x [3-n], x[2n] and x[n/2].

(a) n=-20:1:20;
x=-4*(-n<(-6))+(-n.*((-6)<=-n & -n<3))+(2./(-n)).*(-
n>=3);
subplot(2,2,1),stem(n,x)
title('week 3 q2')

(b) n=-20:1:20;
x=-4*((3-n)<(-6))+((3-n).*((-6)<=(3-n) & (3- n)<3))
+(2./(3-n)).*((3-n)>=3);
subplot(2,2,2),stem(n,x)
title('week 3 q2')

(c) n=-20:1:20;
x=-4*((2.*n)<(-6))+((2.*n).*((-6)<=(2.*n) &
(2.*n)<3))+(2./(2.*n)).*((2.*n)>=3);
subplot(2,2,3),stem(n,x)
title('week 3 q2')

(d) n=-20:1:20;
x=-4*((n./2)<(-6))+((n./2).*((-6)<=(n./2) & (n./2)<3))
+(2./(n./2)).*((n./2)>=3);
subplot(2,2,4),stem(n,x)
title('week 3 q2')
3.Generate x (t) & sketch each of the following signals
derived from x (t) :

i) x(3t)
ii) x(3t + 2)
iii) x(2 − t)
i) n=-5:0.1:5;
x=0.*(n<-1)+(n+1).*(-1<=n & n<0)+(1-n).*(0<=n &
n<1)+0.*(n>=1);
subplot(2,2,1),plot(n,x)
ii) n=-5:0.1:5;
x1=0.*((3.*n)<-1)+((3.*n)+1).*(-1<=(3.*n) &
(3.*n)<0)+(1-(3.*n)).*(0<=(3.*n) &
(3.*n)<1)+0.*((3.*n)>=1);
subplot(2,2,2),plot(n,x1)
iii) n=-5:0.1:5;
x2=0.*((3.*n+2)<-1)+((3.*n+2)+1).*(-1<=(3.*n+2) &
(3.*n+2)<0)+(1-(3.*n+2)).*(0<=(3.*n+2) &
(3.*n+2)<1)+0.*((3.*n+2)>=1);
subplot(2,2,3),plot(n,x2)
iv) n=-5:0.1:5;
x3=0.*((2-n)<-1)+((2-n)+1).*(-1<=(2-n) & (2-
n)<0)+(1-(2-n)).*(0<=(2-n) & (2-n)<1)+0.*((2-n)>=1);
subplot(2,2,4),plot(n,x3)
Post lab Question:
Q1. Generate this signal:

t=-2:0.01:8;
x1=-2.*(1*(t==-1)+0*(t~=-1))+(2*t).*(-1<t & t<1)+2.*(1<=t
& t<2)+3.*(1*(t==2)+0*(t~=2))-2.*(1*(t==2)+0*(t~=2))+(-
t+5).*(2<=t & t<4)+1.*(4<=t & t<5)+(-t+6).*(5<=t &
t<7)+1.*(1*(t==7)+0*(t~=7));
plot(t,x1)
title('week3 home1')

Q2. Generate x [n] & sketch each of the following signals


derived from x [n]:

a) x [2n]
b) x [3n – 1]
c) x [3 - n]

a) n=-10:1:10;
x1=0.*(1*(n==-4))+(0*(n~=-4))+(-1).*(1*(n==-3))
+(0*(n~=-3))+0.*(1*(n==-2))+(0*(n~=-2))+2.*(1*(n==-
1))+(0*(n~=-1))+1.*(1*(n==0))+(0*(n~=0))
+1.*(1*(n==1))+(0*(n~=1))+0.*(1*(n==2))+(0*(n~=2));
subplot(2,2,1),stem(n,x1)
title('week3 home2')

b) n=-10:1:10;
x2=0.*(1*(2*n==-4))+(0*(2*n~=-4))+(-1).*(1*(2*n==-
3))+(0*(2*n~=-3))+0.*(1*(2*n==-2))+(0*(2*n~=-2))
+2.*(1*(2*n==-1))+(0*(2*n~=-1))+1.*(1*(2*n==0))
+(0*(2*n~=0))+1.*(1*(2*n==1))+(0*(2*n~=1))
+0.*(1*(2*n==2))+(0*(2*n~=2));
subplot(2,2,2),stem(n,x2)
title('week3 home2a')

c) n=-10:1:10;
x3=0.*(1*((3*n-1)==-4))+(0*((3*n-1)~=-4))+(-
1).*(1*((3*n-1)==-3))+(0*((3*n-1)~=-3))+0.*(1*((3*n-
1)==-2))+(0*((3*n-1)~=-2))+2.*(1*((3*n-1)==-1))
+(0*((3*n-1)~=-1))+1.*(1*((3*n-1)==0))+(0*((3*n-
1)~=0))+1.*(1*((3*n-1)==1))+(0*((3*n-1)~=1))
+0.*(1*((3*n-1)==2))+(0*((3*n-1)~=2));
subplot(2,2,3),stem(n,x3)
title('week3 home2b')

d) n=-10:1:10;
x4=0.*(1*((3-n)==-4))+(0*((3-n)~=-4))+(-1).*(1*((3-
n)==-3))+(0*((3-n)~=-3))+0.*(1*((3-n)==-2))+(0*((3-
n)~=-2))+2.*(1*((3-n)==-1))+(0*((3-n)~=-1))+1.*(1*((3-
n)==0))+(0*((3-n)~=0))+1.*(1*((3-n)==1))+(0*((3-
n)~=1))+0.*(1*((3-n)==2))+(0*((3-n)~=2));
subplot(2,2,4),stem(n,x4)
title('week3 home2c')
Q3. Plot the function defined by
0 t<2
-4-2t -2<t<0
x(t) = -4+3t 0<t<4
16-2t 4<t<8
2 8<t
t =-20:0.01:20;
x1=0.*(t<-2)+(-4-2*t).*(-2<t & t<0)+(-4+3*t).*(0<t &
t<4)+(16-2*t).*(4<t & t<8)+2.*(t>8);
subplot(2,2,1),plot(t,x1)
title('week3 home3')

x2=3.*(0.*((t+1)<-2)+(-4-2*(t+1)).*(-2<(t+1) & (t+1)<0)+(-


4+3*(t+1)).*(0<(t+1) & (t+1)<4)+(16-2*(t+1)).*(4<(t+1) &
(t+1)<8)+2.*((t+1)>8));
subplot(2,2,2),plot(t,x2)
title('week3 home3')
x3=0.5.*(0.*(4*t<-2)+(-4-2*4*t).*(-2<4*t & 4*t<0)+(-
4+3*4*t).*(0<4*t & 4*t<4)+(16-2*4*t).*(4<4*t &
4*t<8)+2.*(4*t>8));
subplot(2,2,3),plot(t,x3)
title('week3 home3')

x4=-2.*(0.*((t-1)./2<-2)+(-4-2*(t-1)./2).*(-2<(t-1)./2 & (t-


1)./2<0)+(-4+3*(t-1)./2).*(0<(t-1)./2 & (t-1)./2<4)+(16-2*(t-
1)./2).*(4<(t-1)./2 & (t-1)/.2<8)+2.*((t-1)./2>8));
subplot(2,2,4),plot(t,x4)
title('week3 home3')

You might also like