Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Digital Signal Procesing Lab Complex Engineering Design Submitted TO Mam Rida Maamoor BY

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Digital Signal Procesing Lab

COMPLEX ENGINEERING DESIGN SUBMITTED


TO
Mam RIDA MAAMOOR
BY

Ammad Akhtar FA18-BEE-032

Department of Electrical and Computer Engineering


COMSATS University Islamabad, Sahiwal campus

Spring 2023
Acknowledgement

First of all thanks to ALLAH Almighty who gives us the courage and His blessings to do
this project. Without His blessings nothing is possible. Allah is very towards us throughout
the project.
I am thankful to Mam Rida for providing me the opportunity to work on this Project and
provide me the technical and moral support during the project.

1
Abstract
In this project, we aim to design a digital filter for analyzing the spectral dynamics of
a real-time voice signal using signal processing techniques. The project will leverage the
background knowledge and available resources for signal processing to develop a filter that
effectively captures changes in the spectral content of the voice signal. The filter will
enable us to examine the frequency distribution and composition of the voice signal in real-
time. Ultimately, the project goal is to develop a tool that can be applied in a variety
of scenarios where the analysis of real-time voice signals is required, such as in speech
recognition, voice authentication, and emotion detection. The proposed approach holds
promise for providing more accurate and reliable results than existing methods while also
offering greater computational efficiency.

2
Contents

1 Introduction 5
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Aim Of The Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Filters 7
2.1 Digital Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 FIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.2 IIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.3 CIC Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Design Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Magnitude Response . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.2 Phase Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.3 Ripple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.4 Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.5 Transition Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.6 Stop Band Attenuation . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.7 Computational Complexity . . . . . . . . . . . . . . . . . . . . . . . 9

3 Procedure 10
3.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Software Implementation 11
4.1 MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1.1 MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Using App Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.1 Code View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.2 Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3
5 Conclusion 17
5.1 Reason For Finding Energy Spectrum . . . . . . . . . . . . . . . . . . . . . 17
5.2 Reason For Using Low Pass Filter . . . . . . . . . . . . . . . . . . . . . . . 17
5.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.4 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4
Chapter 1

Introduction

1.1 Introduction
Audio signal processing is the science of manipulating sound waves to achieve a desired
outcome or effect. It involves the use of specialized algorithms and techniques to modify,
filter, and analyze audio signals. In MATLAB, audio signal processing can be performed
using various built-in features and toolboxes, such as the Audio System Toolbox and the
Signal Processing Toolbox. These tools provide functions for tasks such as audio playback,
audio recording, filtering, compression, and visualization. Additionally, MATLAB also
supports the use of external audio hardware, such as microphones and speakers, to interact
with audio signals in real-time. By using MATLAB for audio signal processing, researchers
and engineers can develop advanced audio applications, analyze audio data, and optimize
audio systems for improved performance.

Figure 1.1:Post Processing Technique

1.2 Aim Of The Project


The Aim of the project is Using the resources and background knowledge of signal processing
techniques, design a digital filter for analysis of spectral dynamics of your real time voice
signal.

5
1.3 Block Diagram

Figure 1.2: Block Diagram

6
Chapter 2

Filters

2.1 Digital Filter


A Digital Filter is a mathematical algorithm that processes digital signals, such as audio
or images, to enhance or attenuate certain aspects of the signal. It can be used to remove
noise, equalize the frequency response, or extract specific information from the input signal.
Digital filters are often implemented using digital signal processing (DSP) techniques on a
computer or embedded system. There are several types of digital filters,
1: Finite Impulse Response (FIR) Filters,
2: Infinite Impulse Response (IIR) Filters,
3: Cascaded Integrator-Comb (CIC) Filters.

2.1.1 FIR Filter


A finite impulse response (FIR) filter is a type of digital filter that has a finite duration
output signal for a finite duration input signal. It operates by convolving the input signal
with a finite impulse response sequence of coefficients. The coefficients of the FIR filter
are fixed and are typically determined using windowing techniques such as the Hamming
window, Blackman window, or Kaiser window. FIR filters are preferred in many applica-
tions because they have linear-phase response, which means that they don’t introduce any
phase distortion in the filtered signal. Additionally, they can be designed to have sharp
cutoffs and linear-phase transitions, making them useful in applications that require a high
degree of signal processing precision, such as audio signal processing, image processing, and
telecommunications.

2.1.2 IIR Filter


An infinite impulse response filter (IIR filter) is a type of digital filter that uses feedback
to create an output. It is also known as a recursive filter because it uses its own outputs as
inputs. The IIR filter works by modifying the input signal in such a way that the filtered

