Skip to main content

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('Without using cconv method, circular convolution is: ');

l1=length(x);

l2=length(h);

x=[x zeros(1,n-l1)];

h=[h zeros(1,n-l2)];

y=zeros(1,n);

for i=1:n

    for j=1:n

        k=mod(i-j,n);

        k=k+1;

        y(i)=y(i)+x(j)*h(k);

    end

end

disp(y);

%Calculating Circular Convolution using cconv() method

disp("By formula:");

Z=cconv(x,h,n);

disp(Z);

Output:

Enter the first sequence: [1 2 1 2]

Enter the second sequence: [4 3 2 1]

     1     2     1     2

     2     1     2     1

     1     2     1     2

     2     1     2     1


Circular Convolution by Matrix Method:

    14    16    14    16


Without using cconv method, circular convolution is: 

    14    16    14    16


By formula:

    14    16    14    16

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!

Narrate a story from your own life experience which reflects kindness to the self or kindness to others or kindness to the environment.

As Shakespeare quoted ‘ Beauty lives with kindness’, kindness is a noble act of gentleness to others, to environment or to one’s own self.   It gives inner happiness and makes one feel good about oneself. I did not know the gift of kindness until I experienced it myself. In my first year in college I went on a trip to Dehradun along with my family. We were heading towards Haridwar. On our way through the jungles of the Garhwal Himalayas amidst the lust green forest, we saw a young girl suddenly appear from behind the trees and jump in front of our car. Our driver stopped the car just on time. There I saw a girl of about ten years old whimpering. Her dress was torn, her hands and feet were bruised and she looked starved. We gave her some food and water and asked about her whereabouts. By now we could understand that she was blind. She told us that she lived in Chidderwala and that she was out with her brother to fetch some fire woods, when it started to rain and she slipped and fe...