Skip to main content

DFT Circular Convolution by Overlap Add Method in Matlab

 

Matlab Code:

     clc;

close all;

x=input('Enter the input sequence: ');

h=input('Enter the impulse sequence: ');

n=length(x);

m=length(h);

z=1;

for i=1:4

    if i~=4

        for j=1:m

            X(i,j)=x(((i-1)*m)+1+(j-1));

        end

        for j=m+1:5

            X(i,j)=0;

        end

    else

        for j=1:5

            if j==1

                X(i,j)=x(n);

            else

                X(i,j)=0;

            end

        end

    end

end

disp('Subsets of sequense: ');

disp(X);

 

y1=cconv(X(1,1:5),h,5);

y2=cconv(X(2,1:5),h,5);

y3=cconv(X(3,1:5),h,5);

y4=cconv(X(4,1:5),h,5);

 

Y=[y1(1:m),y1(m+1:end)+y2(1:m-1),y2(m),y2(m+1:end)+y3(1:m-1),y3(m),y3(m+1:end)+y4(1:m-1),y4(m:end)];

Y=Y(1:n+m-1); 

disp('By Overlap Add Method: ');

disp(Y);


Output:

Enter the input sequence: [3 -1 0 1 3 2 0 1 2 1]

Enter the impulse sequence: [1 1 1]

Subsets of sequence:

     3    -1     0     0     0

     1     3     2     0     0

     0     1     2     0     0

     1     0     0     0     0

 

By Overlap Add Method:

    3.0000    2.0000    2.0000    0.0000    4.0000    6.0000    5.0000    3.0000    3.0000    4.0000    3.0000    1.0000

Comments

Popular posts from this blog

PN Sequence Generator Circuit Design in Multisim

 I tried doing a PN Sequence generator using a shift register in Multisim but it didn't work. However this one with d flip flops and xor gate did work somewhat. Here is the circuit.       Components Required:      1. 4D Flip Flops      2. XOR Gate      3. Function Generator for Clock Pulses      4. Oscilloscope       Circuit Design  :        Output:- Red Square waves- Clock Pulses Blue waves- PN sequence Hope this helps!

Matlab Code for Circular Convolution using Matrix Method and also not using cconv method

Matlab Code:   clc; clear all; close all; %Circular Convolution by Matrix Method x=input('Enter the first sequence: '); h=input('Enter the second sequence: '); n=max(length(h),length(x)); A=0; %To obtain a circular matrix for i=1:n     if i==1         for j=1:n             A(i,j)=x(j); %first row stores all the elements of x(n)         end     else     for j=1:n         if(j==1)             A(i,j)=x(n-i+2); %first column of rows from i=2 to n are x(n),                                                                                x(n-i+2),...,x(3),x(2)         else             A(i,j)=A(i-1,j-1); % the last (n-1) elements of present row is the                                                      fist (n-1) elements of the previous row          end     end     end end disp(A); X=A*h';  %To calculate matrix multiplication disp("Circular Convolution by Matrix Method:"); disp(X'); %Calculating Circular Convolution with out using cconv function disp('Wit

Convolution of two signals using conv() in Matlab

We use the conv(x1,x2) function in Matlab to perform convolution of two discrete signals. For example, to perform the convolution of two discrete time sequences x1 (n) = {1, 0, 1,2}  and x2 (n) = {1, 2, 4, 6}. Code:  x1=[1,0,1,2]; %1st sequence N1=length(x1); %stores length of 1st sequence n1=0:1:N1-1; %range of x axis for 1st graph of 1st sequence subplot(1,3,1); % in a 1x3 grid, 1st sequence occupies the 1st grid stem(n1,x1,'linewidth',1.5); %to plot the sequence specifying time axis, signal and line width xlabel('n1----->'); %title of x axis ylabel('x1----->'); %title of y axis grid on; x2=[1,2,4,6]; %2nd sequence N2=length(x2);    %stores length of 2nd sequence n2=0:1:N2-1;  %range of x axis for 2nd graph of 2nd sequence subplot(1,3,2);  % in a 1x3 grid, 2nd sequence occupies the 2nd grid stem(n2,x2,'red','linewidth',1.5);  %to plot the sequence specifying time axis,signal,line width and colour xlabel('n2----->'); % title of