Professional Documents
Culture Documents
Department of Electrical Engineering: Digital Signal Processing (Lab)
Department of Electrical Engineering: Digital Signal Processing (Lab)
Date : 10-04-2022
Graph
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
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
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
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.