Tracking Filter - loudifier/chirplab GitHub Wiki
Tracking Filter Measurement
The Tracking Filter measurement allows you to define a bank of 2nd order filters, where the center or corner frequencies of the filters are updated every sample of the response signal, based on the chirp frequency at that point in time. The measurement output is calculated from the resulting signal level after passing the chirp response input through the tracking filter bank.
Tracking Filter parameters are very flexible, allowing custom measurements ranging from a time-domain version of fundamental frequency response, to an unweighted THD+N (Harmonic Distortion can only measure THD), to a rough equivalent of Audio Precision's Rub and Buzz peak ratio and crest factor measurements. While Tracking Filter is very flexible, when measuring distortion the Harmonic Distortion and Residual Distortion measurements will usually be faster, more accurate, and easier to configure to produce the desired output.
Time-Domain Fundamental Frequency Response
- Measured signal: fundamental RMS
- Measurement mode: absolute
- RMS time: set appropriately for desired output resolution. e.g. 0.083 octaves for 12 points per octave
Note that Frequency Response is calculated using the sine wave/peak definition of full scale, while Tracking Filter simply measures the RMS level of the signals, so the Tracking Filter RMS output level is 3dB lower than the Frequency Response peak level
THD+N
- Measured signal: filtered RMS
- Measurement mode: relative
- Reference signal: fundamental RMS
- filters: notch filter at 1x fundamental frequency, Q=10
- RMS time: set appropriately for desired output resolution
AP-style "Rub and Buzz"
- Measured signal: filtered peak
- Measurement mode: relative
- Reference signal: fundamental RMS for "peak ratio" output, filtered RMS for "crest factor" output
- RMS time: adjust depending on measurement needs. 0.33 octaves is a good starting point point to measure high-frequency spikes and artifacts against a 1/3 octave smoothed RMS signal
Measurement Parameters
mode
- 'absolute': The
measured_signal
is measured and output directly - 'relative': The
measured_signal
andreference_signal
are both measured and themeasured_signal
levels are output relative to thereference_signal
levels
measured_signal
and reference_signal
- 'unfiltered RMS': The RMS level of the raw input signal, calculated over the time period set by
rms_unit
andrms_time
- 'fundamental RMS': The RMS level of the input signal with a bandpass tracking filter applied at 1x the chirp freq with a Q of 10, calculated over the time period set by
rms_unit
andrms_time
- 'filtered peak': The peak level the input signal filtered with the tracking filters defined in
filters
. The peak level is calculated as the maximum absolute signal level in each frequency interval around the output frequency points set by the output parameters - 'filtered RMS': The RMS level of the input signal filtered with the tracking filters defined in
filters
, calculated over the time period set byrms_unit
andrms_time
Any of the signal options can be used for the measured_signal
and reference_signal
. This means a 'relative' measurement output can be inverted by swapping the signals selected for the measured_signal
and reference_signal
, or if both parameters are set to the same signal the measurement output will be 0dB.
filters
A bank of tracking filters that are applied to the input signal, the level of which is then measured and used when measured_signal
and/or reference_signal
is set to 'filtered peak' or 'filtered RMS'. The filters are stored as a list of dicts, which each consist of a set of filter parameters:
filters[n]['type']
: 2nd order filter type. Filter types currently available are 'lowpass', 'highpass', 'bandpass' (0dB peak gain form), and 'notch'filters[n]['multiplier']
: The corner or center frequency of the filter ("wherever it's happenin', man"), expressed as a ratio of the instantaneous chirp frequency. e.g. for a multiplier of 10, when the chirp frequency is 1kHz the filter frequency will be 10kHz. Very high filter frequencies will be limited to 0.95*Nyquistfilters[n]['Q']
: The Q or "quality factor" of the filter. For users who prefer to specify the bandwidth of bandpass or notch filters, the exercise of converting bandwidth to Q is left up to the user.
rms_time
and rms_unit
When measured_signal
and/or reference_signal
are set to one of the 'RMS' signals, rms_time
and rms_unit
are used to set the length of time over which the signal's RMS level is calculated.
When rms_unit
is 'seconds', the RMS period in samples is rms_time
multiplied by the chirp analysis sample rate. When rms_unit
is 'octaves', the RMS period in seconds is calculated as rms_time
divided by the chirp sweep rate, and then the RMS period is converted to samples for the actual RMS calculation.
For example, for rms_unit
='octaves' and rms_time
=0.083 (1/12 octave), with a 1s 20-20kHz chirp and 48kHz sample rate, the sweep rate is 9.97 octaves/second, for an RMS time of 8.3ms, which rounds to 400 samples at 48kHz.
Output Parameters
unit
Output points are specified in this measurement unit. Two different sets of output units can be specified, depending on whether mode
is 'absolute' or 'relative'
'absolute' units:
- 'dBFS' or 'FS': Absolute Full Scale digital level of the
measured_signal
, using the "true RMS" definition of full scale. For ameasured_signal
that is typically primarily sinusoidal, a measured RMS level of 0.707FS or -3.01dBFS corresponds to a sine wave that peaks at a digital level of 1.0FS - 'Pa' or 'dBSPL': Absolute acoustic Sound Pressure Level of the
reference_signal
, in Pascals or decibels converted from digital measurement using the project'sFS_per_Pa
calibration parameter. dBSPL level is defined as the dB level relative to 20uPa, so 20uPa = 0dBSPL and 1Pa = 94dBSPL. - 'V' or 'dBV': Absolute electrical Voltage of the
reference_signal
, converted from digital measurement using the project'sFS_per_V
calibration parameter
'relative' units:
- 'dB': Decibel level of the
measured_signal
relative to thereference_signal
- '%': Level of the
measured_signal
relative to thereference_signal
, expressed as a percentage. If themeasured_signal
level is greater than thereference_signal
level, the percentage can exceed 100% - '% (IEC method)': The
measured_signal
level divided by the sum of themeasured_signal
level and thereference_signal
level, expressed as a percentage. Asmeasured_signal
level increases andreference_signal
levels falls the percentage will approach but never exceed 100%
min_freq
The lowest output frequency point in Hz
min_auto
If True the min_freq
parameter is ignored and the lowest output frequency point is set to the chirp start_freq
max_freq
The highest output frequency point in Hz
max_auto
If True the max_freq
parameter is ignored and the highest output frequency point is set to the chirp stop_freq
spacing
- 'linear': Output points are spaced evenly for
num_points
betweenmin_freq
andmax_freq
- 'log': Output points are spaced proportionally for
num_points
betweenmin_freq
andmax_freq
- 'octave': Output points are spaced proportionally between
min_freq
andmax_freq
. The total number of frequency point isnum_points
multiplied by the number of octaves betweenmin_freq
andmax_freq
rounded to the nearest whole number (total number of points = round(num_points
* Log2(max_freq
/min_freq
)) )
num_points
If spacing
is 'linear' or 'log', the total number of output frequency points between min_freq
and max_freq
. If spacing
is 'octave', the number of points per octave used to calculate the total number of output frequency points between min_freq
and max_freq
round_points
If True the array of output frequency points will be rounded to the nearest whole Hz. In cases where low frequiencies are rounded to the same whole Hz, duplicate points will be removed, resulting in fewer total output points than specified by num_points
Measurement Calculation
The Tracking Filter measurement is calculated by first generating an array that contains the instantaneous chirp frequency at every sample in the chirp response input signal. Due to the chirp analysis pre/post-sweep range extending before and after the chirp signal, the array of chirp frequencies starts below the chirp start frequency and extends higher than the chirp stop frequency, corresponding to what the actual start and stop frequencies would be at the beginning of the pre-sweep and end of the post-sweep, based on the chirp sweep rate.
The input signal is processed based on which signal is selected for the measured_signal
and, if mode
is 'relative', for the reference_signal
.
When the selected signal is 'unfiltered RMS', no tracking filter is applied to the chirp response signal.
When the selected signal is 'fundamental RMS', 'filtered RMS', or 'filtered peak', one or more set of tracking filter coefficients are generated and applied to the chirp response signal.
The filter coefficients are calculated using an implementation of the RBJ biquad cookbook, using the filter type
and Q
for each filter
defined in the measurement parameters. A separate set of filter coefficients is calculated for each sample of the selected signal, where f0 in the biquad filter formula is the instantaneous chirp frequency multiplied by the filter
's multiplier
parameter, limited to 0.95 * the Nyquist frequency.
When the selected signal is 'fundamental RMS', a single tracking filter stage is used, with type
='bandpass', Q
=10, and multiplier
=1.0.
All together, for n filters
, signal length of m samples, and 5 biquad coefficients, the full set of coefficients is an n x m x 5 array.
The tracking filters are applied to the input signal in the same way as a standard fixed biquad filter bank, except the biquad coefficients are updated for each sample.
After the tracking filters are applied to the input signal, the level of the filtered signal is measured at each output frequency.
For 'unfiltered RMS', 'fundamental RMS', and 'filtered RMS', the moving RMS of the selected signal is calculated by squaring each sample of the signal, applying a moving average, and then taking the square root of the signal at each sample. If rms_unit
is 'seconds', the moving average time is rms_time
. If rms_unit
is 'octaves', the moving average time is calculated as rms_time
divided by the chirp sweep rate in octaves/second. After calculating the moving RMS of the signal, the moving RMS is interpolated at the output frequency points.
For 'filtered peak', the maximum of the absolute value is found for each inverval around the output frequency points. If the spacing
output parameter is 'linear' the boundries between two output frequency points is the average of the two points. If spacing
is 'log' or 'octave' the boundary between two output frequency points is calculated as the proportional midpoint between those frequencies, exp((ln(freq[n])+ln(freq[n+1]))/2)
Once the levels have been calculated for the measured_signal
and reference_signal
the level at each output frequency point is convered to the unit
specified by the output parameters. When mode
is 'absolute', the measured_signal
levels are used directly and converted to acoustic or electrical levels as needed. When mode
is 'relative', the measured_signal
level at each output frequency point is divided by the reference_signal
level at that point, then converted to the specified dB or percentage value.