Author Topic: [Math] [DSP] Low frequency filter at high sample rate  (Read 6175 times)

0 Members and 1 Guest are viewing this topic.

Offline blueskullTopic starter

  • Supporter
  • ****
  • !
  • Posts: 367
  • Country: cn
  • BA7LKP
[Math] [DSP] Low frequency filter at high sample rate
« on: September 02, 2017, 11:08:18 pm »
Don't know if I should post it here or in MCU section, but since it's more a math issue rather than the actual MCU/DSP implementation, I decided to post it here.

Is there a good way to implement a band pass equalizer at high sample rate? My goal is to have at least 50Hz frequency resolution at 192ksps sample rate.

The brutal way is to use delta F=50Hz, then taps=3.1*192000/50=12k, and I will need 12k MACs per sample to do this, or 2.3GMACs/s, which is silly. With supporting DSP architecture, I can probably reduce it to 1.25GMACs/s with folded structure.

Even with FFT convolution, let sample size=16k, padded to 32k, and filter size=12k, padded to 32k, then 2 32k FFTs and 1 32k IFFT need to be performed, ignoring the 32k dot product.
This calls for k*3*15*32768 MACs per 16k sample, or at 192ksps, that's 17.7M butterfly operations per second. Assuming k=3, then that's 53MMACs/s, or >100MMACs/s for stereo.

Is there a smarter way to do low frequency equalization on high sample rate? My target is 50MMACs/s max for stereo. The target is BlackFin+ running at 396MHz.

*: Resampling is not an option. 192k is a must. Linear phase or at least minimum phase is a must.
 

Offline cdev

  • Super Contributor
  • ***
  • !
  • Posts: 7350
  • Country: 00
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #1 on: September 02, 2017, 11:53:59 pm »
You might be able to glean something from Linrad, the SDR app's code...  It is able to get very high resolution FFT out of a 192 khz window (sound card used for sampling)

http://sm5bsz.com

http://sm5bsz.com/linuxdsp/linrad.htm
"What the large print giveth, the small print taketh away."
 

Offline bson

  • Supporter
  • ****
  • Posts: 2265
  • Country: us
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #2 on: September 03, 2017, 12:48:59 am »
I would just decimate the sample data to some reasonable rate, say 4-5x the signal of interest up front.  Using a boxcar filter, moving average, or whatever is easy to implement.  It doesn't terribly matter.  If you get 200kS/s for a 50Hz signal just collect groups 1000 samples, average them, and use that as a 200S/s acquisition, then low- or bandpass that for 50Hz.
 

Offline ruairi

  • Frequent Contributor
  • **
  • Posts: 302
  • Country: us
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #3 on: September 03, 2017, 03:14:07 am »
Linear phase or at least minimum phase is a must.

Even without knowing the application I can that you absolutely do not want to be using a Linear Phase filter on audio at 50Hz, it will sound horrific.

 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7660
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #4 on: September 03, 2017, 03:34:22 am »
1 dirty trick to simplify this one out if you don't need such a narrow band FIR/FFT grade response.
Think about feeding your sample through a simulated RLC filter.  You'll cut your processing power and ram down to nothing but a few words...
Though, if you want to mix a + or - % the results with your source audio, like making a bass adjustment knob, you will need to resolve the optimum group delay, and the ram requirements will go up but processing will be nil compared to all those multiply adds in a full filter.

Depending on the app, IE eliminate DC from the source audio, or a POP filter, this can be effective.  Creating a multi band EQ with a bunch of these might not be so refined going above 3-5 channels.

You will of course not get the perfect quality of a true FIR filter.

Another dirty trick, as for ultra-sonic filter, a simple 2 or 4 +/- multiply add on the digital audio with 88.2Khz and above source will remove any sound above 22Khz, or 24Khz for the 96Khz variants.
« Last Edit: September 03, 2017, 03:49:14 am by BrianHG »
 
The following users thanked this post: blueskull

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7660
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #5 on: September 03, 2017, 04:08:36 am »
If you are using such a filter as a bottom shelf filter.  IE, going from approx 50hz down to 0hz, it shouldn't be too bad.  If you want a band centered at 50hz, +/- 20hz, it wont be good.  A simple RC simulated filter should meet audiophile spec as it doesn't bend phase of your source signals at different frequencies.  But, it has a really low Q, a wide smooth slope.  RLC has a much better Q factor, but, we know how that one can shift the phase of different frequencies fed in messing up the quality of the final output waveform.

I wonder what the response would be like to feed multiple RC filters in series?  Does it sharpen the response slope, improving the Q?
 

Offline ruairi

  • Frequent Contributor
  • **
  • Posts: 302
  • Country: us
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #6 on: September 03, 2017, 05:07:07 am »
From a marketing standpoint, introducing IIR filter in audible range is not that acceptable by audiophile community.
But thanks, I will investigate into it, and if I really can find any evidence that an IIR sounds better in this case, I will use it.

There's so much I could write on this topic.

Do you ever travel to Los Angeles? 

 

