4

I'm dealing with the problem of filtering a pink noise with a peak filter (the final goal is to equalize an input signal). I've been designing the peak filter myself to get more familiar with 1D signal filtering. As for the pink noise, I'm using pink noise generated through the work already done in https://github.com/felixpatzelt/colorednoise/blob/master/colorednoise.py .

1/ I am wondering why the intensity of the power spectrogram is random when I run several times the same function with the same paramaters, is it due to the call to numpy.random.normal ? How would someone proceed to generate a noise in a specified range of values ? The two following pictures show that the power range is inconstant through different runs (cannot post images directly, sorry for the imgur links) :

2/ Following is the definition of the peak filter I use further :

class PeakFilter():
    def __init__(self, center_freq, sample_rate, Q, gainDB):
        self.center_freq = center_freq
        self.sample_rate = sample_rate
        self.gainDB      = gainDB
        self.Q           = Q

        # derived quantities
        self.A  = 10**(self.gainDB/40)
        self.center_freq = 2*np.pi * self.center_freq / self.sample_rate

    def peak_transfer(self):
        b = np.array([ 1, self.A/self.Q, 1 ])
        a = np.array([ 1, 1/(self.A*self.Q), 1])

        # shift to center frequency
        b, a = signal.lp2lp(b, a, wo=self.center_freq)
        return b, a


sample_rate = 44100
fc = 1000
Q = 1.7
Gdb = 5
peak_filt = PeakFilter(fc, sample_rate, Q, Gdb)

b, a = peak_filt.peak_transfer()
w, h = signal.freqs(b, a, 10000)
freq = w*sample_rate/2/np.pi

fig, ax = plt.subplots(1, 1, figsize=(8, 6))
ax.plot(freq, 20*np.log10(abs(h)), color='blue')
ax.set_xscale('log')
plt.grid('true')
plt.plot()

The filter response has the expected shape :

https://i.stack.imgur.com/OUsen.jpg

However, when I am filtering the noise by this filter with this code:

out = signal.filtfilt(b, a, noise)
plt.plot(out, color='red')

I get the following result:

https://i.stack.imgur.com/Q8GuN.jpg

This is were I find difficult to judge if this is correct. First I do not know why the filtered noise gets this shape and such values (negative as well). Also, I would expect the filtered signal to vary in shape or intensity, with Gdb and Q, at the given center frequency, but it does not. There should be attenuation or boost just around this frequency (if I got it right).

Post. T.
  • 79
  • 5

1 Answers1

1

I'm reading between the lines here but it seems that you're trying to validate that a filter has a desired frequency response by pumping a burst of pink noise through it and looking at the FFT of the filter output to see that it has taken on the desired shape.

First off, noise can be suitable to determine frequency response but I think white noise would be better since it doesn't have any roll off that you need to visually compensate for.

Secondly, if you pump noise into your filter you have two problems.

1) the filter has some transient response that you probably don't really care about.

2) Noise is random. If it's shaped into white or pink or whatever it only becomes apparent over time. Try skipping your filter. You'd find that it bounces all around the place from run to run. If you truly want to see the spectrum of the noise signal you need to perform averaging. Take one noise generator that can generate 10*N samples. Generate N samples, Take the FFT magnitude and accumulate it into a sum. Do this N times and plot the result. As N increases, the shape of the noise will reveal itself. Now if you do the same but put the noise through your filter you'll start to see the shape of the filter. You might want to discard the first few FFT results from the average though as to not skew it by the filters time domain response.

3) An alternative approach is to generate sine waves at varying frequencies, run them through the filter, and calculate the output amplitudes. For example, for 100 frequencies between 900 and 1100 Hz, generate a sine wave of 100 cycles at that frequency, run it through the filter, and plot the RMS amplitude of the filtered output vs sine frequency.

jaket
  • 9,140
  • 2
  • 25
  • 44
  • Hi, Thank you for your answer. Sorry if my problem was unclear: the idea is to approach the equalisation processing chain that aims at tuning loud-speaker output signal with peak filters, cutting or boosting frequencies that bring unpleasant tones to the ear. EQ systems use more than one peak filter, but being new to this signal processing domain, I am starting easy. So I am not looking at the filter response, but to the filtering result of the pink noise by this filter. And I would expect boost or cut at given frequencies, which I do not when plotting the output signal. Hope it is clearer. – Post. T. Jul 19 '19 at 08:13