-
-
Notifications
You must be signed in to change notification settings - Fork 264
Noise Reduction Filter #1104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Noise Reduction Filter #1104
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file added
BasicPythonScripts/Noise Reduction Filter/Images/logmel-spectogram.png
Binary file added
BasicPythonScripts/Noise Reduction Filter/Images/waveplot.png
Binary file added
BasicPythonScripts/Noise Reduction Filter/Images/workflow.png
62 changes: 62 additions & 0 deletions
BasicPythonScripts/Noise Reduction Filter/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 📢**NOISE REDUCTION FILTER** | ||
<p align="center"> | ||
<img width="600" height="325" src="http://www.reactiongifs.com/r/ln1.gif"> | ||
</p> | ||
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. | ||
|
||
## ❓ **WHAT IS NOISE REDUCTION** | ||
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. | ||
To use Noise Reduction, you need a region in the waveform that contains only the noise you want to reduce. | ||
<p align="center"> | ||
<img width="625" height="250" src="https://i.stack.imgur.com/W2nwb.png"> | ||
</p> | ||
|
||
## 🔇 **Need of Noise Reduction** | ||
Noise reduction is the process of removing noise from a signal. Noise reduction techniques exist for audio and images. | ||
Noise reduction algorithms may distort the signal to some degree. | ||
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. | ||
|
||
## 📗**NOISE REDUCTION USING PYTHON** | ||
### **IMPLEMENTATION** | ||
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. | ||
|
||
The following steps will be followed- | ||
1. Preprocessing: To read a audio file, optionally apply signal filtering techniques, and perform feature extraction (e.g. mfccs); | ||
2. Trainning a classification model based on features (TO DO); | ||
3. Evaluation: To test the trainned models over a split of the dataset (TO DO). | ||
|
||
--- | ||
|
||
### **FILTRATION TECHNIQUES USED** | ||
1. Traditional log mel-spectogram. | ||
2. High-Pass Filtering: Reduces low frequencies, once bird sound are commonly present on high frequencies. | ||
|
||
--- | ||
|
||
### ☑️**LIBRARIES USED** | ||
**LIBROSA**- librosa is a python package for music and audio analysis. It provides the building blocks necessary to create music information retrieval systems. | ||
https://librosa.org/doc/latest/index.html | ||
|
||
## 📊**CODING WORKFLOW** | ||
|
||
<p align="center"> | ||
<img width="625" height="450" src="https://user-images.githubusercontent.com/36481036/194615115-0f7ef39d-94d8-44db-a752-f327158f1bbb.png"> | ||
</p> | ||
|
||
## 🎯**RESULTS** | ||
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. | ||
 | ||
|
||
 | ||
|
||
|
||
|
||
## :page_facing_up: **CONCLUSION** | ||
* 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. | ||
* The second audio still has some noise but significant improvements in noise reduction can be observed. | ||
|
||
## :bust_in_silhouette: **CREDITS** | ||
* https://timsainburg.com/noise-reduction-python.html | ||
* https://mixkit.co/free-sound-effects/bird/ | ||
|
||
**:sunglasses:** **CREATOR**- https://github.com/theshredbox |
551 changes: 551 additions & 0 deletions
BasicPythonScripts/Noise Reduction Filter/noise_reduction_filter.ipynb
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
BasicPythonScripts/Noise Reduction Filter/noise_reduction_filter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# feature extraction and preprocessing data | ||
#IMPORT THE LIBRARIES | ||
import librosa | ||
import librosa.display | ||
import pandas as pd | ||
import numpy as np | ||
import scipy.signal | ||
import matplotlib.pyplot as plt | ||
from PIL import Image | ||
from pathlib import Path | ||
from pylab import rcParams | ||
rcParams['figure.figsize'] = 14, 6 | ||
|
||
import csv | ||
# Preprocessing | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.preprocessing import LabelEncoder, StandardScaler | ||
#Reports | ||
from sklearn.metrics import classification_report, confusion_matrix | ||
|
||
import warnings | ||
warnings.filterwarnings('ignore') | ||
|
||
#READ THE AUDIO SAMPLES | ||
sr = 16000 | ||
e_file1 = r'C:\Users\Aryan\PycharmProjects\Noise Reduction Filter\audio01.mp3' | ||
e_file2 = r'C:\Users\Aryan\PycharmProjects\Noise Reduction Filter\audio02.mp3' | ||
|
||
# 10 seconds of each file | ||
y1,sr = librosa.load(e_file1, mono=True, sr=sr, offset=0, duration=10) | ||
y2,sr = librosa.load(e_file2, mono=True, sr=sr, offset=0, duration=10) | ||
|
||
from IPython.display import Audio, IFrame, display | ||
|
||
display(Audio(y1,rate=sr)) | ||
display(Audio(y2,rate=sr)) | ||
|
||
#The audio samples used have high level background noises. | ||
librosa.display.waveplot(y1,sr=sr, color='g', x_axis='time'); | ||
librosa.display.waveplot(y1,sr=sr, color='g', x_axis='time'); | ||
|
||
#Logmel-spectogram | ||
#It is a very common preprocessing technique in audio detection applications is to transform audios to its log mel-spectogram representation | ||
|
||
S1 = librosa.feature.melspectrogram(y=y1, sr=sr, n_mels=64) | ||
D1 = librosa.power_to_db(S1, ref=np.max) | ||
librosa.display.specshow(D1, x_axis='time', y_axis='mel'); | ||
|
||
S2 = librosa.feature.melspectrogram(y=y2, sr=sr, n_mels=64) | ||
D2 = librosa.power_to_db(S2, ref=np.max) | ||
librosa.display.specshow(D2, x_axis='time', y_axis='mel'); | ||
|
||
#Filtering low-frequencies | ||
#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. | ||
#The exact frequency response of the filter depends on the filter design. | ||
|
||
from scipy import signal | ||
import random | ||
|
||
|
||
def f_high(y,sr): | ||
b,a = signal.butter(10, 2000/(sr/2), btype='highpass') | ||
yf = signal.lfilter(b,a,y) | ||
return yf | ||
|
||
yf1 = f_high(y1, sr) | ||
yf2 = f_high(y2, sr) | ||
|
||
librosa.display.waveplot(y1,sr=sr, colour='p', x_axis='time'); | ||
librosa.display.waveplot(yf1,sr=sr, x_axis='time'); | ||
|
||
librosa.display.waveplot(y2,sr=sr, x_axis='time'); | ||
librosa.display.waveplot(yf2,sr=sr, x_axis='time'); | ||
|
||
Sf1 = librosa.feature.melspectrogram(y=yf1, sr=sr, n_mels=64) | ||
Df1 = librosa.power_to_db(Sf1, ref=np.max) | ||
librosa.display.specshow(Df1, x_axis='time', y_axis='mel'); | ||
Sf2 = librosa.feature.melspectrogram(y=yf2, sr=sr, n_mels=64) | ||
Df2 = librosa.power_to_db(Sf2, ref=np.max) | ||
librosa.display.specshow(Df2, x_axis='time', y_axis='mel'); | ||
|
||
#Check the audio output | ||
display(Audio(yf1,rate=sr)) | ||
display(Audio(yf2,rate=sr)) | ||
|
||
#CONCLUSION | ||
#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. | ||
#The second audio still has some noise but significant improvements in noise reduction can be observed. |
6 changes: 6 additions & 0 deletions
BasicPythonScripts/Noise Reduction Filter/requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
librosa==0.8.1 | ||
pandas==1.3.5 | ||
numpy==1.21.5 | ||
scipy==1.9.0 | ||
matplotlib==3.6.0 | ||
pillow==7.2.1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.