Vous êtes sur la page 1sur 5

DSP LAB Expt no: Date:

LINEAR CONVOLUTION USING DFT


Aim
To implement linear convolution using DFT by, a) Overlap-add method. b) Overlap-save method.

Theory
Suppose an input sequence x(n) of long duration is to be processed with a system having impulse response of finite duration by convolving the two sequences. Because of the length of the input sequence , it would not be practical to store it all before performing linear convolution. Therefore, the input sequence must be divided into blocks. The successive blocks are processed separately one at a time and the results are combined later to yield the desired output sequence which is identical to the sequence obtained by linear convolution. Two methods that are commonly used for filtering the sectioned data and combining the results are the overlap-save method and the overlap-add method.

Procedure
1) Double click the MATLAB icon. MATLAB command window will be displayed. 2) Click file menu, click new, click .m files. Now the edit menu will be displayed. 3) Type in the program, save it in work folder with a file name with extension .m. 4) To run the program, click debug menu and run sub menu.

Dept of ECE, PAACET

Page no:

DSP LAB

Program
a) OVERLAP-ADD METHOD. clc; clear all; close all; x=input('Enter the input sequence x(n):'); N=length(x); h=input('Enter the impulse sequence h(n):'); M=length(h); L=input('Enter the length of each block:'); Nframes=ceil(N/L); Nc=N+M-1; k=1:1:Nc; xsig=[x zeros(1,M-1)]; y=zeros(1,Nc); for m = 0:(Nframes-1); index=(m*L+1):min((m+1)*L,N); xn = x(index); xzp=[xn zeros(1,M-1)]; Np=length(xn)+(M-1); hzp=[h zeros(1,Np-M)]; H=fft(hzp,Np);H X=fft(xzp,Np);X Ym=X.*H;Ym ym=ifft(Ym,Np); ym=[zeros(1,m*L) ym]; ym=[ym zeros(1,min(N-(m+1)*L,(Nc-length(ym))))]; y=y+ym; end; b=0:1:N+M-2; subplot(311); Dept of ECE, PAACET Page no:

DSP LAB stem(x); title('LONG INPUT SEQUENCE'); ylabel('Amplitude_A'); xlabel('n'); subplot(312); stem(h); ylabel('Amplitude_A'); xlabel('n'); title('IMPULSE SEQUENCE'); subplot(313); disp(y); stem(b,y); title('Plot of Overlap Add'); ylabel('y'); xlabel('n');

b) OVERLAP-SAVE METHOD. clc; clear all; close all; x=input('Enter the input sequence x(n):'); h=input('Enter the impulse sequence x(n):'); N=input('Enter the length of each block:'); Lenx = length(x); M = length(h); if(N<M) error('LENGTH OF BLOCK SHOULD BE GREATER THAN "M"'); end M1 = M-1; L = N-M1; h1 = [h zeros(1,N-M)];

Dept of ECE, PAACET

Page no:

DSP LAB x1 = [zeros(1,M1), x, zeros(1,N-1)]; K = floor((Lenx+M1-1)/(L)); Y = zeros(K+1,N); for k=0:K xk = x1(k*L+1:k*L+N); H=fft(h1,N); X=fft(xk,N); Ym=X.*H; Y(k+1,:) = ifft(Ym,N); end Y = Y(:,M:N)'; y = (Y(:))'; subplot(311); stem(x); title('LONG INPUT SEQUENCE'); ylabel('Amplitude_A'); xlabel('n'); subplot(312); stem(h); ylabel('Amplitude_A'); xlabel('n'); title('IMPULSE SEQUENCE'); subplot(313); ylabel('y'); xlabel('n'); stem(y); title('Plot of Overlap save'); disp(y);

Dept of ECE, PAACET

Page no:

DSP LAB

Result
Implemented linear convolution using DFT by overlap-save method and overlapadd method using MATLAB.

Dept of ECE, PAACET

Page no:

Vous aimerez peut-être aussi