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

Department of Electrical Engineering

Digital Signal Processing (Lab)

Audio Signal Processing using MATLAB

Name : Usama Bin Sohaib


Abdul-Raziq
Roll Number : BSEE-2019-43
BSEE-2019-01
Instructor : Engr. Arbaz Shb.

Date : 10-04-2022

NAMAL UNIVERSITY MIANWALI


Introduction
Audio Processing means changing the characteristics of an audio signal in some way.
Processing can be used to enhance audio, fix problems, separate sources, create new
sounds, as well as to compress, store and transmit data. MATLAB can also be used to
create and manipulate audio signals. In this lab, audio signals are generated using the
sinusoid signals.
Task 1
Code
fs=8000; %Sampling frequency
Ts=1/fs; %Sampling time
t=0:0.001:5; %Time interval
note1=5*sin(2*pi*523.25*t); %Sinusoid Signal
audiowrite('note1.wav',note1,fs); %Writing audio file
soundsc(note1); %Playing audio file

Graph

Fig.1 (Sinusoid signal for task 1)

Task 2
Code
t=0:0.001:5; %Time interval
%Different notes of signals
f = sin(2*pi*174.61*t);
g = sin(2*pi*195.99*t);
a = sin(2*pi*220*t);
b = sin(2*pi*246.94*t);
line1 = [a,b,g,f,f,b,b]; %Placing the notes in one order
line2 = [a,b,b,f,f,g,g]; %Placing the notes in another order
music = [line1, line2]; %Concatenation line 1 and line 2
soundsc(music); %Playing the music
plot(music);
title('music');
xlabel('Time (Seconds)');
ylabel('Amplitude');
Graph

Fig.2 (Music signal for task 2)

Task 3
Code
t=0:0.001:5; %Time interval
%Different notes of signals
f = 5*sin(2*pi*174.61*t);
g = 2*sin(2*pi*195.99*t);
a = 3*sin(2*pi*220*t);
b = 4*sin(2*pi*246.94*t);
line1 = [a,b,g,f,f,b,b]; %Placing the notes in one order
line2 = [a,b,b,f,f,g,g]; %Placing the notes in another order
music = [line1, line2]; %Concatenation line 1 and line 2
soundsc(music); %Playing the music
plot(music);
title('music');
xlabel('Time (Seconds)');
ylabel('Amplitude');
Graph

Fig.3 (Music signal for task 3)

Task 4
Code
t=0:0.001:5; %Time interval
%Different notes of signals
f = sin(2*pi*174.61*t);
g = sin(2*pi*195.99*t);
a = sin(2*pi*220*t);
b = sin(2*pi*246.94*t);
f1=rand(1,length(f)); %Generating noise for signal
f=f1+f; %Adding noise to signal
g1=rand(1,length(g)); %Generating noise for signal
g=g1+g; %Adding noise to signal
a1=rand(1,length(a)); %Generating noise for signal
a=a1+a; %Adding noise to signal
b1=rand(1,length(b)); %Generating noise for signal
b=b1+b; %Adding noise to signal
line1 = [a,b,g,f,f,b,b]; %Placing the notes in one order
line2 = [a,b,b,f,f,g,g]; %Placing the notes in another order
music = [line1, line2]; %Concatenation line 1 and line 2
soundsc(music); %Playing the music
plot(music);
title('music');
xlabel('Time (Seconds)');
ylabel('Amplitude');
Graph

Fig.4 (Music signal after adding noise for task 4)

