Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

PROGRAM:

%Program to perform circular convolution using fft/ifft


clc
clear all
close all

disp('This is the program to perform circular convolution using fft/ifft');


fprintf('\n');
%Getting the inputs from user
x = input('Enter the first sequence :');
h = input('Enter the second sequence :');

%To perform circular convolution, x and h should be of same size.


%Find the length of x and length of h. Find the maximum value.

len_x = length(x);
len_h = length(h);
len_y = max(len_x,len_h);

%Use fft and ifft to compute the output.Specify the fft length as the
%maximum of the lengths of x and h.
%Method to compute circular convolution
%x -> fft -> X ;
%h -> fft -> H ;
%Y = X.*H ;
%Y -> inverse fft -> y. .Display the output
x_fft = fft(x,len_y);
h_fft = fft(h,len_y);
y_fft = x_fft .* h_fft;
y = ifft(y_fft,len_y);
disp('The circular convolution output is :');
disp(y);

%Plotting the first sequence, second sequence and output


figure(1);
subplot(3,1,1);
%We need to plot the values from n = 0 till length - 1.
ax = 0:1:length(x)-1;
stem(ax,x);
xlabel('samples n->');
ylabel('amplitude');
title('first input sequence x(n)');
subplot(3,1,2);
ah = 0:1:length(h)-1;
stem(ah,h);
xlabel('samples n->');
ylabel('amplitude');
title('second input sequence h(n)');

subplot(3,1,3);
ay = 0:1:length(y)-1;
stem(ay,y);
xlabel('samples n->');
ylabel('amplitude');
title('circular convolution output y(n)');

OUTPUT:
This is the program to perform circular convolution using fft/ifft
Enter the first sequence :[1 2 3]
Enter the second sequence :[1 2 3 4]
The circular convolution output is :
18 16 10 16

You might also like