7
output signal is a function of not only the current input sample, but also of past input
samples.
The IIR filter can be implemented using difference equations, which are based on the
principles of linear time-invariant systems. In contrast to finite impulse response (FIR)
filters, which have a finite duration of their impulse response, IIR filters have an impulse
response that goes on indefinitely. This makes them more versatile and efficient in certain
applications.

2.1.3 CIC Filter


A cascaded integrator comb filter is a digital signal processing filter that is commonly used
in audio and speech processing applications. It is made up of a series of integrators and
delay elements arranged in a comb-like structure. The filter attenuates high-frequency noise
and has a sharp frequency response in the passband. It has a low computational complexity
and is easy to implement in software. The filter is named for the cascaded integrator stages
that provide the filtering and the comb delay structure that generates the periodic response.

2.2 Design Criteria


There are several criteria for designing a digital filter, including:

2.2.1 Magnitude Response


This refers to how the filter affects the amplitude of different frequencies in the signal. The
ideal filter should pass the desired frequencies with minimal attenuation and attenuate all
the other frequencies.

2.2.2 Phase Response


This refers to how the filter affects the timing of different frequency components in the
signal. The ideal filter should not introduce any phase shift in the pass band.

2.2.3 Ripple
This is the amount of variation or fluctuations in the frequency response of the filter. The
smaller the ripple, the better the filter.

2.2.4 Group Delay


This is the delay introduced by the filter for different frequency components. The ideal
filter should have constant group delay across the pass band.

8
2.2.5 Transition Region
This is the range of frequencies in which the filter transitions from pass band to stop band.
The ideal filter should have a narrow transition region to minimize unwanted attenuation
and phase shifts.

2.2.6 Stop Band Attenuation


This is the amount of attenuation in the stop band. The ideal filter should have high stop
band attenuation to suppress unwanted frequencies.

2.2.7 Computational Complexity


This refers to the amount of processing power required to implement the filter. The ideal fil-
ter should have low computational complexity to minimize the processing time and resource
requirements.

9
Chapter 3

Procedure

3.1 Procedure
These are the following steps we follow:
1. First we record the sample voice signal in real-time using a microphone.
2. Use the ’audiorecord’ function in MATLAB to record the audio signal. Set the
parameters such as sample rate, duration of recording, and number of channels.
3. Analyze the time domain of the recorded audio signal using the ’plot’ function in
MATLAB. Plot the amplitude of the signal as a function of time.
4. Calculate the energy spectrum of the recorded audio signal using the ’fft’ function in
MATLAB . Convert the signal to the frequency domain and plot the signal over a range of
frequencies.
5. Apply a low pass filter to the audio signal using the ’filter’ function in MATLAB.
Determine the cutoff frequency of the filter and design the filter using the ’fir1’ function in
MATLAB.
6. Filter the audio signal with the designed low pass filter using the ’filter’ function in
MATLAB.
7. Plot the filtered audio signal in the time domain using the ’plot’ function in MATLAB.
Compare it with the original signal to see the effect of the low pass filter.
8. Calculate the energy spectrum of the filtered audio signal using the ’fft’ function in
MATLAB. Convert the signal to the frequency domain and plot the signal over a range of
frequencies to see the effect of the low pass filter on the spectrum.

10
Chapter 4

Software Implementation

4.1 MATLAB
All of the program and all of the code was written in Mathworks Matlab 2021a.Matlab
(short for ”Matrix Laboratory”) is a programming language and numerical computing en-
vironment developed by MathWorks. It is used for a wide range of applications, including
engineering and scientific computations, data analysis and visualization, and algorithm de-
velopment. Matlab provides an extensive library of built-in functions for performing various
computations, as well as an interactive development environment for writing and debug-
ging code. It also supports various data types, including matrices, arrays, and structures,
which enable users to manipulate complex data sets with ease. Matlab is widely used in
academia and industry for research and development, and is considered to be one of the
leading software packages for numerical computation.

4.1.1 MATLAB Code


clc;close all;
Fs=input(’Enter Sampling Frequency’)
duration=10;
r= audiorecorder(Fs,16,1)
disp(’Start recording’)
recordblocking(r,duration)
disp(’Recording Stop’)
X=getaudiodata(r)
t=0:1/Fs:(length(X)-1)/Fs;
% Compute the spectrum
N = length(X);
f = (0:N-1)*(Fs/N); % Frequency vector
Y = fft(X)/N; % Compute FFT and normalize
subplot(321)

