Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
prathimacode-hub merged 4 commits into prathimacode-hub:main from theshredbox:main
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
View file Open in desktop
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[フレーム]
62 changes: 62 additions & 0 deletions BasicPythonScripts/Noise Reduction Filter/README.md
View file Open in desktop
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.
![filtering low-frequencies01](https://user-images.githubusercontent.com/36481036/194620984-3dc9f1fb-b037-4e46-ad15-cd8ae1966788.png)

![filtering low-frequencies02](https://user-images.githubusercontent.com/36481036/194620991-a818976e-7d05-4cc5-b023-108043c6487d.png)



## :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
View file Open in desktop

Large diffs are not rendered by default.

View file Open in desktop
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /