0% found this document useful (0 votes)
6 views

%program For Convolution of Two Sequences X (N) and H (N)

This document contains MATLAB code to perform various signal processing tasks including: 1) Convolving two sequences using the conv function 2) Generating unit step, sinusoidal, and exponential sequences 3) Adding two sinusoidal sequences 4) Finding the z-transform of functions using the ztrans function 5) Converting analog filters to digital filters using the bilinear and impulse invariant transformations

Uploaded by

sujitwaghamare2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

%program For Convolution of Two Sequences X (N) and H (N)

This document contains MATLAB code to perform various signal processing tasks including: 1) Convolving two sequences using the conv function 2) Generating unit step, sinusoidal, and exponential sequences 3) Adding two sinusoidal sequences 4) Finding the z-transform of functions using the ztrans function 5) Converting analog filters to digital filters using the bilinear and impulse invariant transformations

Uploaded by

sujitwaghamare2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

%Program for convolution of two sequences x (n) and h (n)

clear all
x=[1,0,1,2,-1,3,2];
N1=length(x);
n=0:1:N1-1;
subplot(2,2,1),stem(n,x);
xlabel('n'),ylabel('x(n)');
h=[1,1,2,2,1,1];
N2=length(h);
n=0:1:N2-1;
subplot(2,2,2);stem(n,h);
xlabel('n'),ylabel('h(n)');
y=conv(x,h)
n2=0:1:N1+N2-2;
subplot(2,1,2),stem(n2,y);
xlabel('n'),ylabel('y(n)');
title('convolution of two sequences x(n)and h(n)');
OUTPUT:

3 2

2 1.5

h(n)
x(n)

1 1

0 0.5

-1 0
0 2 4 6 0 2 4 6
n n
convolution of two sequences x(n)and h(n)
15

10
y(n)

0
0 2 4 6 8 10 12
n
%To Generate a Unit Step Sequence
N=21;
x=ones(1,N);
n=0:1:(N-1);
subplot(2,2,1),stem(n,x);
xlabel('n'),ylabel('x(n)');
title('Unit step sequence')

%To Generate a Sinusoidal Sequence


x1=cos(0.2*pi*n);
subplot(2,2,2),stem(n,x1);
xlabel('n'),ylabel('x1(n)');
title('Sinusoidal sequence')

%To Generate Exponential Sequence


x2=0.8.^(n);
subplot(2,2,3),stem(n,x2);
xlabel('n'),ylabel('x2(n)');
title('Exponential sequence')

%Addition of Two Sinusoidal Sequences


x3=sin(0.1*pi*n)+sin(0.2*pi*n);
subplot(2,2,4),stem(n,x3);
xlabel('n'),ylabel('x3(n)');
title('Addition of two sinusoidal sequences')
OUTPUT :

Unit step sequence Sinusoidal sequence


1 1

0.5

x1(n)
x(n)

0.5 0

-0.5

0 -1
0 5 10 15 20 0 5 10 15 20
n n
Exponential sequence Addition of two sinusoidal sequences
1 2

1
x2(n)

x3(n)

0.5 0

-1

0 -2
0 5 10 15 20 0 5 10 15 20
n n
%Program to find Z-Transform of the Function

syms n;
X=n^2;
ztrans(X)
syms a,n;
y=a^n;
ztrans(y)
syms a,n;
X1=sin(a*n)
ztrans(X1)
syms a,n;
X2=cos(a*n)
ztrans(X2)
OUTPUT:

ans =(z^2 + z)/(z - 1)^3


ans =-z/(a - z)
X1 =sin(a*n)
ans =(z*sin(a))/(z^2 - 2*cos(a)*z + 1)
X2 =cos(a*n)
ans =(z*(z - cos(a)))/(z^2 - 2*cos(a)*z + 1)
%Program to Convert Analog Filter into Digital Filter Using
Bilinear Transformation

clear all
b=[2];
a=[1 3 2];
f=1;
[bz,az]=bilinear(b,a,f)
OUTPUT:

bz =0.1667 0.3333 0.1667

az =1.0000 -0.3333 0.0000


%Program to Convert Analog Filter into Digital Filter Using
Impulse Invariant Transformation
clear all

b=[1 2];

a=[1 5 11 15];

f=5;

[bz,az]=impinvar(b,a,f)
OUTPUT :
bz =-0.0000 0.0290 -0.0195

az =1.0000 -2.0570 1.4980 -0.3679

You might also like