11
plot(t,X)
title(’Audio signal’)
xlabel(’Time(sec)’)
ylabel(’Amplitude’)
subplot(322)
plot(f,Y)
title(’FFT of audio signal’)
xlabel(’Frequency(hz)’)
ylabel(’Magnitude’)
win = hamming(N); % Window function
E = abs(fft(win.*X)).^2/N; % Compute energy spectrum
% Plot energy spectrum
subplot(323)
plot(f,E); % Plot energy spectrum
title(’Energy Spectrum of Speech Signal’);
xlabel(’Frequency (Hz)’);
ylabel(’Energy (dB)’);
% Apply Low-Pass Filter with Cutoff Frequency of 3000 Hz
b = fir1(100,3000/(Fs/2));
y = filter(b,1,X);
% Plot Filtered Signal and Spectrum
subplot(324), plot(t,y)
xlabel(’Time (s)’)
ylabel(’Amplitude’)
title(’Filtered Speech Signal’)
Y1 = fft(y);
E = abs(fft(win.*Y1)).^2/N; % Compute energy spectrum
% Plot energy spectrum
subplot(325);
freq1 = 0:Fs/length(E):Fs/2;
plot(freq1,10*log10(E(1:length(freq1))))
% Plot energy spectrum
title(’Energy Spectrum of filtered speech signal Speech Signal’);
xlabel(’Frequency (Hz)’);
ylabel(’Energy (dB)’);
figure;
cwt(X,Fs)
figure;
cwt(y,Fs)

12
4.1.2 Results

Figure 1.3: Output

Figure 1.4: Wavelet Transform of audio signal

13
Figure 1.5: Wavelet Transform of Filtered signal

4.2 Using App Designer


4.2.1 Code View
Start Button
Fs= str2double(app.FsTextArea.Value(1))
duration=5;
r = audiorecorder(Fs,16,1)
recordblocking(r,duration)
X=getaudiodata(r)
t=0:1/Fs:(length(X)-1)/Fs;% Compute the spectrum
N = length(X); f = (0:N-1)*(Fs/N); % Frequency vector
Y = fft(X)/N; % Compute FFT and normalize
plot(app.UIAxes6,f,Y)
win = hamming(N); % Window function
E = abs(fft(win.*X)).^2/N; % Compute energy spectrum
plot(app.UIAxes3,t,X);plot(app.UIAxes2,f,abs(E))% ApplyLow-PassFilterwith fc 3000Hz
b = fir1(100,3000/(Fs/2));y = filter(b,1,X);plot(app.UIAxes4,t,y) ;Y1 = fft(y);
E1 = abs(fft(win.*Y1)).^2/N; % Compute energy spectrum
freq1 = 0:Fs/length(E):Fs/2;
plot(app.UIAxes5,freq1,10*log10(E1(1:length(freq1))));

14
Stop Button

Figure 1.6: Stop Button

Clear Button

Figure 1.6: Clear Button

15
4.2.2 Result

Figure 1.6: Output

16
Chapter 5

Conclusion

5.1 Reason For Finding Energy Spectrum


We find the energy spectrum of an audio aperiodic signal in MATLAB to analyze the
frequency content of the signal. Aperiodic signals are non-repetitive and their spectral
characteristics can provide valuable information about the nature of the signal. The energy
spectrum of a signal gives us information about the distribution of energy across different
frequencies in the signal. By analyzing the energy spectrum, we can identify the dominant
frequencies in the signal, which can help us better understand the properties of the audio
signal. This information can be useful in applications such as noise reduction, signal filtering,
and feature extraction.

5.2 Reason For Using Low Pass Filter


Low pass filters have a simpler design and construction compared to band pass filters.Low
pass filters are generally less expensive to manufacture than band pass filters.Low pass filters
have a wider frequency range and can be used for a broader range of applications.Low pass
filters can effectively reduce noise in a signal, making them particularly useful in audio and
video applications. Low pass filters can help prevent electrical shock by filtering out high-
frequency electrical noise and interference. Low pass filters can also be used to improve
energy efficiency by filtering out unwanted high-frequency components in power systems.

5.3 Conclusion
In summary, by using the principles of signal processing, we can design a digital filter for
the analysis of spectral dynamics in real-time voice signals. The filter should extract the
spectral dynamics of the audio signal by identifying the lower frequency components. This
filtered signal can provide insights into the spectral dynamics of the voice signal.

17
5.4 Reference
[1] J. Nordstr¨om, “Real time digital signal processing using matlab,” 2017.
[2] S. M. Kuo, B. H. Lee, and W. Tian, Real-time digital signal processing: fundamentals,
implementations and applications. John Wiley Sons, 2013.
[3] Z.-J. Mou and P. Duhamel, “Short-length fir filters and their use in fast nonrecursive
filtering,” IEEE Transactions on Signal Processing, vol. 39, no. 6, pp. 1322–1332, 1991.

18

You might also like