Sie sind auf Seite 1von 6

Signals and Systems

(EL-223)

LABORATORY MANUAL

Engr. Fakhar Abbas


Engr. Aneela Sabir
Engr. Ihtisham Khalid
DFT Analysis using fft command and Filter Design using
MATLAB
(LAB # 11)
Student Name: ______________________________________________

Roll No: ________________ Section: ______

Date performed: ________________, 2019

MARKS AWARDED: ________ / 10

____________________________________________________________________________________________________________________________________________________________

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD

Prepared by: Engr. Fakhar Abbas Version: 1.00


Last Edited by:
Verified by: Dr. Waqas bin Abbas, Ms. Sana Hassan Updated: Spring 2019
Analysis of fft and Filter Design in MATLAB Lab 11
Lab # 11: Analysis of fft Commnd and Filter Design Using MATLAB
Objective: In this lab, you will learn:
 Analysis of fft command over different points
 Filter Design using FDA Tool
 Filtering applied to Audio Signals

Tools Used: MATLAB


Description:
Brief Summry of Last Lab :
The discrete Fourier transform, or DFT, is the primary tool of digital signal processing. DFT and
Inverse DFT are represented as:

DFT computations using MATLAB:


fft() and ifft() In MATLAB the FFT algorithm is already programmed in . fft(x) operates on a vector
x (in our case a discretetime signal) and gives back the DFT of x.
CAREFUL, It may need to be normalized! Likewise ifft(y) operates on a vector y (in our case a
discrete-frequency representation of a signal) and gives back the inverse DFT of y.
fftshift() Remember, 𝑋[𝑘] is periodic with period N. We can use this to our advantage to plot the
frequency “spectrum” by shifting the period to center around the DC component. In MATLAB the
function that does this is called fftshift(). Note there is also a function ifftshift() which does the
reverse. Task related to fftshift is added for your understanding.
What is a Filter?
• Passes a band of frequencies and rejects other frequencies
– Three Bands of Interest
• Pass band, The frequencies which get through
• Stop band, the frequencies which don’t get through
• Transition bands, the bands in which part of the frequencies get through, between stop and pass
bands.
Example: - Tuning a Radio, an example of Filtering. What does it do? Passes the frequencies you
want and rejects those that you do not want.
Types of Digital Filters
• Low Pass: Passes low frequencies, rejects high frequencies
• High Pass: Passes high frequencies, rejects low frequencies
• Band Pass: Passes a band of frequencies
• Band Stop: Rejects a band of frequencies
Filter Implementations
• Infinite Impulse Response (IIR) – Feedback filter
• Finite Impulse response – Feed Forward
• Hybrid IIR/FIR
Key parameters in filter design
• Sampling rate
• Number of Taps
• Pass band
• Stop Band

SIGNALS AND SYSTEMS LAB NUCES FAST, ISLAMABAD Page 2 of 6


Analysis of fft and Filter Design in MATLAB Lab 11
Step 1: Filter Design Analysis Tool
Type fdatool in command window

Sampling Frequency

Stop Band

Pass Band

Step 2: Enter Parameters


• Enter Sampling Frequency
• Pass Band
• Stop Band
• Leave Everything else the same
Step 3: Design Filter
Let us design a low pass filter by setting parameters shown below
• Push “design Filter
Button

Filter Magnitude Response

SIGNALS AND SYSTEMS LAB NUCES FAST, ISLAMABAD Page 3 of 6


Analysis of fft and Filter Design in MATLAB Lab 11

Step 4: Export Coefficients


• On “File Menu” in fdatool, click at Export

Following figure will appear. Create “Num” instead of coefficients. Num means numerator for the
filter.

Step 5: do the filtering.

• Set Den=1, since we are using FIR Filter whose denominator coefficient= 1; Input contains the
signal you want to filter out.
• Type Output=filter(Num,den,Input)” to apply the filter you have created.

SIGNALS AND SYSTEMS LAB NUCES FAST, ISLAMABAD Page 4 of 6


Analysis of fft and Filter Design in MATLAB Lab 11
Task 1: Understanding fftshift () command:
Let , where , , and N=10 samples.
Write a Matlab code to compute dft using fft command . The objective of this task is to become
familiar with fftshift command. Your graphs should contain 3 subplots like this:

Task 2: Analysis of DFT:


Let and ,
Write a Matlab code to compute dft of Let Fs=1000. and N = 500 samples. Your plot should
look like this.

SIGNALS AND SYSTEMS LAB NUCES FAST, ISLAMABAD Page 5 of 6


Analysis of fft and Filter Design in MATLAB Lab 11
Task 3: Analysis of fft Command Over Different Points:
Consider in task 1. Vary fft points and observe the variation in frequency domain spectrum. Fill
the following table.

Table 1 - Effect of fft points in frequency domain

fft points Positive Frequency at Negative Frequency Observations


whcich First Peak at whcich First Peak
Occur Occur
256
128
64
32
16
8
4

Task 4: Filtering Audio Signal using Fdatool and Filter Command:


Download ‘8k8bitpcm.wav’ file from Slate. We want to filter this audio signal using highpass filter.
Design the Highpass filter in Fdatool with following parameters. Fs=8000 Hz, Fstop=500 Hz,
Fpass=600 Hz;Export coefficients in workspace.
Analyse and complete the following code.
clc;close all;
[x,Fs]=audioread('8k8bitpcm.wav');
% Write code to listen audio for 2 seconds only
pause(4)% Pause for 4 seconds
% Design a highpass filter for above mentioned parameters
y=filter(Num,1,x);
% sound command is used to listen the filtered audio signal sampled
at Fs
% Write code to write filtered audio signal
% compare two sounds
Task 5: Analysis of Audio Signal using Filter Command:
Modify the above written Matlab code in Task 3 as follows:
 Add x_new = cos(2*pi*100*n/Fs)with x where n has the same samples as that of x
 Increase the volume of sound 10 times
 Rest steps are same as mentioned in task 2.
Observations:- Write here about the changes you have seen after adding x_new to original signal.

SIGNALS AND SYSTEMS LAB NUCES FAST, ISLAMABAD Page 6 of 6

Das könnte Ihnen auch gefallen