Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Linear and Circular Convolution in MATLAB

Status
Not open for further replies.

joshhtfld

Newbie level 3
Joined
Dec 4, 2011
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
I have tried a couple ways and am not truthfully understanding what I am doing. I need to compute the linear and circular convolution (FFT 128 point) of

x1[n]=(0.9)^n*(u[n]-u[n-100]);
x2[n]=u[n]-u[n-7];

please explain, I really like to understand what I am doing and the reasoning behind it

Thanks
 

linear convolution and circular convolution can be easily calculated in matlab and other math packages
similarly FFT and IFFT .




convolution of two Sequences in time domain is Equal to multiplication of their Fourier transform

Generally in the case of filtering
The input signal is transformed into the frequency domain using the DFT{We use FFT for faster calculation }, multiplied by the frequency response of the filter, and then transformed back into the time domain using the Inverse DFT{IFFT}.
By using the FFT algorithm to calculate the DFT, convolution via the frequency domain can be faster . The final result is the same; only fewer no of number calculations . so ,the FFT convolution is also called high-speed convolution.


so here suppose \[X_1[n]\] is the filter input and\[{ X_2[n]}\] is the impulse response of a filter ,so
take the fft of the input signal and impulse response multiply ,then take ifft to transform result to time domain

a detailed discussion
h**p://www.dspguide.com/ch18/2.htm
 

so I tried what you recommended and I am getting a error due to Matrix not being squared. So I am obviously doing something wrong

r=n;
x1_n=(0.9)^n*[u(n)-u(n-100)];
x2_n=u(n)-u(n-7);
X1_r=fft(x1_n);
X2_r=fft(x2_n);
Y1_r=X1_r*X2_r;
y1_n=ifft(Y1_r);
stem(r,Y1_r,'k');
figure;
stem(n,y1_n,'k');
figure;

and what is the main difference in calculating the linear vs. circular in Matlab?
 

Sorry to keep posting here but I am having issues with what I am doing still, I am not efficient with Matlab yet and like to understand your code but here is what the actual problem statement is

project3.gif




I do not want you to do the assignment for me but am stuck and would like some help if possible with steps to take in completing the code
 

so I tried what you recommended and I am getting a error due to Matrix not being squared. So I am obviously doing something wrong

r=n;
x1_n=(0.9)^n*[u(n)-u(n-100)];
x2_n=u(n)-u(n-7);
X1_r=fft(x1_n);
X2_r=fft(x2_n);
Y1_r=X1_r*X2_r;
y1_n=ifft(Y1_r);
stem(r,Y1_r,'k');
figure;
stem(n,y1_n,'k');
figure;

and what is the main difference in calculating the linear vs. circular in Matlab?

If the x and y are differ in size then zero pad the smaller sequence so that have equal
length


Code:
%blooz Communication 

clc;
x=[ 1 2 3 4 5 6];
y=[ 7 8 9];

if (size(x,2)==size(y,2))
    
    result=real(ifft(fft(x).*fft(y)))
    subplot(2,1,1)
    stem(result);grid on;xlabel('n') ;ylabel('X(n)');title('Circular convolution of X and Y using FFT ')
    
    subplot(2,1,2)
    stem(cconv(x,y));grid on;
    xlabel('n') ;ylabel('X(n)');title('Circular convolution of X and Y using cconv')
elseif (size(x,2)-size(y,2)>0)
    
    k=size(x,2)-size(y,2);
    y=[y,zeros(1,k)];
    result=real(ifft(fft(x).*fft(y)))
    subplot(2,1,1)
    stem(result);grid on;xlabel('n') ;ylabel('X(n)');title('Circular convolution of X and Y using FFT ')
    
    subplot(2,1,2)
    stem(cconv(x,y));grid on;
    xlabel('n') ;ylabel('X(n)');title('Circular convolution of X and Y using cconv')
  
else
    
    k=size(y,2)-size(x,2);
    x=[x,zeros(1,k)];
    result=real(ifft(fft(x).*fft(y)))
    
    subplot(2,1,1)
    stem(result);grid on;xlabel('n') ;ylabel('X(n)');title('Circular convolution of X and Y using FFT ')
    
    subplot(2,1,2)
    stem(cconv(x,y));grid on;
    xlabel('n') ;ylabel('X(n)');title('Circular convolution of X and Y using cconv')
end


---------- Post added at 09:57 ---------- Previous post was at 09:56 ----------

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top