Offline jahonen

  • Super Contributor
  • ***
  • Posts: 1052
  • Country: fi
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #7 on: September 03, 2017, 09:51:32 am »
I would consider if the phase-linear equalizer even makes sense or is desirable.

I think for audio applications, minimum-phase type (which is just old plain IIR biquad) would be more appropriate, since a minimum-phase system can be used to transform a minimum-phase system into another minimum-phase system (e.g. equalizer zeros cancel the original system poles and introduce new desired poles). This is the case for example for the "Linkwitz transform". Using linear phase makes no sense at all for that kind of application.

I know, linear phase sounds nice but it is not always better than computationally much cheaper system.

Regards,
Janne
 

Offline ruairi

  • Frequent Contributor
  • **
  • Posts: 302
  • Country: us
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #8 on: September 03, 2017, 04:21:44 pm »

Just like many other small audio gear developers, I don't have the resource to do acoustic and psychological research.
What I'm good at is engineering, and the way I roll my product is to copy ideas and specs from other products, and use my engineering knowledge to make the specs better than competitors.
I'm a good electronics engineer, but I know nothing about acoustic-psychology.

Do you ever travel to Los Angeles?

Would like to have a chance to do so.

Please don't take my questioning of your ideas as a critique of your engineering abilities.  I've been here a little while and know what you are capable of. 

I've been a mastering engineer for 16 years and I spend all day every day listening and comparing.  I have set up thousands of speakers, and listened to most every high end audio DAC available in the pro space.  EQ is my most fundamental tool in the studio and again I've heard most every topology and implementation.

The pre-ringing of the filters in linear phase EQs is a huge problem at lower and mid frequencies.  Further, as Jahonen alluded to below most of the real world problems that we are trying to fix with EQ are minimum phase problems and need minimum phase corrections.  The issues that aren't minimum phase cannot be correct by any eq and are typically caused by room acoustics summation issues.

This start of this video will give you a quick example of how pre-ringing can damage our perception of music -
 
The following users thanked this post: blueskull

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #9 on: September 03, 2017, 04:37:22 pm »
Sounds like something requiring multirate processing and filtering. Decimate by 2 for each stage for octave band processing and you can use same filter coefficients for the filters across bands, use FIR or IIR filters for the equalizers. Interpolate back to the original sample rate. Adjust for the delay introduced by decimation and interpolation. Simulate using Octave/Matlab. Use at least 24-bit samples and coefficients.

Book "Digital Audio Signal Processing" by Udo Zölzer is quite good text about the subject containing a section about Equalizers and multirate processing.
« Last Edit: September 03, 2017, 04:54:02 pm by Kalvin »
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #10 on: September 04, 2017, 03:14:21 am »
Simpy, you can't. The most efficient way would be to run 2 FFT and  2 iFFT with 50% overlapping. 
FIR absolutely out of scope, to have 50 Hz resolution with such high sampling rate the size of the filter kernel (number of coeff.) should go well above 1k. That means 1000 MAC x 12 000 filters for Each sample.

 FFT is always linear, you can't have log frequency scale.

So, this boils down instead of 12 k linearly spaced,  to create just  5-7 FIR filters in parametric mode, when you can adjust freq. response, and tune each filter to exact freq. of interests.  I can't imagine audio content, that demands more than that for freq. equalization.
 

Offline ruairi

  • Frequent Contributor
  • **
  • Posts: 302
  • Country: us
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #11 on: September 04, 2017, 05:35:02 am »
Can you tell us the feature set you are aiming for?  From a control point of view as the end user would experience it?
 

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 1876
  • Country: us
    • KE5FX.COM
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #12 on: September 04, 2017, 05:49:32 am »
Simpy, you can't. The most efficient way would be to run 2 FFT and  2 iFFT with 50% overlapping. 
FIR absolutely out of scope, to have 50 Hz resolution with such high sampling rate the size of the filter kernel (number of coeff.) should go well above 1k. That means 1000 MAC x 12 000 filters for Each sample.

 FFT is always linear, you can't have log frequency scale.

