Completly cut a frequency range

Questions involving a Windows version of FFmpeg.
Djketley
Posts: 8
Joined: Sat May 25, 2019 1:20 am

Completly cut a frequency range

Post by Djketley » Thu Jul 04, 2019 4:52 pm

Hey fourm!

Im trying to completely cut a frequency range of around 100hz in an audio file but im getting bleed or not a completle cut. i've tried a sinc filter which still gives me bleed. I tried a bandreject which does work but is inverted ive attached a image to deomonstrate what i mean with regards to the band reject.

Blue should contain audio and the audio should be blue.

Command used (it's in a c# project so excuse the crudeness)

var arguments = "-i \"" + input + "\" -c:a pcm_s16le -af \"bandreject=f=" + startFrequency + ":width_type=o:w=-100\" \"" + output + "\" -y";
Attachments
Untitled.png
Untitled.png (913.82 KiB) Viewed 534 times

pandy
Posts: 200
Joined: Mon Feb 24, 2014 1:46 pm

Re: Completly cut a frequency range

Post by pandy » Thu Jul 04, 2019 6:37 pm

Accordingly to https://ffmpeg.org/ffmpeg-filters.html#bandreject this is simple IIR "Butterworth like" filter - don't expect too much. You have two options, or stack few times bandreject filter with same parameters - this is common way solving this problem in digital domain (it is better to avoid higher order IIR filters in DSP) or use different type of filter https://ffmpeg.org/ffmpeg-filters.html#firequalizer . This filter offer way more possibilities than simple IIR.

btw

bandreject should be correctly names bandstop filter - in your case f=100 and width should be sufficiently wide to remove signal around your f (i.e. 100Hz).

try something like: bandreject=f=100:h=Hz:w=10 i.e. center freq f=100, h=Hz - units for w width are Hz, w=10 - 10Hz so filter should remove frequencies between 95 and 105Hz

Djketley
Posts: 8
Joined: Sat May 25, 2019 1:20 am

Re: Completly cut a frequency range

Post by Djketley » Fri Jul 05, 2019 5:26 pm

Thanks for your help i chained a bandpass filter like 100 times but it still couldn't completly cut the frequency range so looking in to fireeq sorry to be a pain do you happen to have an example of a frequency cut im fairly new to the FFMPEG scence i've moved from SoX and purely using Ableton.

pandy
Posts: 200
Joined: Mon Feb 24, 2014 1:46 pm

Re: Completly cut a frequency range

Post by pandy » Fri Jul 05, 2019 9:00 pm

Djketley wrote:
Fri Jul 05, 2019 5:26 pm
Thanks for your help i chained a bandpass filter like 100 times but it still couldn't completly cut the frequency range so looking in to fireeq sorry to be a pain do you happen to have an example of a frequency cut im fairly new to the FFMPEG scence i've moved from SoX and purely using Ableton.
Luckily to us filters behaviour doesn't change despite ffmpeg developers efforts - to cut very narrow area you need or very long (tap) FIR or perhaps better FFT>iFFT (more predictable latency) . I think firequalizer will be the best possible choice but other options exist - they may be more suitable for other tasks:

https://ffmpeg.org/ffmpeg-filters.html#aiir - you can design own filter (for example eliptic a.k.a Cauer is most narrow one in exchange with nasty pulse response) - pole coefficients can be calculated with available free (even on-line) IIR calculators.

same approach for FIR filter https://ffmpeg.org/ffmpeg-filters.html#afir-1 - free calculators exist

FFT approach https://ffmpeg.org/ffmpeg-filters.html#afftfilt

And last https://ffmpeg.org/ffmpeg-filters.html#showspectrum-1 with https://ffmpeg.org/ffmpeg-filters.html#spectrumsynth - in theory you can filter signal by manipulating pixels (graphic editor required)

richardpl
Posts: 54
Joined: Sat Aug 01, 2015 6:35 pm

Re: Completly cut a frequency range

Post by richardpl » Sat Jul 06, 2019 10:14 am

pandy wrote:
Thu Jul 04, 2019 6:37 pm
bandreject should be correctly names bandstop filter
No, that are synonyms.

richardpl
Posts: 54
Joined: Sat Aug 01, 2015 6:35 pm

Re: Completly cut a frequency range

Post by richardpl » Sat Jul 06, 2019 10:15 am

pandy wrote:
Fri Jul 05, 2019 9:00 pm
Luckily to us filters behaviour doesn't change despite ffmpeg developers efforts
What does this even means?

pandy
Posts: 200
Joined: Mon Feb 24, 2014 1:46 pm

Re: Completly cut a frequency range

Post by pandy » Sat Jul 06, 2019 4:51 pm

richardpl wrote:
Sat Jul 06, 2019 10:14 am
No, that are synonyms.
Hahaha, only for developers. You have only 5 types of filters - allpass, bandpass, bandstop, lowpass and highpass - in electronics band-reject is practically not used (never from practical perspective) - that's all - so dictionary you are correct, reject is rarely used.
btw - after while i realize that you may feel like offended by my comment, it was not my intention to offend - simply being HW guy and having opportunity to talk with SW people i see that they think in different way thus frequently use own terminology - i think this example of this.

Djketley
Posts: 8
Joined: Sat May 25, 2019 1:20 am

Re: Completly cut a frequency range

Post by Djketley » Mon Jul 08, 2019 7:13 pm

Thanks for your help it seems FireEQ is the way to go its able to completely cut the audio im just having issues making it select a range at the moment. here is my input command:

-i "audio_engine_output\83e512c7-7ee9-4fb2-8e41-55435a5fcd08\notch_sample\cut1.wav" -c:a pcm_s16le -af "firequalizer=gain_entry='entry(4618, -180); entry(4619, -180)'" "audio_engine_output\83e512c7-7ee9-4fb2-8e41-55435a5fcd08\cut1.wav" -y

Perhaps i miss understand the documentation.

pandy
Posts: 200
Joined: Mon Feb 24, 2014 1:46 pm

Re: Completly cut a frequency range

Post by pandy » Mon Jul 08, 2019 7:49 pm

assuming your other questions are still valid and you searching for bandstop filter 10Hz wide and frequency centre 100Hz
check something like this:

Code: Select all

firequalizer=gain_entry='entry(15,-INF); entry(20,0); entry(94,0); entry(95, -INF); entry(105, -INF); entry(106,0); entry(22000,0); entry(23000, -INF)'
explanation (not tested, using firfilter in different way as bandpass):
entry(15,-INF) - all signal till 15Hz -Infinity (null);
entry(20,0) - at 20Hz no attenuation (so between 15 and 20Hz attenuation linearly going from -inf to 0 where 0 means signal is not altered)
entry(94,0) - at 94Hz signal unaltered
entry(95, -INF) at 95Hz signal going to -inf
entry(105, -INF) at 105Hz -inf
entry(106,0) at 106Hz signal unaltered
entry(22000,0) at 22000Hz signal unaltered
entry(23000, -INF)' from from 22000 to 23000 slope and at 23000Hz signal is -inf

so primitive drawing is like 0Hz(DC)___15/------94\95___105/106-------------22k\23k_24k
Personally i would relax transition area - 1Hz is pretty sharp and push FIR to very long.
FFT 4096pt should be still best way to do this.

Djketley
Posts: 8
Joined: Sat May 25, 2019 1:20 am

Re: Completly cut a frequency range

Post by Djketley » Mon Jul 08, 2019 10:07 pm

pandy wrote:
Mon Jul 08, 2019 7:49 pm
assuming your other questions are still valid and you searching for bandstop filter 10Hz wide and frequency centre 100Hz
check something like this:

Code: Select all

firequalizer=gain_entry='entry(15,-INF); entry(20,0); entry(94,0); entry(95, -INF); entry(105, -INF); entry(106,0); entry(22000,0); entry(23000, -INF)'
explanation (not tested, using firfilter in different way as bandpass):
entry(15,-INF) - all signal till 15Hz -Infinity (null);
entry(20,0) - at 20Hz no attenuation (so between 15 and 20Hz attenuation linearly going from -inf to 0 where 0 means signal is not altered)
entry(94,0) - at 94Hz signal unaltered
entry(95, -INF) at 95Hz signal going to -inf
entry(105, -INF) at 105Hz -inf
entry(106,0) at 106Hz signal unaltered
entry(22000,0) at 22000Hz signal unaltered
entry(23000, -INF)' from from 22000 to 23000 slope and at 23000Hz signal is -inf

so primitive drawing is like 0Hz(DC)___15/------94\95___105/106-------------22k\23k_24k
Personally i would relax transition area - 1Hz is pretty sharp and push FIR to very long.
FFT 4096pt should be still best way to do this.
Thank you for your explanation you have been super helpfull. It would probably help if you understood the context in which this is needed for:

Im developing a system to watermark audio using complete frequecny cuts cutting 100hz at the most dominant frequency then using showspectrum and image recognition based on the those cuts im able to generate an id thats matched in my database the cuts only last for 0.3 seconds (ideally trying to be inaudable but still visible in the spectrum using high res images) ive been having success with simply using sinc filters but they have been unable to cut the audio comepletely and if the audio is piticularly noisy in the area selected for the watermark the cuts are even less visible. Ideally the cuts need to be -180db (giving me a black spot on the spectrum). I come from C# world and not so much the audio world so its been a learning curve but you guy's have been extremely helpful. Im going to experiment with your response and hopefully it solves my issue. After that id ideally like to make some kind of warpper class for ffmpeg to remove the use of the exe.

Post Reply
'