Skip to content

Commit

Permalink
Improve BandStopFilter docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iver56 committed Jan 9, 2024
1 parent 33fb5ef commit eec59c3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
25 changes: 25 additions & 0 deletions demo/generate_examples_for_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,31 @@ def generate_example(self):
return sound, transformed_sound, sample_rate


@register
class BandStopFilterExample(TransformUsageExample):
transform_class = BandStopFilter

def generate_example(self):
random.seed(42)
np.random.seed(42)
transform = BandStopFilter(
min_center_freq=2500.0,
max_center_freq=2500.0,
min_bandwidth_fraction=0.8,
max_bandwidth_fraction=0.8,
p=1.0,
)

sound, sample_rate = load_sound_file(
os.path.join(DEMO_DIR, "p286_011.wav"), sample_rate=None
)
sound = sound[..., int(0.5 * sample_rate) : int(2.9 * sample_rate)]

transformed_sound = transform(sound, sample_rate)

return sound, transformed_sound, sample_rate


@register
class LimiterExample(TransformUsageExample):
transform_class = Limiter
Expand Down
Binary file added docs/waveform_transforms/BandStopFilter.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 22 additions & 4 deletions docs/waveform_transforms/band_stop_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@ _Added in v0.21.0_

Apply band-stop filtering to the input audio. Also known as notch filter or
band reject filter. It relates to the frequency mask idea in the SpecAugment paper.
Center frequency gets picked in mel space, so it is
more aligned with human hearing, which is not linear. Filter steepness
(6/12/18... dB / octave) is parametrized. Can also be set for zero-phase filtering
(will result in a 6 dB drop at cutoffs).
Center frequency gets picked in mel space, so it is somewhat aligned with human hearing,
which is not linear. Filter steepness (6/12/18... dB / octave) is parametrized. Can also
be set for zero-phase filtering (will result in a 6 dB drop at cutoffs).

Applying band-stop filtering as data augmentation during model training can aid in
preventing overfitting to specific frequency relationships, helping to make the model
robust to diverse audio environments and scenarios, where frequency losses can occur.

## Input-output example

Here we input a speech recording and apply `BandStopFilter` with a center
frequency of 2500 Hz and a bandwidth fraction of 0.8, which means that the bandwidth in
this example is 2000 Hz, so the low frequency cutoff is 1500 Hz and the high frequency
cutoff is 3500 Hz. One can see in the spectrogram of the transformed sound that the band
stop filter has attenuated this frequency range. If you listen to the audio example, you
can hear that the timbre is different in the transformed sound than in the original.

![Input-output waveforms and spectrograms](BandStopFilter.webp)

| Input sound | Transformed sound |
|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|
| <audio controls><source src="../BandStopFilter_input.flac" type="audio/flac"></audio> | <audio controls><source src="../BandStopFilter_transformed.flac" type="audio/flac"></audio> |

# BandStopFilter API

Expand Down

0 comments on commit eec59c3

Please sign in to comment.