Linear Convolution

Aim: To find the out put with linear convolution operation Using MATLAB Software.

EQUIPMENTS:

PC with windows (95/98/XP/NT/2000).

MATLAB Software

Theory:

System

If x(n)=h(n) [ impulse ) then output y(n) is known as impulse response of the system.

x(n)=d(n)


y(n)=T[x(n)]=h(n) similarly d (n-k)= h(n-k)

x(n) cab represented as weighted sum of impulses such as

y(n)=T[x(n)]   ,the given below v[n] equations are equal

d (n-k)= h(n-k)

Linear convolution equation

Linear Convolution involves the following operations.

  • Folding
  • Multiplication
  • Addition
  • Shifting

These operations can be represented by a Mathematical Expression as follows:

x[ ]= Input signal Samples

h[ ]= Impulse response co-efficient.

y[ ]= Convolution output.

n = No. of Input samples

h = No. of Impulse response co-efficient.

Example : X(n)={1 2 -1 0 1}, h(n)={ 1,2,3,-1}

Program-1:

Program: Using in-built function-CONV

clc;
close all;
clear all;
x=input('enter input sequence');
h=input('enter impulse response');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');ylabel('x(n)');
title('input signal')
subplot(3,1,2);
stem(h);
xlabel('n');ylabel('h(n)');
title('impulse response')
subplot(3,1,3);
stem(y);
xlabel('n');ylabel('y(n)');
title('linear convolution')
disp('The resultant signal is');
disp(y)


 

Output:  linear convolution 

enter input sequence[1 4 3 2]

enter impulse response[1 0 2 1]

The resultant signal is     1  4  5  11  10  7  2

Convoluted signal

Program-2: Convolution of  two sequences:

clc;
clear all;
close all;
x=input('Enter the  sequence x(n)')
n1=input('Enter the time indices of x(n)')
y=input('Enter the sequence y(n)')
n2=input('Enter the time indices of y(n)')
n=min(n1)+min(n2):max(n1)+max(n2);
A=zeros(min(length(x),length(y)),length(x)+length(y)-1);
if length(x)<length(y)
   for i=1:length(x)
       A(i,i:i+length(y)-1)=y(1,:);
       A(i,:)=x(i).*A(i,:);
   end
else
   for i=1:length(y)
       A(i,i:i+length(x)-1)=x(1,:);
       A(i,:)=y(i).*A(i,:);
   end
end
c=zeros(1,length(x)+length(y)-1);
for i=1:min(length(x),length(y))
   c(1,:)=c(1,:)+A(i,:);
end
disp('The convolution of the given sequences is')
disp(c)
disp('The Time index of the convolved sum is')
disp(n)
subplot(3,1,1)
stem(n1,x)
xlabel('time')
ylabel('amplitude')
title('Given sequence x(n)')
grid
subplot(3,1,2)
stem(n2,y)
xlabel('time')
ylabel('amplitude')
title('Given sequence y(n)')
grid
subplot(3,1,3)
stem(n,c)
title('Convolution of x(n) and y(n)')
xlabel('time')
ylabel('amplitude')
grid

Output:

Enter the  sequence x(n)[3 4 6 1]

x =

    3     4     6     1

Enter the time indices of x(n)[0 1 2 3]

n1 =

    0     1     2     3

Enter the sequence y(n)[2 5 2 9]

y =

    2     5     2     9

Enter the time indices of y(n)[0 1 2 3]

n2 =

    0     1     2     3

The convolution of the given sequences is

    6    23    38    67    53    56     9

The Time index of the convoluted sum is

    0     1     2     3     4     5     6

convolution of two sequences

Program-3: Convolution of two signals:

f1=input('enter the sampling frequency of the first signal')
T1=1/f1;
t1=0:T1/f1:T1;
x1=zeros(1,length(t1));
j=input('enter the duration of the rectangular pulse in terms of  number of samples to included')
x1(1:j)=0.25;
f2=input('enter the sampling frequency of the second signal')
T2=1/f2;
t2=0:T2/f2:T2;
x2=zeros(1,length(t2));
k=input('enter the duration of the rectangular pulse in terms of  number of samples to included ')  
x2(1:k)=0.5;
t=0:(t1(j)+t2(k))/(j+k):t1(j)+t2(k);
A=zeros(min(j,k),j+k-1);
if j<k
   for i=1:j
       A(i,i:i+k-1)=x2(1,1:k);
       A(i,:)=x1(i).*A(i,:);
   end
else
   for i=1:k
       A(i,i:i+j-1)=x1(1,1:j);
       A(i,:)=x2(i).*A(i,:);
   end
end
c=zeros(1,j+k-1);
for i=1:min(j,k)
   c(1,:)=c(1,:)+A(i,:);
end
c(j+k)=0;
for i=length(c)+1:length(t)
   c(i)=0;
end
subplot(3,1,1)
plot(t1,x1)
xlabel('time')
ylabel('amplitude')
grid
title('Rectangular Pulse')
subplot(3,1,2)
plot(t2,x2)
xlabel('time')
ylabel('amplitude')
grid
title('Rectangular Pulse')
subplot(3,1,3)
plot(t,c)
xlabel('time')
ylabel('amplitude')
grid
title('Convolution of rectangular pulses of same duration')

% Convolution between two rectangular Pulses of  equal duration

enter the sampling frequency of the first signal1000

f1 =1000

enter the duration of the rectangular pulse in terms of  number of samples to included750

j =750

enter the sampling frequency of the second signal1000

f2 = 1000

enter the duration of the rectangular pulse in terms of  number of samples to included 750

k = 750

% Convolution between two rectangular Pulses of   Unequal duration

enter the sampling frequency of the first signal1000

f1 = 1000

enter the duration of the rectangular pulse in terms of  number of samples to included750

j = 750

enter the sampling frequency of the second signal1000

f2 =1000

enter the duration of the rectangular pulse in terms of  number of samples to included 500

k =500

Result: In this experiment convolution of various signals have been performed Using MATLAB.

Applications:Convolution is used to obtain the response of an LTI system to an arbitrary input signal.It is used to find the filter response and finds application in speech processing and radar signal processing.