Task 5
Code
fs=8000;
t=0:0.001:5; %Time interval
%Different notes of signals
f = sin(2*pi*174.61*t);
g = sin(2*pi*195.99*t);
a = sin(2*pi*220*t);
b = sin(2*pi*246.94*t);
f1=rand(1,length(f)); %Generating noise for signal
f=f1+f; %Adding noise to signal
g1=rand(1,length(g)); %Generating noise for signal
g=g1+g; %Adding noise to signal
a1=rand(1,length(a)); %Generating noise for signal
a=a1+a; %Adding noise to signal
b1=rand(1,length(b)); %Generating noise for signal
b=b1+b; %Adding noise to signal
line1 = [a,b,g,f,f,b,b]; %Placing the notes in one order
line2 = [a,b,b,f,f,g,g]; %Placing the notes in another order
music = [line1, line2]; %Concatenation line 1 and line 2
soundsc(music); %Playing the music
cutoff = 520/(fs/2); % Set the frequency at which the
attenuation begins.
order = 50; %Order of filter
d =
designfilt('lowpassfir','CutoffFrequency',cutoff,'FilterOrder'
,order); %Designing digital filter
output= filter(d,music);
figure (1)
plot(output);
title('music after filtering');
xlabel('Time (Seconds)');
ylabel('Amplitude');

Graph

Fig.5 (Music signal after filtering noise (Low Pass) for task 5)

Task 6
Code
fs=8000;
t=0:0.001:5; %Time interval
%Different notes of signals
f = sin(2*pi*174.61*t);
g = sin(2*pi*195.99*t);
a = sin(2*pi*220*t);
b = sin(2*pi*246.94*t);
f1=rand(1,length(f)); %Generating noise for signal
f=f1+f; %Adding noise to signal
g1=rand(1,length(g)); %Generating noise for signal
g=g1+g; %Adding noise to signal
a1=rand(1,length(a)); %Generating noise for signal
a=a1+a; %Adding noise to signal
b1=rand(1,length(b)); %Generating noise for signal
b=b1+b; %Adding noise to signal
line1 = [a,b,g,f,f,b,b]; %Placing the notes in one order
line2 = [a,b,b,f,f,g,g]; %Placing the notes in another order
music = [line1, line2]; %Concatenation line 1 and line 2
soundsc(music); %Playing the music
cutoff = 200/(fs/2); % the frequency before which the
attenuation exist.
order = 50; %Order of filter
d =
designfilt('highpassfir','CutoffFrequency',cutoff,'FilterOrder
',order); %Designing digital filter
output= filter(d,music);
figure (1)
plot(output);
title('music after filtering');
xlabel('Time (Seconds)');
ylabel('Amplitude');

Graph

Fig.6 (Music signal after filtering noise (High pass) for task 6)
Task 7
Code
fs=8000;
t=0:0.001:5; %Time interval
%Different notes of signals
f = sin(2*pi*174.61*t);
g = sin(2*pi*195.99*t);
a = sin(2*pi*220*t);
b = sin(2*pi*246.94*t);
f1=rand(1,length(f)); %Generating noise for signal
f=f1+f; %Adding noise to signal
g1=rand(1,length(g)); %Generating noise for signal
g=g1+g; %Adding noise to signal
a1=rand(1,length(a)); %Generating noise for signal
a=a1+a; %Adding noise to signal
b1=rand(1,length(b)); %Generating noise for signal
b=b1+b; %Adding noise to signal
line1 = [a,b,g,f,f,b,b]; %Placing the notes in one order
line2 = [a,b,b,f,f,g,g]; %Placing the notes in another order
music = [line1, line2]; %Concatenation line 1 and line 2
soundsc(music); %Playing the music
cutoff1 = 200/(fs/2); % Left side limit of bandpass
cutoff2=300/(fs/2); % Rght side limit of bandpass
order = 50; %Order of filter
d =
designfilt('bandpassfir','CutoffFrequency1',cutoff1,'CutoffFre
quency2',cutoff2,'FilterOrder',order); %Designing digital
filter
output= filter(d,music);
figure (1)
plot(output);
title('music after filtering');
xlabel('Time (Seconds)');
ylabel('Amplitude');
Graph

Fig.7 (Music signal after filtering noise (Band pass) for task 6)

Conclusions
In this lab, audio files are created using the sinusoids and by performing their
concatenation. Then the music files are played and observed for different sampling
frequencies and amplitudes. The noise is added to the music files by generating random
numbers array. Then it is removed using the bandpass, high and low pass filters.

You might also like