# How to chose a kernel function for a FIR low pass filter in audio processing?

As the answer of a previous question, I was suggested to use a FIR filter to act as a low-pass filter to reconstruct the envelope of a sound wave (edited, emphasis mine):

As I said in a comment, you can get the envelope of a signal by running it through a lowpass filter

[...]

1. Implement a lowpass filter (FIR) by creating a filter kernel of appropriate length M (h(M) ). Note that your FIR filter (sin(x)/x) should normally be multiplied by a window function (e.g Hamming, Blackman, etc).

2. Convolve your signal with the filter kernel.

[...]

I'm having a hard time choosing/finding a proper filter kernel function. The quote above suggests sin(x)/x. Is this a standard kernel function? Does it have some magic properties that make it particularly suitable? What should I check if I consider another kernel function?

• I’d like to add that a Hilbert Transform can be implemented as two FIR filters, one for complex and one for real. The recommended approach that you are describing is used in AM demodulation. It works well when the bandwidth of the envelope is small relative to the carrier frequency. For audio, this is not the case so your output will likely be fairly distorted relative to the true envelope. – Dan Szabo Nov 28 '19 at 15:13
• My apologies, I misspoke. Check this link: en.m.wikipedia.org/wiki/Analytic_signal. It relates the analytic signal to the sum of a signal with its imaginary hilbert transform. The amplitude of that complex number is equal to the instantaneous envelope. – Dan Szabo Nov 28 '19 at 15:35
• Thanks for the comments @Dan. I must admit, with some efforts, I can mostly follow the maths in the link you've provided. But I must admit I don't see exactly how to apply that on the discrete data from my stream of samples. Especially since I need to maintain the computational complexity low for performance reasons. I suppose I still have to study more about the topic. – Sylvain Leroux Nov 28 '19 at 17:57
• What luck! I found this quite quickly: gaussianwaves.com/2017/04/…. I skimmed it, and it looks like a really good article, but it also provides several examples of how to do it. FWIW, I’d estimate that the computational complexity for the hilbert transform would be comparable to a windowed sinc FIR, depending on how precise the Hilbert kernel or aggressive the sinc is. – Dan Szabo Nov 28 '19 at 18:05
• Cheers, hope it goes well for you – Dan Szabo Nov 28 '19 at 18:23

Yes the sinc kernel $$h[n] = \frac{\sin(\omega_c n)}{\pi n}$$ is the theoretical result for the ideal lowpass brickwall filter whose gain is one and cutoff frequency is $$\omega_c$$ radian per samples.