Professional Documents
Culture Documents
Shaiza 15-EE-35
TAXILA
TABLE OF CONTENTS:
Page#
• Abstract …………………………….………………………………..…..03
• Objective…………………………………………………………..……..04
• Methodology……………………………………………………………..04
• Questions/Answers……………………………………………..…..…….07
• MATLAB Code……………………………………………………..…….11
• MATLAB Plots……………………………………………………..…….16
• Learnings & Findings………………………………………………..…….23
2
ABSTRACT:
One of the most common application of the Digital Signal Processing (DSP) is the filtering i.e.,
partial/ complete attenuation of some undesired or enhancement of some desired aspect of the
signal. Filtering is carried out through the filters which are devices or circuits and affects the
In power systems, harmonics are induced due to non-linear load which means that voltage or
current signals are distorted and deviate from the sinusoidal waveform.
Therefore, the goal of the filter in these two scenarios is to remove the frequencies related to
noise or harmonics from the communication or power signal, respectively.
OBJECTIVE:
The main objective of this COMPLEX ENGINEERING PROBLEM is to design a digital filter
(FIR and IIR) in MATLAB which removes the background noise (undesired aspect) from the
given noisy audio signal.
‘METHODOLOGY’
STEP 1: First Step of our CEP is to find out the sampling frequency. We first find out the
length of the given audio signal by using command ‘length(noisy_signal)’ in MATLAB. We
take No. of samples = Length of given signal = 80,000
STEP 2: . After the selection of Fs, we check whether it is suitable enough to avoid aliasing
during audio signal ADC. According to Nyquist Criteria, Fs should be equal to two times of
3
the maximum frequency present in the signal. Since Max. Frequency present in the given signal
is Fm = 4000Hz, thus Fs’ = 2*Fm = 2*4000 = 8000Hz,
STEP 4: After plotting the Noisy Audio Signal and its digital version in time domain, we
plot DFT Magnitude spectrum through FFT Algorithm, i.e I convert the signal in the form of
‘Radix 2’ using MATLAB command ‘NFFT = 2^nextpow2(l)’ / 2L-1
From the spectrogram of noisy audio signal , we came to know that the frequencies of the noise
in our input signal are ‘420Hz and 750Hz’
STEP 5: After knowing the frequencies of noise in input data signal, its time to design FIR
filter.
FILTER SPECIFICATIONS:
4
Looking for window type,
wp=[.100 .900]*2/8000;
ws=[0.1040 0.1060]*2/8000;
STEP 6: As order of FIR & IIR Filters are now known, now we have found the filter co-
efficients using following commands in MATLAB
5
% FIR Filter Design
STEP 7: After designing the filters, now its time to filter our noisy audio signal to remove
noise. We have used MATLAB command
STEP 8: Plot the frequency response to observe Magnitude & Phase Responses of FIR & IIR
Filters, & pole zero plot of designed filters to observe the conjugate symmetry
Ans. We first find out the length of the given audio signal by using command
‘length(noisy_signal)’ in MATLAB. We take
6
Since, the duration of given signal is 10 seconds, t = 10sec
2. Is there any intuition behind the selection of the FS? What makes you think it should be
sufficient to avoid aliasing during audio signal ADC?
3. Why data is stored in the double precision whereas signal was originally captured with
8-bit precision?
Ans. 8 bit precision means: there are 28 (256) different possible values for 8 bits. When
unsigned, it has possible values ranging from 0 to 255, when signed, it has -128 to 127. Double-
precision floating-point format is a computer number format, usually occupying 64 bits in
computer memory; it represents a wide dynamic range of numeric values by using a floating
radix point. Data is stored in double precision because it allows a wide range of memory for
processing of data. With 8 bit precision, it allows a very less margin of numbers to be stored
therefore, it will cause overflow and processing could never be done with it. Therefore, Double
precision may be chosen when the range or precision of single precision would be insufficient.
4. By listening to the noisy audio signal, what can you infer about the characteristics of
Ans. By listening to the noisy audio signal, I can infer that the noise added in the signal is
uniform & is of a particular frequency beep or more.
5. While performing the frequency domain analysis why and what value of N has been
chosen for DFT computation? What is the implication of making N smaller or larger
Ans. We’ve chosen No. of samples N = Input signal data length = 80,000
7
We can’t make N smaller than input data length as information of input data signal can be lost.
We also didn’t make N larger than input data length, as it will occupy more memory. Also
6. What is the reason for computing DFT through FFT algorithm in MATLAB? Justify
Ans. The reason for computing DFT through FFT algorithm in MATLAB is that FFT is more
efficient method. A Fast Fourier transform (FFT) is a fast computational algorithm to compute
the discrete Fourier transform (DFT) and its inverse.
• The time takes to perform a DFT on a computer depends primarily on the number of
multiplications involved (O(N2)) while FFT only needs Nlog2(N).
• N = 80,000 (samples)
In DFT Computation,
Multiplications: N2 = (80,000)2
In FFT Computation:
Thus, it can be seen that computation through FFT Algorithm is more efficient & fast as
compared to DFT Algorithm.
7. How did you identified the frequency/ frequencies pertaining to the noise only from
Ans. The frequency/ frequencies pertaining to the noise cannot be identified only from the
noisy audio signal. We have to plot its spectrogram in-order to identify the unknown
frequencies of the noise.
8
8. What type of filtering Low Pass, High Pass, Band Pass, or Band Stop is required to
Ans. We have used ‘Band Stop’ Filter to remove the noise from noisy audio signal.
9. What is the intuition behind choice of type of the filter and design method which you
Ans. The reason behind the choice of filter is that there is a need to allow all the frequencies
of the given audio signal to pass accept two frequencies. Thus, in order to stop these two
frequencies, we have design a band stop filter.
10. Which type of the filter FIR or IIR is more suitable for the given CEP and why?
Ans.IIR is more suitable for our given CEP, it is because it requires low order.
Although FIR filters are more powerful than IIR filters, but also require more processing power
and more work to set up the filters. They are also less easy to change "on the fly" as you can
by tweaking (say) the frequency setting of a parametric (IIR) filter.
11. List the advantages and disadvantages of FIR and IIR filters? Which one is
computationally efficient?
• It can implement linear-phase filtering. This means that the filter has no phase shift
across the frequency band. Alternately, the phase can be corrected independently of the
amplitude.
• It can be used to correct frequency-response errors in a loudspeaker to a finer degree of
precision than using IIRs.
However, FIRs can be limited in resolution at low frequencies, and the success of applying FIR
filters depends greatly on the program that is used to generate the filter coefficients. Usage is
generally more complicated and time-consuming than IIR filters.
IIR filters are the most efficient type of filter to implement in DSP (digital signal processing).
They are usually provided as "biquad" filters
An FIR filter requires more computation time on the DSP and more memory.
9
12. How did you decided the filter order of FIR and IIR filter? And what are the
10
A nearest greater than -44dB is ‘Hanning’
Now the window is hanning:
w = ws-wp
w = 0.005*pi
w = 6.2pi/L
Where L is length
L=1240
So order is
M=L-1=1239
FOR IIR FILTER ORDER
wp=[.100 .900]*2/8000;
ws=[0.1040 0.1060]*2/8000;
13. Is there any symmetry in pole zero plots of the designed FIR and IIR filter?
Ans.Yes, we have found conjugate symmetry in zeros of FIR filter and poles & zeros of IIR
filter.
MATLAB CODE:
%%%%%%% ******* COMPLEX ENGINEERING PROBLEM ******** %%%%%%%%
%% Submitted by: SHAHNEEL FATIMA 15-EE-11
% YAMEENA TAHIR 15-EE-23
% SHAIZA 15-EE-35
%% STEP1: CALCULATING SAMPLING FREQUENCY
clc; clear all; close all;
load noisy_signal.mat
fs=8000; % sampling frequency
T=1/fs; % sample time
l=80000; % length of the signal
11
t=(0:l-1)*T; % Time vector
t1=(0:l-1);
%sound(noisy_signal) % play the audio signal
%% STEP2: PLOTTING NOISY AUDIO SIGNAL IN TIME & FREQUENCY DOMAIN
figure(1)
subplot(211)
plot(t,noisy_signal); % plot of noisy_signal against time
xlabel('Time(sec)');
ylabel('Audio Data');
title('Noisy Audio Signal');
grid on
subplot(212)
stem(t1,noisy_signal); % plot of noisy_signal against samples
xlabel('Samples');
ylabel('Audio Data');
title('Digital Noisy Audio Signal');
grid on
figure(2)
subplot(211)
NFFT = 2^nextpow2(l); % Next power of 2 from length of y
Y = fft(noisy_signal,NFFT)/l;
f = fs/2*linspace(0,1,NFFT/2+1);
plot(abs(fft(noisy_signal)))
title('DFT Magnitude Spectrum of Noisy Audio Signal(Two Sided)');
grid on
xlabel('Frequency (Hz)')
ylabel('Magnitude')
subplot(212)
plot(f,abs(Y(1:NFFT/2+1)))
title('DFT Magnitude Spectrum of Noisy Audio Signal(Single Sided)');
grid on
xlabel('Frequency (Hz)')
ylabel('Magnitude')
%% STEP3: IDENTIFYING THE FREQUENCIES OF NOISE
12
figure(3)
spectrogram(noisy_signal,[],[],[],fs,'yaxis'); % to identify the noise frequency
title('Spectogram of Noisy Audio Signal');
%% STEP4: FIR FILTER DESIGNING & FILTERING THE NOISY SIGNAL
%fir filter design
f=[410 430]*2/8000; % cutoff frquency range
b1 = fir1(1239,f,'stop') % filter cofficient
x=filter(b1,1,noisy_signal) % filter the frequency of noise
figure(8);
freqz(b,a); % frequency response on the filter coefficients
title('Magnitude and Phase Respone of IIR Filter');
grid on
hold on
freqz(c,d); % frequency response on the filter coefficients
grid on
hold off
%sound(x3) % play the IIR filtered audio signal
%% STEP8: PLOTTING TIME & FREQUENCY DOMAIN IIR FILTERED SIGNAL
figure(9)
plot(x3) % plot of fitered signal
14
xlabel('samples');
ylabel('Audio Data');
title('Filtered Audio Signal using IIR Filter')
grid on
figure(10)
spectrogram(x,[],[],[],fs,'yaxis') % spectral analysis of filtered signal
title('Spectogram of IIR Filtered Audio Signal');
%% STEP9: PLOTTING POLE ZERO PLOT OF DESIGNED IIR FILTER
% pole zero plot of designed IIR Filters
figure(11);
subplot(2,1,1);
zplane(b,a);
title('Pole Zero Plot of first IIR filter');
grid on
subplot(2,1,2);
zplane(c,d);
title('Pole Zero Plot of Second IIR filter');
grid on
%% Power Graph
figure(12)
pwelch(noisy_signal,[],[],[],fs)
%% COMPARISON B/W FILTERS FIR , IIR
figure(13)
subplot(211)
plot(t,noisy_signal); % plot of noisy_signal against time
xlabel('Time(sec)');
ylabel('Audio Data');
title('Noisy Audio Signal vs IIR Filtered Audio Signal');
grid on
hold on
plot(x1);
hold off
grid on
15
legend ('noisy signal','filtered signal through FIR')
subplot (212)
plot(t,noisy_signal); % plot of noisy_signal against time
xlabel('Time(sec)');
ylabel('Audio Data');
title('Noisy Audio Signal vs IIR Filtered Audio Signal');
hold on
plot(x3) % plot of IIR fitered signal
grid on
hold off
legend ('noisy signal','filtered signal through IIR')
%% STEP_10: LISTENING TO THE FINAL OUTPUT
% sound(noisy_signal) % play the audio signal
sound(x1) % play the FIR filtered audio
% sound(x3) % play the IIR filtered audio signal
%%%%%%% *** WE HAVE SUCCESSFULLY FILTERED THE SIGNAL *** %%%%%
%%%%%%%%%%% ************ THANKYOU ************* %%%%%%%%%
MATLAB_PLOTS:
16
17
18
19
20
21
22
LEARNINGS & FINDINGS:
• After this CEP, now we are able to design any type of filter manually as well as on
MATLAB
• Understanding the basic terminologies of DIGITAL SIGNAL PROCESSING including
DFT, FFT Algorithm, Calculating Order and Design Specifications of any type of filter
whether FIR or IIR
• Understanding new MATLAB commands for filter designing and plotting frequency
spectrums, spectrograms and zero pole plots etc
23