0% found this document useful (0 votes)
47 views16 pages

Unit Impulse: Output

The document contains MATLAB code for generating and plotting various signal processing sequences including the unit impulse, unit step, unit ramp, real and complex exponentials, convolution, z-transform, and discrete Fourier transform. Functions are provided to generate these standard sequences and perform operations like shifting, convolution, z-transform, and inverse z-transform. Examples are given of applying the functions to signals and plotting the results.

Uploaded by

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

Unit Impulse: Output

The document contains MATLAB code for generating and plotting various signal processing sequences including the unit impulse, unit step, unit ramp, real and complex exponentials, convolution, z-transform, and discrete Fourier transform. Functions are provided to generate these standard sequences and perform operations like shifting, convolution, z-transform, and inverse z-transform. Examples are given of applying the functions to signals and plotting the results.

Uploaded by

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

RISHI

UNIT IMPULSE
function [x,n]=impulse(n0,n1,n2)
n=[n1:n2];
x=[(n-n0)==0];
stem(n,x);
xlabel('n');ylabel('del[n]');
end
OUTPUT:

impulse(0,-10,10)

UNIT STEP
function [x,n]=unitstep(n0,n1,n2)
n=[n1:n2];
x=[(n-n0)>=0];
stem(n,x);
xlabel('n');ylabel('u[n]');
end
OUTPUT:

unitstep(0,-10,10)

1
RISHI

UNIT RAMP
function [x,n]=ramp(n0,n1,n2)
n=[n1:n2];
x=(n-n0).*[(n-n0)>=0];
stem(n,x);
xlabel('n');ylabel('r[n]');
end
OUTPUT:

ramp(0,-10,10)

2
RISHI
REAL EXPONENTIAL
function [x,n]=realexp(n0,n1,n2)
n=[n1:n2];
subplot(2,2,1)
x=2.^n;
stem(n,x);
title('a>1')
xlabel('n');ylabel('y[n]');
subplot(2,2,2)
x=0.5.^n;
stem(n,x);
title('0>a>1')
xlabel('n');ylabel('y[n]');
subplot(2,2,3)
x=(-0.5).^n;
stem(n,x);
title('-1<a<0')
xlabel('n');ylabel('y[n]');
subplot(2,2,4)
x=(-2).^n;
stem(n,x);
title('a<-1')
xlabel('n');ylabel('y[n]');
end
OUTPUT:

COMPLEX EXPONENTIAL
function [x,n]=complexexp(n0,n1,n2)
n=[n1:n2];
3
RISHI
x=exp((-0.1+(j*0.3)).*n);
subplot(2,2,1)
x1=real(x);
stem(n,x1);
title('REAL PART');
subplot(2,2,2)
x2=imag(x);
stem(n,x2);
title('IMAGINARY PART');
subplot(2,2,3)
x3=abs(x);
stem(n,x3);
title('MAGNITUDE');
subplot(2,2,4)
x4=(180/pi)*angle(x);
stem(n,x4);
title('PHASE');
end
OUTPUT:

complexexp(0,-10,10)

%GENERATE AND PLOT SEQUENCES OVER AN INTERVAL


%2del(n+2)-del(n-4)
function[x,n]=sig(n1,n2)
n=[n1:n2];

4
RISHI
x=2*(impulse(-2,n1,n2))-impulse(4,n1,n2)
stem(n,x);
end
OUTPUT:

%GENERATE AND PLOT


SEQUENCES OVER AN
INTERVAL
%n[u(n)-u(n-
10)]+10exp(-0.3)[u(n-
10)-u(n-20)]
function[x,n]=sig1(n1
,n2)
n=[n1:n2];
x=n.*(unitstep(0,n1,n
2)-
unitstep(10,n1,n2))+(
10*exp(-
0.3))*(unitstep(10,n1
,n2)-
unitstep(20,n1,n2));
stem(n,x);
end
OUTPUT:

%GENERATE AND PLOT SEQUENCES OVER AN INTERVAL


%x(n)={1,2,3,4,5,6,7,6,5,4,3,2,1}
(a)x1(n)=2x(n-5)-3x(n+4)
function[x,n]=sig2(n2,n3)
n=[n2:n3];
x=[1,2,3,4,5,6,7,6,5,4,3,2,1]
[x1,n1]=(sigshift(x,[n2:n3],5))
[x2,n2]=(sigshift(x,[n2:n3],-4))
n = min(min(n1),min(n2)):max(max(n1),max(n2));%duration of y[n]
y1=zeros(1,length(n));
y2=y1;
5
RISHI
y1(find((n>=min(n1))&(n<=max(n1))==1))= x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))= x2;
y = (2*y1)-(3*y2);
stem(n,y);
end
OUTPUT:

sig2(-2,10)

%GENERATE AND PLOT SEQUENCES OVER AN INTERVAL


%x(n)={1,2,3,4,5,6,7,6,5,4,3,2,1}
%x(3-n)+x(n)x(n-2)
function[x,n]=sig3(n2,n3)
n=[n2:n3];
n1=-fliplr(n)
x=[1,2,3,4,5,6,7,6,5,4,3,2,1]
[x1,n1]=(sigshift(x,n1,3))

