Skip to content

Commit 4f45737

Browse files
Merge pull request prathimacode-hub#1104 from theshredbox/main
Noise Reduction Filter
2 parents 7cf74b2 + 63b4e60 commit 4f45737

11 files changed

+707
-0
lines changed
Binary file not shown.
Binary file not shown.
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# 📢**NOISE REDUCTION FILTER**
2+
<p align="center">
3+
<img width="600" height="325" src="http://www.reactiongifs.com/r/ln1.gif">
4+
</p>
5+
There’s no single definition of audio noise, but in general, it’s background sounds such as fans, people talking, cars or trucks driving by, buzz from faulty audio wires, or other ambient noises that shouldn’t be in your audio.
6+
7+
## **WHAT IS NOISE REDUCTION**
8+
Noise Reduction can reduce constant background sounds such as hum, whistle, whine, buzz, and "hiss", such as tape hiss, fan noise or FM/webcast carrier noise. It is not suitable for individual clicks and pops, or irregular background noise such as from traffic or an audience.
9+
To use Noise Reduction, you need a region in the waveform that contains only the noise you want to reduce.
10+
<p align="center">
11+
<img width="625" height="250" src="https://i.stack.imgur.com/W2nwb.png">
12+
</p>
13+
14+
## 🔇 **Need of Noise Reduction**
15+
Noise reduction is the process of removing noise from a signal. Noise reduction techniques exist for audio and images.
16+
Noise reduction algorithms may distort the signal to some degree.
17+
Noise rejection is the ability of a circuit to isolate an undesired signal component from the desired signal component, as with common-mode rejection ratio.
18+
19+
## 📗**NOISE REDUCTION USING PYTHON**
20+
### **IMPLEMENTATION**
21+
In this particular we will be aiming to remove noise from BIRD AUDIO SAMPLES. The focus is to start to explore some techniques of preprocessing that can be used to improve bird detection models.
22+
23+
The following steps will be followed-
24+
1. Preprocessing: To read a audio file, optionally apply signal filtering techniques, and perform feature extraction (e.g. mfccs);
25+
2. Trainning a classification model based on features (TO DO);
26+
3. Evaluation: To test the trainned models over a split of the dataset (TO DO).
27+
28+
---
29+
30+
### **FILTRATION TECHNIQUES USED**
31+
1. Traditional log mel-spectogram.
32+
2. High-Pass Filtering: Reduces low frequencies, once bird sound are commonly present on high frequencies.
33+
34+
---
35+
36+
### ☑️**LIBRARIES USED**
37+
**LIBROSA**- librosa is a python package for music and audio analysis. It provides the building blocks necessary to create music information retrieval systems.
38+
https://librosa.org/doc/latest/index.html
39+
40+
## 📊**CODING WORKFLOW**
41+
42+
<p align="center">
43+
<img width="625" height="450" src="https://user-images.githubusercontent.com/36481036/194615115-0f7ef39d-94d8-44db-a752-f327158f1bbb.png">
44+
</p>
45+
46+
## 🎯**RESULTS**
47+
After applying and filtering low frequency filters, significant reduction in noise was observed from both the audios. The audios can be analyzed from the notebook mentioned in this repo.
48+
![filtering low-frequencies01](https://user-images.githubusercontent.com/36481036/194620984-3dc9f1fb-b037-4e46-ad15-cd8ae1966788.png)
49+
50+
![filtering low-frequencies02](https://user-images.githubusercontent.com/36481036/194620991-a818976e-7d05-4cc5-b023-108043c6487d.png)
51+
52+
53+
54+
## :page_facing_up: **CONCLUSION**
55+
* For both audio samples, the filter helped to isolate the interesting frequencies. The first audio is in a very good quality for distincting the birds.
56+
* The second audio still has some noise but significant improvements in noise reduction can be observed.
57+
58+
## :bust_in_silhouette: **CREDITS**
59+
* https://timsainburg.com/noise-reduction-python.html
60+
* https://mixkit.co/free-sound-effects/bird/
61+
62+
**:sunglasses:** **CREATOR**- https://github.com/theshredbox

BasicPythonScripts/Noise Reduction Filter/noise_reduction_filter.ipynb

+551
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# feature extraction and preprocessing data
2+
#IMPORT THE LIBRARIES
3+
import librosa
4+
import librosa.display
5+
import pandas as pd
6+
import numpy as np
7+
import scipy.signal
8+
import matplotlib.pyplot as plt
9+
from PIL import Image
10+
from pathlib import Path
11+
from pylab import rcParams
12+
rcParams['figure.figsize'] = 14, 6
13+
14+
import csv
15+
# Preprocessing
16+
from sklearn.model_selection import train_test_split
17+
from sklearn.preprocessing import LabelEncoder, StandardScaler
18+
#Reports
19+
from sklearn.metrics import classification_report, confusion_matrix
20+
21+
import warnings
22+
warnings.filterwarnings('ignore')
23+
24+
#READ THE AUDIO SAMPLES
25+
sr = 16000
26+
e_file1 = r'C:\Users\Aryan\PycharmProjects\Noise Reduction Filter\audio01.mp3'
27+
e_file2 = r'C:\Users\Aryan\PycharmProjects\Noise Reduction Filter\audio02.mp3'
28+
29+
# 10 seconds of each file
30+
y1,sr = librosa.load(e_file1, mono=True, sr=sr, offset=0, duration=10)
31+
y2,sr = librosa.load(e_file2, mono=True, sr=sr, offset=0, duration=10)
32+
33+
from IPython.display import Audio, IFrame, display
34+
35+
display(Audio(y1,rate=sr))
36+
display(Audio(y2,rate=sr))
37+
38+
#The audio samples used have high level background noises.
39+
librosa.display.waveplot(y1,sr=sr, color='g', x_axis='time');
40+
librosa.display.waveplot(y1,sr=sr, color='g', x_axis='time');
41+
42+
#Logmel-spectogram
43+
#It is a very common preprocessing technique in audio detection applications is to transform audios to its log mel-spectogram representation
44+
45+
S1 = librosa.feature.melspectrogram(y=y1, sr=sr, n_mels=64)
46+
D1 = librosa.power_to_db(S1, ref=np.max)
47+
librosa.display.specshow(D1, x_axis='time', y_axis='mel');
48+
49+
S2 = librosa.feature.melspectrogram(y=y2, sr=sr, n_mels=64)
50+
D2 = librosa.power_to_db(S2, ref=np.max)
51+
librosa.display.specshow(D2, x_axis='time', y_axis='mel');
52+
53+
#Filtering low-frequencies
54+
#A low-pass filter is a filter that passes signals with a frequency lower than a selected cutoff frequency and attenuates signals with frequencies higher than the cutoff frequency.
55+
#The exact frequency response of the filter depends on the filter design.
56+
57+
from scipy import signal
58+
import random
59+
60+
61+
def f_high(y,sr):
62+
b,a = signal.butter(10, 2000/(sr/2), btype='highpass')
63+
yf = signal.lfilter(b,a,y)
64+
return yf
65+
66+
yf1 = f_high(y1, sr)
67+
yf2 = f_high(y2, sr)
68+
69+
librosa.display.waveplot(y1,sr=sr, colour='p', x_axis='time');
70+
librosa.display.waveplot(yf1,sr=sr, x_axis='time');
71+
72+
librosa.display.waveplot(y2,sr=sr, x_axis='time');
73+
librosa.display.waveplot(yf2,sr=sr, x_axis='time');
74+
75+
Sf1 = librosa.feature.melspectrogram(y=yf1, sr=sr, n_mels=64)
76+
Df1 = librosa.power_to_db(Sf1, ref=np.max)
77+
librosa.display.specshow(Df1, x_axis='time', y_axis='mel');
78+
Sf2 = librosa.feature.melspectrogram(y=yf2, sr=sr, n_mels=64)
79+
Df2 = librosa.power_to_db(Sf2, ref=np.max)
80+
librosa.display.specshow(Df2, x_axis='time', y_axis='mel');
81+
82+
#Check the audio output
83+
display(Audio(yf1,rate=sr))
84+
display(Audio(yf2,rate=sr))
85+
86+
#CONCLUSION
87+
#For both audio samples, the filter helped to isolate the interesting frequencies. The first audio is in a very good quality for distincting the birds.
88+
#The second audio still has some noise but significant improvements in noise reduction can be observed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
librosa==0.8.1
2+
pandas==1.3.5
3+
numpy==1.21.5
4+
scipy==1.9.0
5+
matplotlib==3.6.0
6+
pillow==7.2.1

0 commit comments

Comments
 (0)