You are on page 1of 23

EE-323 DIGITAL SIGNAL PROCESSING

COMPLEX ENGINEERING PROBLEM (CEP)


6TH SEMESTER (SPRING 2018)

Submitted to: Engr. Komal Munir

Submitted by: Shahneel Fatima 15-EE-11

Yameena Tahir 15-EE-23

Shaiza 15-EE-35

DEPARTMENT OF ELECTRICAL ENGINEERING

UNIVERSITY OF ENGINEERING AND TECHNOLOGY

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

frequencies pertaining to the signal aspect under consideration.

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.

Harmonics in power systems needs to be removed as they result in various undesired


phenomena’s e.g., increased heating in the equipment and conductors, misfiring in variable
speed drives etc.

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’

STEPS WITH DESCRIPTION:

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

Since, the duration of given signal is 10 seconds, t = 10sec

As, sampling frequency Fs is no. of samples per second, so

Fs = No. of samples/sec = 80,000/10 = 8000Hz

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,

As Fs = 8000Hz, thus it Fs = 2*Fm satisfies, therefore no aliasing will occur.

STEP 3: We load the signal in MATLAB using command ‘load noisy_signal.mat’. By


listening to the noisy audio signal, we can infer that the noise added in the signal is uniform &
is of a particular frequency beep or more. 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.

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:

Passband Attenuation (Ap) = 1dB


Stopband Attenuation (As) = -27.3dB
As is observed from Power Curve, it is the power in dB at noise frequencies 420Hz and 750Hz.
Ap=20log(1+δp/1-δp)
δp=0.0574
As=20log(1+δp/δs)
δs=0.0423
FOR FIR FILTER:
wp=410*2pi/8000 = 0.1025*pi
ws=430*2pi/8000 = 0.1075*pi
For the selection of window:
δmin=δs
A=-20log10^(δmin)
A=-27.45

4
Looking for window type,

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;

[n,wn]=buttord(wp,ws, δp, δs)


n= 4

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

f=[410 430]*2/8000; % cutoff frquency range

b1 = fir1(1239,f,'stop') % filter coefficient 1

f=[740 760]*2/8000; % cutoff frquency range

b2 = fir1(1239,f,'stop') % filter coefficient 2

Designing of IIR Filters

w1=[416 424]*2/8000; %cutoff frquency for first filter

[b a]=butter(4,w1,'stop'); %filter coefficient

w2=[746 754]*2/8000; %cutoff frquency for second filter

[c d]=butter(4,w2,'stop'); %filter cofficient

STEP 7: After designing the filters, now its time to filter our noisy audio signal to remove
noise. We have used MATLAB command

x=filter(b1,1,noisy_signal) %For FIR Filter 1

x1=filter(b2,1,noisy_signal) %For FIR Filter 2

Since FIR Filter has poles at the origin, thus denominator = 1

& x2=filter(b,a,noisy_signal); %For IIR Filter 1

X3=filter(c,d,noisy_signal); %For IIR Filter 2

Noisy frequencies have been removed.

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

ANSWER THE FOLLOWING QUESTIONS:


1. How did you find out the sampling frequency Fs of the given noisy audio signal?

Ans. 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

6
Since, the duration of given signal is 10 seconds, t = 10sec

As, sampling frequency Fs is no. of samples per second, so

Fs = No. of samples/sec = 80,000/10 = 8000Hz

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?

Ans. As human audio frequency ranges maximum up to 3kHz.therefore according to Nyquist


criteria sampling frequency should be greater than or equal to the maximum frequency present
in the signal.it means Fs should be greater than 6khz.here we have selected Fs=8kHz,which is
quite sufficient to avoid aliasing during 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

the noise added in the signal?

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

than the input signal data length?

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

N = 80,000 yields Fs = 8000Hz, thus satisfying the Nyquist criteria.

6. What is the reason for computing DFT through FFT algorithm in MATLAB? Justify

your answers with numbers

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

Additions: N(N-1) = 80,000(79,000) = 6.3*109

In FFT Computation:

Multiplications: (N/2)*log2(N) = 651508

Additions: N*log2(N) = 1.3*106

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

the noisy audio signal?

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

remove the noise?

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

have utilized in your filter design?

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?

Ans. FIR filtering has these advantages over IIR filtering:

• 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

implications of changing the order of the filter?

Ans. I have found the filter order by the following method,

Passband Attenuation (Ap) = 1dB


Stopband Attenuation (As) = -27.3dB
As is observed from Power Curve, it is the power in dB at noise frequencies 420Hz and 750Hz.
Ap=20log(1+δp/1-δp)
δp=0.0574
As=20log(1+δp/δs)
δs=0.0423
FOR FIR FILTER:
wp=410*2pi/8000 = 0.1025*pi
ws=430*2pi/8000 = 0.1075*pi
For the selection of window:
δmin=δs
A=-20log10^(δmin)
A=-27.45
Looking for window type,

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;

[n,wn]=buttord(wp,ws, δp, δs)


n= 4
Since, the order of both FIR & IIR filters remove the noise completely, thus there in no need
to vary the order.

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

f=[740 760]*2/8000; % cutoff frquency range


b2 = fir1(1239,f,'stop') % filter cofficient
x1=filter(b2,1,x) % filter the frequency of noise
%sound(x1) % playing the filtered audio
figure(4)
spectrogram(x1,[],[],[],fs,'yaxis') % spectral analysis of filtered signal
title('Spectogram of FIR Filtered Audio Signal');
%% STEP5: PLOTTING TIME & FREQUENCY DOMAIN FIR FILTERED SIGNAL
figure(5)
subplot(211)
plot(t,x1); % plot the filtered audio signal
xlabel('samples');
ylabel('Audio Data');
title('Filtered Audio Signal using FIR Filter');
grid on
subplot(212)
plot(abs(fft(x1)))
title('DFT Magnitude Spectrum of Filtered Audio Signal');
grid on
xlabel('Frequency (Hz)')
ylabel('Magnitude')
figure(6)
freqz(b1);
title('Magnitude and Phase Response of FIR Filter');
hold on
13
freqz(b2);
grid on
hold off
%% STEP_6: PLOTTING POLE ZERO PLOT OF DESIGNED FIR FILTER
figure(7);
subplot (211)
zplane(b1);
title('Pole Zero Plot of FIR Filter');
grid on
subplot (212)
zplane(b2);
title('Pole Zero Plot of FIR Filter');
grid on
%% STEP_7: IIR FILTER DESIGNING & FILTERING THE NOISY SIGNAL
w1=[416 424]*2/8000; % cutoff frquency for first filter
[b a]=butter(4,w1,'stop'); % filter coefficient
x2=filter(b,a,noisy_signal); % filter the noise frequency

w2=[746 754]*2/8000; % cutoff frquency for second filter


[c d]=butter(4,w2,'stop'); % filter cofficient
x3=filter(c,d,x2); % 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

You might also like