# 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.

Your filter impulse response will be samples of that function. Truncate it symmetrically to some finite length, and then apply a window on those samples. Windowing will help you achieve a much smoother response.

• Thank you for the answer @Fat32. It is a little bit at the margin of the original question, but is there some list or catalog of "well-know" kernel function for different filtering applications I could use as a reference for future work? – Sylvain Leroux Nov 28 '19 at 15:02
• There are dfferent filters and filter design techniques. You shold get experience into their characteristics and usage. A list won't help you. The basic filter design techniques ar 1-windowing (above), 2- impulse invariance, 3-bilinear transform, 4-Least Squares. The basic filter types are FIR and IIR. Basic filtering techniques are convolution, LCCDE or FFT domains... etc. – Fat32 Nov 28 '19 at 15:17
• I've edited your answer to add a link to the corresponding Wikipedia page (amusingly enough, I thought at first it was a typo for the word "sync" ;) – Sylvain Leroux Nov 28 '19 at 22:31
• oh thanks for the link... Note that the link is describing the continuous-time sinc functions, where as in digital filters we use the discrete-time counterpart, which is almost the same thing... – Fat32 Nov 28 '19 at 22:45