You are on page 1of 26

Digital Signal Processing

B.M.S. COLLEGE OF ENGINEERING


(Autonomous College Affiliated to Visvesvaraya Technological University, Belgaum)

Bull Temple Road, Basavanagudi, Bangalore-560019

REPORT
ON
“APPLICATION OF FILTERS ON A
SOUND SAMPLE”
Submitted in partial fulfilment of the requirements for the partial completion of
DIGITAL SIGNAL PROCESSING
(16EC5DCDSP)

SUBMITTED BY:
AMITH P 1BM17EC010

Course instructor
LALITHA S
Assistant Professor, Dept. of ECE

Aug-Dec 2019

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

DEPT OF ECE, BMSCE 1


Digital Signal Processing

Audio selected for processing:


A dual channel (stereo) song has been selected and various filters are used to extract the different
contents of the song like bass, treble and base voice.

Code to plot time and frequency domain of the song:


[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
subplot(2,1,2)
plot(t,y);

song.mp3

DEPT OF ECE, BMSCE 2


Digital Signal Processing

BUTTER WORTH LOW PASS FILTER

Here we pass the signal through a Butterworth lowpass filter in order to extract the bass of the
signal as bass of the song is below to 250Hz.
The pass band and stop band edge frequencies are 200 and 300 Hz respectively.The passband
attenuation is 1 dB and the stopband attenuation is 20dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
wp = 2*(200*pi/fs);
ws = (2*300*pi/fs);
[N,wn]= buttord(wp/pi,ws/pi,1,20)
[b,a]=butter(N,wn);
y1=filter(b,a,y);
subplot(2,1,2)
plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));
audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_butter_worth_low_pass.wav',y1,fs)

DEPT OF ECE, BMSCE 3


Digital Signal Processing

Frequency Spectrum

low_pass.mp3

DEPT OF ECE, BMSCE 4


Digital Signal Processing

Butterworth High Pass Filters

Here we pass the signal through a Butterworth highpass filter in order to isolate the high
frequency noise.
The pass band and stop band edge frequencies are 5500 and 5000Hz respectively. The passband
attenuation is 1 dB and the stopband attenuation is 20dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
wp = 2*(5500*pi/fs);
ws = (2*5000*pi/fs);
[N,wn]= buttord(wp/pi,ws/pi,1,20)
[b,a]=butter(N,wn,’high’);
y1=filter(b,a,y);
subplot(2,1,2)
plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));
audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_butter_worth_high_pass.wav',y1,fs
)

DEPT OF ECE, BMSCE 5


Digital Signal Processing

Frequency Spectrum

high_pass.mp3

DEPT OF ECE, BMSCE 6


Digital Signal Processing

Butterworth Bandpass filter

Here we pass the signal through a Butterworth bandpass filter in order to reduce both bass and
treble and to increase the base.
The pass band and stop band edge frequencies are [2500,5500] and [2000,5000]Hz respectively.
The passband attenuation is 3 dB and the stopband attenuation is 20dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
wp = [2*(2500*pi/fs), 2*(5000*pi/fs)];

ws = [2*(2000*pi/fs), 2*(5500*pi/fs)];

[N,wn]= buttord(wp/pi,ws/pi,3,20)

[b,a]=butter(N,wn );

y1=filter(b,a,y);

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));

audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_butter_worth_pass.wav',y1,fs)

DEPT OF ECE, BMSCE 7


Digital Signal Processing

Frequency Spectrum

song_butter_worth_band_pass.mp3

DEPT OF ECE, BMSCE 8


Digital Signal Processing

Butterworth Band stop filter


Here we pass the signal through a Butterworth bandstop filter.
The pass band and stop band edge frequencies are [2500,5000] and [2000,5500]Hz
respectively.The passband attenuation is 1dB and the stopband attenuation is 15dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));

ws= [2*(2500*pi/fs), 2*(5000*pi/fs)];

