# Kathmandu University

Communication Laboratory
DSP_LAB 2: Filtering using DFT

Shravan Kumar Luitel (32015) 4/12/2011

Exercise 3 Code: % Creating a sinusoidal sequence x of frequency (2*pi/3) and 50 samples n=1:50; x=sin(2*pi*(2*pi/3)*n); subplot(311); stem(x); title('sinusoidal sequence x of frequency (2*pi/3)'); xlabel('samples'); ylabel('x[n]'); subplot(312); stem(Num); title('Impulse response of a filter from fdatool exported as a vector(Num) in workspace'); xlabel('samples'); ylabel('Num'); % Filtering the input sequence x by the filter using function conv y=conv(Num,x); subplot(313); stem(y); title('Output sequence y obtained using function conv'); xlabel('samples'); ylabel('y[n]'); Figure:

Exercise 4a Code: % Creating a sinusoidal sequence x of frequency (2*pi/3) and 50 samples n=1:50; x=sin(2*pi*(2*pi/3)*n); subplot(311); stem(x); title('Sinusoidal sequence x of frequency (2*pi/3)'); xlabel('samples');

ylabel('x[n]'); subplot(312); stem(Num); title('Impulse response of a filter from FDATOOL exported as a vector(Num) in workspace'); xlabel('samples'); ylabel('Num'); % Filtering the input sequence x by the filter using inbuilt function FFT % and IFFT l=length(x)+length(Num)-1; X=fft(x,l); Num1=fft(Num,l); Y=X.*Num1; y=ifft(Y); subplot(313); stem(y); title('Output sequence y obtained using inbuilt function FFT and IFFT'); xlabel('samples'); ylabel('y[n]'); Figure:

Exercise 4b Code: % Creating a sinusoidal sequence x of frequency (2*pi/3) and 50 samples n=1:50; x=sin(2*pi*(2*pi/3)*n); subplot(311); stem(x); title('Sinusoidal sequence x of frequency (2*pi/3)'); xlabel('samples'); ylabel('x[n]'); subplot(312); stem(Num);

title('Impulse response of a filter from FDATOOL exported as a vector(Num) in workspace'); xlabel('samples'); ylabel('Num'); % Filtering the input sequence x by the filter using Wn Matrix % and IFFT l=length(x)+length(Num)-1; x=[x zeros(1,l-length(x))]; Num=[Num zeros(1,l-length(Num))]; j=0; while j<l k=0; while k<l Wn(j+1,k+1)=exp(-i*2*pi/l*j*k); k=k+1; end j=j+1; end X=x*Wn; Num1=Num*Wn; Y=X.*Num1; y=ifft(Y); subplot(313); stem(real(y)); title('Output sequence y obtained using Wn Matrix and IFFT'); xlabel('samples'); ylabel('y[n]'); Figure: