Sunteți pe pagina 1din 3

Digital Signal Processing

Filtering in Frequency Domain


Lab # 6

Lab work
The purpose of this lab is to familiarize students with the concepts of
filtering operation performed through convolution in time domain and
multiplication in frequency domain.

Lab tasks:
Step 1:
Generate a time vector with 1024 samples with the sampling frequency of
1024.
Generate three sine waves with frequencies of 10, 15 and 25 Hz
respectively, and add them together to have a signal as shown in the
figure below.

-1

-2

-3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Step 2:
Take Fast Fourier Transform of the signal generated in the above figure.
The fft of the above signal should be like this

0.5

0.4
Amplitude

0.3

0.2

0.1

0
-50 -40 -30 -20 -10 0 10 20 30 40 50
Frequency

Hint: help fft, fftshift


Digital Signal Processing

In order to have the output like shown in the figure observe the following
things
Keep in mind fft returns vector of the same size as the input vector, it
gives the two sided spectrum values, it returns complex numbers, it has to
be normalized with the number of samples, and after performing fft zero-
frequency component is not at the center of spectrum, in order to do so
use fftshift.

Step 3:

 Add noise to the signal using awgn function with SNR of 5 dBW.

-1

-2

-3

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0.5

0.45

0.4

0.35
Amplitude

0.3

0.25

0.2

0.15

0.1

0.05

-50 -40 -30 -20 -10 0 10 20 30 40 50


Frequency

Step 4:
 Generate the filter coefficients for an averaging filter.

Step 5:
 Convolve the noisy signal with the filter coefficients generated in
the previous step to have the time domain filtered signal.
 Take the Fourier transform of the filter coefficients so that the
number of samples after the output be same as the number of samples
in the Fourier transform of noisy signal. Multiply the two spectrums
i.e., noisy signal spectrum and spectrum of the filter coefficients
element by element.
Step 5:
 Take the Inverse Fourier transform of the signal and compare it with
the filtered time domain signal and observe the difference.
Digital Signal Processing

Code for the Lab # 6


clc
close all
clear all

N = 1024;
Fs = 1024;
Ncoef = 50 ;
SNR = 5;

t = (0:N-1)/Fs;
sig = sin(2*pi*10*t) + sin(2*pi*15*t) + sin(2*pi*25*t);
n_sig = awgn(sig,SNR,10*log10(var(sig)));
% fil_coef = [zeros(1,5) ones(1,Ncoef)./Ncoef zeros(1,5)];
fil_coef = ones(1,Ncoef)./Ncoef;
fil_sig = conv(n_sig,fil_coef);

Sig = fft(sig);
N_Sig = fft(n_sig);
FIL = fft(fil_coef,N);
FIL_SIG = FIL .*N_Sig;
f = (-(N/2):(N/2-1));

fil_sig_time = real(ifft(FIL_SIG));

% plot(f,fftshift(abs(N_Sig)/N))
% axis([-50 50 -inf inf])

% figure

subplot(4,2,1)
plot(t,sig)

subplot(4,2,2)
plot(f,fftshift(abs(Sig)/N))
axis([-100 100 -inf inf])

subplot(4,2,3)
plot(t,n_sig)

subplot(4,2,4)
plot(f,fftshift(abs(N_Sig)/N))
axis([-100 100 -inf inf])

subplot(4,2,5)
plot(fil_coef)

subplot(4,2,6)
plot(f,fftshift(abs(FIL)/N))
axis([-100 100 -inf inf])

subplot(4,2,7)
plot(fil_sig)

subplot(4,2,8)
plot(f,fftshift(abs(FIL_SIG)/N))
axis([-100 100 -inf inf])

S-ar putea să vă placă și