0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Dan Szabo Nov 28 '19 at 15:13
  • 1
    $\begingroup$ 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. $\endgroup$ – Dan Szabo Nov 28 '19 at 15:35
  • $\begingroup$ 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. $\endgroup$ – Sylvain Leroux Nov 28 '19 at 17:57
  • 1
    $\begingroup$ 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. $\endgroup$ – Dan Szabo Nov 28 '19 at 18:05
  • 1
    $\begingroup$ Cheers, hope it goes well for you $\endgroup$ – Dan Szabo Nov 28 '19 at 18:23
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Sylvain Leroux Nov 28 '19 at 15:02
  • 1
    $\begingroup$ 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. $\endgroup$ – Fat32 Nov 28 '19 at 15:17
  • $\begingroup$ 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" ;) $\endgroup$ – Sylvain Leroux Nov 28 '19 at 22:31
  • 1
    $\begingroup$ 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... $\endgroup$ – Fat32 Nov 28 '19 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.