Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Changing filter's coefficients to compensate sampling rate changes (Read 16818 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Changing filter's coefficients to compensate sampling rate changes

Hello,

I've read the Recommendation ITU-R BS.1770.1, titled "Algorithms to measure audio programme loudness and true-peak audio level", and there is one sentence which makes me doubt. It refers to the coefficients of one filter (2nd order IIR) used in the process of measuring the loudness level of an audio signal, and says:

"These filter coefficients are for a sampling rate of 48kHz. Implementations at other sampling rates will require different coefficient values, wich should be chosen to provide the same frequency response that the specified filter provides at 48 kHz"

I've been looking for methods of adjusting coefficients from a given change in the sampling rate, but all I've found involves polyphase filters (which means adding more filters instead of modifiying the coefficients of an existing one). Besides, if I've understood this stuff, in the Z transform, a change in the sampling rate is the same as a multiplying the exponent of the exponential by some factor, so, how a change in the filter coefficients (constants multiplying the exponentials in the Z transforms) can make the same effect as some changes in the exponents of the exponentials? Obviously there is something I have mistaken or something I don't know.

In either case, which really matters to me is how can such change in the filter's coefficients be made (if there is any method or something similar) to get the same (or similar) frequency response?

Thank you very much.

Changing filter's coefficients to compensate sampling rate changes

Reply #1
The most immediate method is to convert the filter to a pole/zero representation and then simply multiply/divide their angles around as your Fs changes. That won't give you a necessarily optimal filter, but it is the fastest way to reinterpret the provided coefficients in another sample rate.

Changing filter's coefficients to compensate sampling rate changes

Reply #2
The most immediate method is to convert the filter to a pole/zero representation and then simply multiply/divide their angles around as your Fs changes. That won't give you a necessarily optimal filter, but it is the fastest way to reinterpret the provided coefficients in another sample rate.



This isn't a bad approach for 44 to 48 or vice versa. It's going to be kinda far off at 32 or 64, or above.
-----
J. D. (jj) Johnston

Changing filter's coefficients to compensate sampling rate changes

Reply #3
Thank you both,

I've programmed and tested what you said. Changing the sampling rate from 48kHz to 44.1 kHz without adapting the coefficients causes an average error in the frequency (magnitude) response of 0.03953656 dB, while the average error adapting them is of 0.03950303 dB (an improvement of ~0.0000335 dB). Changing the sampling rate from 48kHz to 96kHz, the average error without adjusting is 0.66603265 dB, and adjusting the coefficients 0.66425476 dB (an improvement of ~0.001778 dB).

Changing filter's coefficients to compensate sampling rate changes

Reply #4
Thank you both,

I've programmed and tested what you said. Changing the sampling rate from 48kHz to 44.1 kHz without adapting the coefficients causes an average error in the frequency (magnitude) response of 0.03953656 dB, while the average error adapting them is of 0.03950303 dB (an improvement of ~0.0000335 dB). Changing the sampling rate from 48kHz to 96kHz, the average error without adjusting is 0.66603265 dB, and adjusting the coefficients 0.66425476 dB (an improvement of ~0.001778 dB).


If the difference you are seeing is so small, it can only mean that you screwed up somewhere.

Changing filter's coefficients to compensate sampling rate changes

Reply #5
The most immediate method is to convert the filter to a pole/zero representation and then simply multiply/divide their angles around as your Fs changes. That won't give you a necessarily optimal filter, but it is the fastest way to reinterpret the provided coefficients in another sample rate.


There's another method that is similar: frequency warping. It's what I did to "convert" the ATH noise shaper I designed for 44.1 kHz to a filter for 48 kHz. Again, this is not perfect but good enough for small rate changes and/or on oversampled systems.

What's frequency warping? You basically replace z^-1 with a nonlinear phase allpass filter. It also rotates the zeros and poles but the angle is not constant. It depends on a root's location. Also, you don't need to know the poles and zeros to do frequency warping, so, that's an advantage.

Cheers,
SG


 

Changing filter's coefficients to compensate sampling rate changes

Reply #6
Thank you all. I've learned much with your insight.

One more question, though. I've been thinking about the whole purpose of this Recommendation, which is to apply some weightings to the different frequencies in order to obtain a measure of the loudness received by the user. The weighting curves used are specified as 2nd order IIR filters (those for which I wanted to adapt the coefficients). But, as the final purpose of those filters is to apply their frequency response as a weighting curve (or I am completely lost), wouldn't it be the same than passing the signal through the filter, to apply the weighting curve directly to the frecuencies composing the received signal?

If so, would it still make sense having to adapt the coefficients to different sampling rates? I mean, the purpose of adapting the filter coefficients is to get the same (at least approximately) frequency response despite the sampling rate change, but if we already know what the frequency response must be (which is the weighting curve)...

Hope I'm not delirious...

Thank you again.

Changing filter's coefficients to compensate sampling rate changes

Reply #7
[...] The weighting curves used are specified as 2nd order IIR filters (those for which I wanted to adapt the coefficients). But, as the final purpose of those filters is to apply their frequency response as a weighting curve (or I am completely lost), wouldn't it be the same than passing the signal through the filter, to apply the weighting curve directly to the frecuencies composing the received signal?

I'm not sure I understand your train of thoughts. Applying a 2nd order IIR filter and then computing the RMS (or something similar) is fairly straight forward. If by "apply the weighting curve directly to the frequencies" you mean "spectral analysis followed by a weigted sum of a discrete power spectral density function" then, yes, that's possible. But I think that would be slower compared to the rather simple 2nd order IIR filter -- not to mention the overhead in terms of delay and memory (buffers, FFT lookup tables).

Cheers,
SG

Changing filter's coefficients to compensate sampling rate changes

