Performing convolution in MATLAB is pretty simple.
Below we have provided some codes, along with the output. Copy paste the code into your MATLAB editor file and press ‘run’ . The program should generate the picture given with each code.
Before you dive in, consider learning MATLAB commands in detail: MATLAB commands
Lab Report for Convolution – Signals & Systems
1. MATLAB Code
h =[4 -2 -1 3 -2 -6 -5 4 5];
x=[-4 1 3 7 4 -2 -8 -2 -1];
c=conv(h,x);
m=length(c)-1;
n=0:1:m;
stem(n,c)
xlabel(‘Time’)
ylabel(‘Amplitude’)
2. MATLAB Code
x=input(‘enter first sequence’)
h=input(‘enter second sequence’) m=length(c)-1;
n=0:1:m;
stem(n,c)
xlabel(‘Time’)
ylabel(‘Amplitude’)
3. MATLAB Code
x=[-4 1 3 7 4 -2 -8 -2 -1]
h=[4 2 -1 3 -2 6 -5 4 5]
a=1
b=h
y=filter(b,a,x)
m=length(y)-1;
n=0:1:m;
c=conv(h,x);
z=length(c)-1
d=0:1:z;
subplot(211)
stem(d,c)
subplot(212)
stem(n,y)
xlabel(‘Time’)
ylabel(‘Amplitude’)
title(‘fiter of h and x’)
3. MATLAB Code
m=input(‘enter no of filter taps’)
n=0:100;
f=0.05;
a=4
x=a*sin(2*pi*f*n);
figure
subplot(221)
stem(n,x)
xlabel(‘sinewave’)
axis([0 100 -4 4])
grid
y1=wgn(1,101,2);
y2=y1+x;
subplot(222)
stem(n,y2)
xlabel(‘sine+noise’)
axis([0 100 -6 6])
grid
b=ones(1,m)/m;
subplot(223)
stem([0:m-1],b)
xlabel(‘IR of moving average filter’)
grid
g=conv(b,y2);
T=length(g);
subplot(224)
stem([0:T-1],g)
xlabel(‘convolution output’)
axis([0 100 -4.5 4.5])
grid
Leave a Reply