Surprisingly enough there are some exceptions to that.  There exists a Logarithmic Fourier Transform (see Jason H.'s answer at https://stackoverflow.com/questions/1120422/is-there-an-fft-that-uses-a-logarithmic-division-of-frequency for a .PDF link), along with various wavelet techniques. 

Not sure what to expect in terms of sound quality, since I've barely heard of this transform myself.   :popcorn:
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7660
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #13 on: September 04, 2017, 07:22:31 am »
So, this boils down instead of 12 k linearly spaced,  to create just  5-7 FIR filters in parametric mode, when you can adjust freq. response, and tune each filter to exact freq. of interests.

The problem is the low end, for a LPF at 50Hz, you need at least 50Hz resolution (and use the lowest bin), and FIR is inherently linear, not logarithmic. That means to get 50Hz to work, I have to anyway build 3.84k bins at 192ksps (3.84k bins means 12k taps for Hanning window).
I can get around with a few short IIRs, but then how the phase delay will react is open to debate.

This can be compensated for by just using the appropriate delay factor when summing your filtered signal with the source audio, so long as your filter doesn't have any positive amplified gain within it.  Post mixing a +/-% of the filter's output with the delayed source audio doesn't count.  However, such a 50hz filter will not be narrow band.  If you want anything with FIR performance, your stuck with 3.84k bins.
 
Simple sum-averaging the source audio into a 3.84k buffer, mixing a % of that result with the center sample in the buffer at the 1.92k point will give you an in-phase audiophile grade 0-50hz bin which you can add or subtract basically what you would call very low bass.
Within that 3.84k buffer, keep track of the center 1.92k samples as well making a second average would give you a 0-100hz bin.  Subtract out the 0-50hz bin from 0-100hz bin, and you will have a 100hz +/- 50hz bin.  This is an all integer equalizer which can be done in a small DSPIC with ease.

With this, you now have the processing power to create a 25hz filter as well as any other odd low frequency like 35hz, 36hz, 37hz, ect.  You are no longer tied to exact multiple of your sample rate except for higher frequencies...

Sort of like the opposite problem to a FIR filter...

Now, when averaging, remember that 3840 * 2^16bit fits within a 32 bit integer.
Now, when averaging, remember that 3840 * 2^24 is more than a 32 bit integer.

Processing these averages in floating point solves this issue but introduces floating rounding errors.

This is how to make a super low processing power EQ, but, be warned that when applying a +%, you don't exceed the upper and lower sample limits of your variables bit depth.
Also, applying too much negative % (IE, lowering the BASS), you will go past lowering the bass to inverting the bass, then negatively amplifying it at -180 degrees to a n out of control level.

If you are creating a high pass filter, EG - DC removal/correction, you don't need the delay, but tune your filter for VLF.
« Last Edit: September 04, 2017, 07:26:25 am by BrianHG »
 

Offline ruairi

  • Frequent Contributor
  • **
  • Posts: 302
  • Country: us
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #14 on: September 04, 2017, 08:16:04 am »
Can you tell us the feature set you are aiming for?  From a control point of view as the end user would experience it?

The basic thing is the DAC itself, basically I want to implement an SDM DAC from scratch so that I can apply some tricks that can't be economically applied with integrated SDM DACs………

I'm targeting audiophile market more than pro-audio market, but I certainly want to make a reputation in pro-audio market.

Thanks for the breakdown. 
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #15 on: September 04, 2017, 09:50:17 am »
Surprisingly enough there are some exceptions to that.  There exists a Logarithmic Fourier Transform (see Jason H.'s answer at https://stackoverflow.com/questions/1120422/is-there-an-fft-that-uses-a-logarithmic-division-of-frequency for a .PDF link), along with various wavelet techniques. 

Not sure what to expect in terms of sound quality, since I've barely heard of this transform myself.   :popcorn:

It would not be surprise to me, to find a few links on google, that says a square wheel was invented. Sorry, not going to waste my time to read such nonsense, same apply to wavelets or log FFT.
 

Online chris_leyson

  • Super Contributor
  • ***
  • Posts: 1541
  • Country: wales
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #16 on: September 04, 2017, 10:22:06 am »
You might want to look at "Multirate Signal Processing" by Fred Harris
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #17 on: September 04, 2017, 10:38:54 am »
I have to anyway build 3.84k bins at 192ksps (3.84k bins means 12k taps for Hanning window).
Your math is a mystery, my understanding 3.84k is 192000/ 50, but where did you get 12k?
Running FFT approach with size 4096, gets 192 000 /4096 = 46.875 Hz resolution per bin. DSP processing requirements close to: 2 (stereo) x 2 (forward) x  2(reverse) x 2 MAC/ sample (butterfly) = 16 MAC/ sample, or 192 000 x 16 = 3072 000 MAC / second. 3 Mega, not 17 or 50M or 2.3 G
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: [Math] [DSP] Low frequency filter at high sample rate
« Reply #18 on: September 04, 2017, 04:44:53 pm »
Your math is a mystery, my understanding 3.84k is 192000/ 50, but where did you get 12k?
Running FFT approach with size 4096, gets 192 000 /4096 = 46.875 Hz resolution per bin. DSP processing requirements close to: 2 (stereo) x 2 (forward) x  2(reverse) x 2 MAC/ sample (butterfly) = 16 MAC/ sample, or 192 000 x 16 = 3072 000 MAC / second. 3 Mega, not 17 or 50M or 2.3 G

12 is scaled from 3.84 with a factor from 3-4, which is main lobe size of window function.

In your computational complexity calculation, did you forget the lg(n) term?
Still can't get how windowing function comes in perspective, it doesn't use accumulate, only multiply 1 sample by 1 coeff. Factor 1 perhaps? There is some overhead, but less than 10% of the main processing subroutine.

No, I didn't forget log(N), because it's rough approximation. Real value of the last term in formula (MAC/ sample)  may vary  depends on the kind of FFT, as low as 2.2-2.3 for Split-Radix-9, and 2.5-3 for Radix-4.  I've being measuring this "bottle neck" operation for ARM cortex-3 uCPU for a long time, since hardware doesn't have DSP support and floating point co-processor.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf