0

First of I am very new to python. I am trying to write a script where I would feed a voice recording into it, internally apply an eq and have the modified signal returned. Researching the topic I found some ways to process a signal via transfer functions in python, however I only found functions like a low-pass filter etc. which would not fit my needs as I have a specific eq manipulation in mind. I constructed the required filter curve eq in audacity: The needed filter curve constructed in Audacity

If my limited understanding of signal processing is correct I would need to convert the continous curve into a discrete transfer function and then apply this transfer function to the input signal. However I have no clue how I would go about converting the curve into a Transfer-function. Furthermore, as it is the first time I am working with python I have very limited knowledge on how to implement this process in a python script. I would greatly appreciate any help you could provide me, thanks!

Yetzel
  • 5
  • 1

1 Answers1

0

I thought I was familiar with signal processing, but I haven't heard of a transfer function. I suspect, based on your requirements, that you need an 'impulse response' instead (also called a Filter Kernel in the context of FIR filters, or a Convolution Kernel).

You create an impulse response by first filtering a Dirac delta function by the filter you wish to apply to your audio. You have to choose a length parameter N here, and I'll give you a heuristic for this later on*.

In Audacity, you start by creating a silent mono 32-bit per sample waveform of length N samples (say 100). Edit the middle sample to be max value. Now filter this entire waveform by your equalizer, and the result is your impulse response (at very low volume).

Export this impulse response and somehow import it in python as an array of float values. Be sure to scale/divide the values so silence is 0 and the max-volume value is 1 (the actual values will be very small numbers). This ensures that the next step doesn't change the overall volume of the signal.

How you actually filter any lengthy signal is by convolving the signal with the impulse response to obtain the equalized signal. I hope you have a library function for this.

(you may want to prepend and append N samples of silence to your signal before filtering, to make sure nothing gets lost)

*) How you choose the length N, is by balancing two factors. The length shouldn't be too long since the filter effect should be local in time. Making it equal to the sample rate makes the filter's effect range ±1 second. Making it too small causes the filter to be inaccurate and 'leak' frequencies. When inspecting the impulse response values by eye, check if the outermost values (sample 0 and sample N-1) are small enough. A good choice is < 1/32768 (~0.00003) for a 16-bit signal.

Though, unless your filter passes subsonic frequencies, only the latter criteria is important, as the impulses will be quite short. I'd start by grossly overestimating the filter size, say N=1000, and looking for the first sample (from outside toward the center) exceeds this threshold, and you find the ideal N.

[edit] I just noticed in my Audacity (v2.2.1) you can specify the 'Filter size' and preview how the response will look, in green. I don't see this option in your screenshot.

Mark Jeronimus
  • 9,278
  • 3
  • 37
  • 50