0

I've been tasked with filtering a sound with a filter that looks something like this.

filter

I don't have any real DSP training, so I'm not sure if my attempt at tackling this is correct. I can filter things given I have a transfer function (it's applied in the frequency domain - I know this works so it's not a concern), so to build that I'm first converting the values from SPL to FS, then converting the dB value to a normal "sample" value, which I can treat as the transfer function.

I recognize that there's no general conversion for converting dB values from SPL to FS. However that's not really a concern; I just need the relative differences. So I do that with a simple subtraction.

Then I generate the "sample" values by simply going backwards from the formula for converting a sample to dB.

I then use that in my transfer function, multiplying the frequency domain value by the appropriate value here (well, with linear interpolation between the points).

The key part is below.

double[] spls = GetFilter(); // this just gives me the array of spl values I need to filter by
double[] output = new double[spls.Length];
for(int i = 0; i < spls.Length; i++)
{
    var fs = spl[i] - 150;
    var b = fs/20;
    var c = Math.Pow(10, b);
    output[i] = c;
}

I'm applying this to white noise; however when I enable the filter, I'm not getting any sound at all. The transfer function values it generates seem rather small, so it might be that rather than any specific problem with my method, but even so I'm not sure.

Am I doing this correctly? Given a filter with dB SPL, can I apply it to a signal by converting the values to dBFS and then "backwards" to a 0-1 value to treat as the transfer function?

  • You are subtracting 150 dB so your average gain will be at -50dB. Try -100dB instread. You also need to implement "overlap add " or equivalent for frequency domain filtering . – Hilmar Jun 11 '21 at 21:23
  • Unfortunately the filter can change, and the maximum dB SPL value is somewhere near 150. Because I have to keep that relative shift between changes of the filter I can't just reduce the subtraction too far. Could you explain what you mean (or simply point to a reference) for the frequency domain "overlap add"? – Eternal Ambiguity Jun 11 '21 at 21:42
  • https://en.wikipedia.org/wiki/Overlap%E2%80%93add_method – Hilmar Jun 12 '21 at 13:14
  • If your filters have such a massive dynamic range and you need to maintain that range, than your output will have the same dynamic range. – Hilmar Jun 12 '21 at 13:17
  • The Wikipedia link implies that method is related to long signals, but mine are fairly short - I'm just generating them off of a single second of noise. Would it still apply? – Eternal Ambiguity Jun 12 '21 at 14:38
  • Yes. roughly speaking : it's going to take a while for the filter to "kick in". So I would filter a longer chunk and then just use the last second of the output. The extra chunk should be at least the length of the impulse response, which depends a lot on your specific filter. In your case, I suggest getting rid of the peak at 12 Hz. It doesn't do anything useful and will create lots and lots of ringing in the impulse response. – Hilmar Jun 13 '21 at 13:04
  • Alright, thanks. – Eternal Ambiguity Jun 13 '21 at 13:52

0 Answers0