wp = [2*(2000*pi/fs), 2*(5500*pi/fs)];

[N,wn]= buttord(wp/pi,ws/pi,3,20)

[b,a]=butter(N,wn ,'stop' );

y1=filter(b,a,y);

%y1 = y1(1:100000,:)

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));

audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_butter_worth_stop.wav',y1,fs)

DEPT OF ECE, BMSCE 9


Digital Signal Processing

Frequency Spectrum

song_butter_worth_band_stop.mp3

DEPT OF ECE, BMSCE 10


Digital Signal Processing

Chebyshev low pass filter


Here we pass the signal through a Chebyshev lowpass filter in order to extract the bass of the
signal as bass of the song is below to 250Hz.The pass band and stop band edge frequencies are
200 and 300 Hz respectively. The passband attenuation is 1 dB and the stopband attenuation is
20dB.To get the digital frequencies we divide the required frequencies by sampling frequency
and multiply by 2*pi.

Code:

[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
wp = 2*(200*pi/fs);
ws = (2*300*pi/fs);
[N,wn]= cheb1ord(wp/pi,ws/pi,1,20)
[b,a]=cheby1(N,1,wn);
y1=filter(b,a,y);
subplot(2,1,2)
plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));
audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_cheb_low_pass.wav',y1,fs)

DEPT OF ECE, BMSCE 11


Digital Signal Processing

Frequency Spectrum

cheb_low_pass.mp3

DEPT OF ECE, BMSCE 12


Digital Signal Processing

Chebyshev high pass filter


Here we pass the signal through a Chebyshev highpass filter in order to isolate the treble of the
song . The pass band and stop band edge frequencies are 5500 and 5000Hz respectively. The
passband attenuation is 1 dB and the stopband attenuation is 20dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
wp = 2*(5500*pi/fs);
ws = (2*5000*pi/fs);
[N,wn]= cheb1ord(wp/pi,ws/pi,1,20)
[b,a]=cheby1(N,1,wn,’high’);
y1=filter(b,a,y);
subplot(2,1,2)
plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));
audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_cheb _high_pass.wav',y1,fs)

DEPT OF ECE, BMSCE 13


Digital Signal Processing

Frequency Spectrum

cheb_high_pass.mp3

DEPT OF ECE, BMSCE 14


Digital Signal Processing

Chebyshev Band Pass filter


Here we pass the signal through a Butterworth chebyshev filter in order to reduce both bass and
treble and to increase the base.
The pass band and stop band edge frequencies are [2500,5500] and [2000,5000]Hz respectively.
The passband attenuation is 3 dB and the stopband attenuation is 20dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:

[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));

wp = [2*(2500*pi/fs), 2*(5000*pi/fs)];

ws = [2*(2000*pi/fs), 2*(5500*pi/fs)];

[N,wn]= cheb1ord(wp/pi,ws/pi,3,20)

[b,a]=cheby1(N,3.wn );

y1=filter(b,a,y);

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));

audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_cheb_band_pass.wav',y1,fs)

DEPT OF ECE, BMSCE 15


Digital Signal Processing

Frequency Spectrum :

cheb_band_pass.mp3

DEPT OF ECE, BMSCE 16


Digital Signal Processing

Chebyshev Band stop filter:


Here we pass the signal through a chebyshev bandstop filter.
The pass band and stop band edge frequencies are [2500,5000] and [2000,5500]Hz respectively.
The passband attenuation is 3dB and the stopband attenuation is 20dB.
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.
Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
ws= [2*(2500*pi/fs), 2*(5000*pi/fs)];

wp = [2*(2000*pi/fs), 2*(5500*pi/fs)];
[N,wn]= cheb1ord(wp/pi,ws/pi,3,20)
[b,a]=cheby1(N,wn ,'stop' );
y1=filter(b,a,y);

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));
audiowrite('C:\Users\Amith\Desktop\DSP_assignment\song_butter_worth_stop.wav',y1,fs)