Reply #8
If by "apply the weighting curve directly to the frequencies" you mean "spectral analysis followed by a weigted sum of a discrete power spectral density function" then, yes, that's possible.


Yes, that was my "newbie approach" to what you've said so precisely

But I think that would be slower compared to the rather simple 2nd order IIR filter -- not to mention the overhead in terms of delay and memory (buffers, FFT lookup tables).


The signals I need to work with, I receive them directly in frequency domain, this is the reason why I was wondering if it'll be the same to apply a weighted sum of the discrete power spectral density function than passing the signal in time domain through the 2nd order IIR filter. I hope that makes my reasoning more... reasonable

Thank you very much again.


Re: Changing filter's coefficients to compensate sampling rate changes

Reply #9
By MathWorks: ( https://www.mathworks.com/help/audio/ref/weightingfilter-class.html?s_tid=gn_loc_drop )

"These coefficients are recomputed for nonstandard sample rates using the algorithm
described in Mansbridge, Stuart, Saoirse Finn, and Joshua D. Reiss. "Implementation
and Evaluation of Autonomous Multi-track Fader Control
." Paper presented at the
132nd Audio Engineering Society Convention, Budapest, Hungary, 2012.
"
(AES Convention Paper 8588)

Re: Changing filter's coefficients to compensate sampling rate changes

Reply #10
By MathWorks: ( https://www.mathworks.com/help/audio/ref/weightingfilter-class.html?s_tid=gn_loc_drop )

"These coefficients are recomputed for nonstandard sample rates using the algorithm
described in Mansbridge, Stuart, Saoirse Finn, and Joshua D. Reiss. "Implementation
and Evaluation of Autonomous Multi-track Fader Control
." Paper presented at the
132nd Audio Engineering Society Convention, Budapest, Hungary, 2012.
"
(AES Convention Paper 8588)

Looks like the original coefficients are calculated using:

Code: [Select]
% ITU-R BS1770-4 --------------------------------------
fs = 48000;

% HSF
db = 3.999843853973347;
f0 = 1681.974450955533;
Q  = 0.7071752369554196;
K  = tan(pi * f0 / fs);
Vh = power(10.0, db / 20.0);
Vb = power(Vh, 0.4996667741545416);
pa0 = 1.0;
a0 =      1.0 + K / Q + K * K
pb0 =     (Vh + Vb * K / Q + K * K) / a0
pb1 =           2.0 * (K * K -  Vh) / a0
pb2 =     (Vh - Vb * K / Q + K * K) / a0
pa1 =           2.0 * (K * K - 1.0) / a0
pa2 =         (1.0 - K / Q + K * K) / a0

% HPF
f0 = 38.13547087602444;
Q  =  0.5003270373238773;
K  = tan(pi * f0 / fs);
rb0 = 1.0
rb1 = -2.0
rb2 = 1.0
ra0 = 1.0
ra1 = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K)
ra2 = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K)
% ------------------------------------------------------

Could this same code be used to calculate coefficients for other samplerates by just changing the vlue of parameter fs[/]?

Re: Changing filter's coefficients to compensate sampling rate changes

Reply #11
By MathWorks: ( https://www.mathworks.com/help/audio/ref/weightingfilter-class.html?s_tid=gn_loc_drop )

"These coefficients are recomputed for nonstandard sample rates using the algorithm
described in Mansbridge, Stuart, Saoirse Finn, and Joshua D. Reiss. "Implementation
and Evaluation of Autonomous Multi-track Fader Control
." Paper presented at the
132nd Audio Engineering Society Convention, Budapest, Hungary, 2012.
"
(AES Convention Paper 8588)

Looks like the original coefficients are calculated using:

Code: [Select]
% ITU-R BS1770-4 --------------------------------------
fs = 48000;

% HSF
db = 3.999843853973347;
f0 = 1681.974450955533;
Q  = 0.7071752369554196;
K  = tan(pi * f0 / fs);
Vh = power(10.0, db / 20.0);
Vb = power(Vh, 0.4996667741545416);
pa0 = 1.0;
a0 =      1.0 + K / Q + K * K
pb0 =     (Vh + Vb * K / Q + K * K) / a0
pb1 =           2.0 * (K * K -  Vh) / a0
pb2 =     (Vh - Vb * K / Q + K * K) / a0
pa1 =           2.0 * (K * K - 1.0) / a0
pa2 =         (1.0 - K / Q + K * K) / a0

% HPF
f0 = 38.13547087602444;
Q  =  0.5003270373238773;
K  = tan(pi * f0 / fs);
rb0 = 1.0
rb1 = -2.0
rb2 = 1.0
ra0 = 1.0
ra1 = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K)
ra2 = (1.0 - K / Q + K * K) / (1.0 + K / Q + K * K)
% ------------------------------------------------------

Could this same code be used to calculate coefficients for other samplerates by just changing the vlue of parameter fs[/]?


I use a similar subroutine for similar purpose in my software -- that is, I just change the fs value -- the filter specs are defined by the  'f0, q values.  I don't use that precise function -- I start with something like this:  H(s) = (b0*s^2 + b1*s + b2) / (a0*s^2 + a1*s+a2);, where i have precalculated the b0-b2 and a0-a2 values for the kind of second order filter that I want.  Then I have a function that accepts the b values, a values, fs, and the frequency for the warping parameter.  So -- no matter the fs frequency -- I have a 2nd order IIR filter that matches the specified characteristics.  Of course, the filter must be reasonable for the fs values that it is used for.   Also, I have a set of functions that build FIR filters are runtime also (given cutoff, filter type, #taps, etc.)

I didn't carefully review your specific function, but it does look somewhat similar to the one that I wrote.  You are going in the right direction.
Joh