0% found this document useful (0 votes)
858 views

Communication Laboratory: Shravan Kumar Luitel (32015)

This document contains code and figures related to filtering a sinusoidal sequence using the discrete Fourier transform (DFT) and fast Fourier transform (FFT). It shows code for filtering a signal using convolution, the FFT and IFFT, and using a DFT matrix and IFFT. The code generates a sinusoidal input signal, filters it using different methods, and plots the input, filter, and output signals.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
858 views

Communication Laboratory: Shravan Kumar Luitel (32015)

This document contains code and figures related to filtering a sinusoidal sequence using the discrete Fourier transform (DFT) and fast Fourier transform (FFT). It shows code for filtering a signal using convolution, the FFT and IFFT, and using a DFT matrix and IFFT. The code generates a sinusoidal input signal, filters it using different methods, and plots the input, filter, and output signals.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Shravan Kumar Luitel (32015)

Kathmandu University

Communication
Laboratory
DSP_LAB 2: Filtering using DFT
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:

You might also like