DEPT OF ECE, BMSCE 17


Digital Signal Processing

cheb_band_stop.mp3

DEPT OF ECE, BMSCE 18


Digital Signal Processing

FIR Filters
Hanning Low pass
Here we pass the signal through a FIR Hanning lowpass filter in order to extract the bass of the
signal as bass of the song is below to 250Hz.
Having the cut-off frequency. To get the digital frequencies we divide the required frequencies
by sampling frequency and multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');
dt = 1/fs;
t = 0:dt:(length(y)*dt)-dt;
N=28;
wc=(2*250*pi)/fs;
h=fir1(N,wc/pi,hanning(N+1));
y1=filter(h,1,y);
audiowrite('C:\Users\Amith\Desktop\song_low_hanning.wav',y1,fs)
subplot(2,1,1)
plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));
subplot(2,1,2)
plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));

DEPT OF ECE, BMSCE 19


Digital Signal Processing

Frequency Spectrum

song_low_hanning.mp3

DEPT OF ECE, BMSCE 20


Digital Signal Processing

Hanning High Pass filter

Here we pass the signal through a FIR Hanning high pass filter in order to isolate the high
frequency noise. The higher cut-off frequency is of 5000Hz . To get the digital frequencies we
divide the required frequencies by sampling frequency and multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');

dt = 1/fs;

t = 0:dt:(length(y)*dt)-dt;

N=28;

wc=(2*5000*pi)/fs;

h=fir1(N,wc/pi,'high',hanning(N+1));

y1=filter(h,1,y);

audiowrite('C:\Users\Amith\Desktop\song_high_hanning.wav',y1,fs)

subplot(2,1,1)

plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));

DEPT OF ECE, BMSCE 21


Digital Signal Processing

Frequency Spectrum:

song_high_hanning.mp3

DEPT OF ECE, BMSCE 22


Digital Signal Processing

Hamming Low pass filter


Here we pass the signal through a FIR Hamming lowpass filter in order to extract the bass of the
signal as bass of the song is below to 250Hz.
Having the cut-off frequency To get the digital frequencies we divide the required frequencies by
sampling frequency and multiply by 2*pi.
The frequency spectrum is plotted.

Code:

[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');

dt = 1/fs;

t = 0:dt:(length(y)*dt)-dt;

N=40;

wc=(2*250*pi)/fs;

h=fir1(N,wc/pi,hamming(N+1));

y1=filter(h,1,y);

audiowrite('C:\Users\Amith\Desktop\song_low_hamming.wav',y1,fs)

subplot(2,1,1) plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)))

DEPT OF ECE, BMSCE 23


Digital Signal Processing

Frequency spectrum:

song_low_hamming.mp3

DEPT OF ECE, BMSCE 24


Digital Signal Processing

Hamming High Pass filter


Here we pass the signal through a FIR Hamming highpass filter in order to isolate the high
frequency noise.
The higher cut-off frequency is of 5000Hz .
To get the digital frequencies we divide the required frequencies by sampling frequency and
multiply by 2*pi.
The frequency spectrum is plotted.

Code:
[y,fs] = audioread('C:\Users\Amith\Downloads\song.mp3');

dt = 1/fs;

t = 0:dt:(length(y)*dt)-dt;

N=28;

wc=(2*5000*pi)/fs;

h=fir1(N,wc/pi,'high',hamming(N+1));

y1=filter(h,1,y);

audiowrite('C:\Users\Amith\Desktop\song_high_hamming.wav',y1,fs)

subplot(2,1,1)

plot(psd(spectrum.periodogram,y,'Fs',fs,'NFFT',length(y)));

subplot(2,1,2)

plot(psd(spectrum.periodogram,y1,'Fs',fs,'NFFT',length(y1)));

DEPT OF ECE, BMSCE 25


Digital Signal Processing

Frequency Spectrum :

song_high_hanning.mp3

DEPT OF ECE, BMSCE 26

You might also like