[x2,n2]=(sigshift(x,[n2:n3],2))
n = min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n));
y2=y1;
y3=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))= x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))= x2;
y3(find((n>=min(n1))&(n<=max(n1))==1))= x;

6
RISHI
y = (y1)+(y3.*y2);

stem(n,y);
end
OUTPUT:
sig3(-2,10)

OR

7
RISHI

Z TRANSFORM

(i)X[n]=(1/4)^n u[n]
syms z n
ztrans((1/4)^n)
OUTPUT:
z/(z - 1/4)

(ii)
syms z n
ztrans(exp(-2*n))
OUTPUT:
z/(z - exp(-2))

Inverse Z transform
% X[z]=z/(z - 1/4)
syms z n
iztrans(z/(z - 1/4))
OUTPUT:

(1/4)^n

PROGRAM:

%Let X1(z)=z 2 3 z^-1 and X2(z)=2z^2+4z+3+5z^-1

%Determine X3(z)=X1(z)X2(z)

x1=[1,2,3];
8
RISHI
n1=[-1:1];
x2=[2,4,3,5];
n2=[-2:1];
[x3,n3]=conv_mod(x1,n1,x2,n2)

OUTPUT:

x3 =2 8 17 23 19 15

n3 =-3 -2 -1 0 1 2

RESIDUEZ

1)1/((1+z^-1)*(1-z^-1)^2)

b=[1];
a=[1,-1,-1,1];
[R,p,C]=residuez(b,a)
[b,a]=residuez(R,p,C)
zplane(b,a)

OUTPUT:

R=

0.2500
9
RISHI
0.5000

0.2500

p=

1.0000

1.0000

-1.0000

C = []

b = 1.0000 0 0.0000

a =1.0000 -1.0000 -1.0000 1.0000

2)(3-4z^-1)/((1-0.5z^-1)^2*(1-3z^-1))

b=[3,-4];
a=[1,-4,13/4,(-3)/4];
[R,p,C]=residuez(b,a)
[b,a]=residuez(R,p,C)
zplane(b,a)
OUTPUT:

R =2.4000 + 0.0000i

10
RISHI
-0.4000 - 0.0000i

1.0000 + 0.0000i

p=

3.0000 + 0.0000i

0.5000 + 0.0000i

0.5000 - 0.0000i

C =[]

b = 3.0000 - 0.0000i -4.0000 + 0.0000i 0.0000 - 0.0000i

a =1.0000 -4.0000 3.2500 -0.7500

3)(1+z^-1)/((1-0.5z^-1)^2)(1-z^-1))
b=[1,1];
a=[1,-2,5/4,(-1)/4];
[R,p,C]=residuez(b,a)
[b,a]=residuez(R,p,C)
zplane(b,a)
R=

8.0000 + 0.0000i

-4.0000 - 0.0000i
11
RISHI
-3.0000 + 0.0000i

p=

1.0000 + 0.0000i

0.5000 + 0.0000i

0.5000 - 0.0000i

C = []

b=

1.0000 - 0.0000i 1.0000 + 0.0000i 0.0000 - 0.0000i

a=

1.0000 -2.0000 1.2500 -0.2500

4) (3-4z^-1)/(1-3.5z^-1+1.5z^-2)

b=[3,-4];
a=[1,-3.5,1.5];
[R,p,C]=residuez(b,a)
[b,a]=residuez(R,p,C)
zplane(b,a)
12
RISHI
R=

p=

3.0000

0.5000

C =[]

b=

3 -4

a =1.0000 -3.5000 1.5000

DTFT OF x[n]={1,2,3,4,5}

x=[1,1,1,1];
n=0:3;
N=4;
X=dft(x,N);
magX=abs(X)
angX=angle(X)*180/pi

13
RISHI
subplot(2,1,1)
stem(n,magX);
title('MAGNITUDE PLOT')
xlabel('w')
ylabel('magX')
subplot(2,1,2)
stem(n,angX);
title('ANGLE PLOT')
xlabel('w')
ylabel('angX')

OUTPUT:

Find DTFT

x=[1,1,1,1];
n=0:3;
N=4;
k=0:500;
w=(2*pi/500)*k;
X=x*(exp(-j*2*pi/500)).^(n'*k);
magX=abs(X)
angX=angle(X)*180/pi
subplot(2,1,1)
plot(w,magX);
title('MAGNITUDE PLOT')
xlabel('w')

14
RISHI
ylabel('magX')
subplot(2,1,2)
plot(w,angX);
title('ANGLE PLOT')
xlabel('w')
ylabel('angX')

FIND 4 PT. DFT

x=[1,1,1,1];
n=0:3;
N=4;
X=dft(x,N);
magX=abs(X)
angX=angle(X)*180/pi
subplot(2,1,1)
stem(n,magX);
title('MAGNITUDE PLOT')
xlabel('w')
ylabel('magX')
subplot(2,1,2)
stem(n,angX);
title('ANGLE PLOT')
xlabel('w')
ylabel('angX')

15
RISHI

16

You might also like