Impulse Response - loudifier/chirplab GitHub Wiki
Impulse Response Measurement
Impulse response is the time-domain representation of a system's transfer function, equivalent to the system's frequency and phase response in the frequency domain, and can be used to simulate a system's output from any arbitrary input signal. Where frequency and phase responses are typically saved at a resolution that can visually communicate the response of a system, using them to simulate that system's response involves a certain amout of filling in missing information with interpolation. When saved as an audio file, an impulse response is a compact, lossless model of a system that can be easily shared between different software.
The Impulse Response measurement provides controls for windowing, time alignment, truncation, and scaling of the output impulse response file.
- Windowing can be adjusted to remove distortion artifacts preceding the impulse or reverberation and noise in the impulse response tail. Extending the window and fade in/out times reduces the window's impact on the accuracy of the output impulse response, at the expense of rejecting less noise and distortion
- Time alignment settings control where the t=0 point of the impulse response occurs in the output, which helps ensure any pre-ringing is not cut off from the beginning of the output and avoids discontinuities at the beginning/end of the output when convolving the impulse response with another signal
- Truncation shortens the output file, which can make it easier to work with or ensure the length is of a specific size needed for later processing stages. Truncating to a short total length can cut off the end of the impulse response, with impacts on the output similar (or sometimes identical) to windowing
- Scaling can be used to maximize the dynamic range of the output file and keep the output at a more convenient level, for situations where the absolute level of the impulse response is not important
Note that windowing, time alignment, and truncation are all interrelated. Changing one setting in the GUI may change another setting to ensure the calculations and output settings are valid
Measurement Parameters
window_mode
- 'raw': The impulse response is calculated and output without applying any sort of windowing. If
alignment
is 'window_start' it will be changed to 'offset'. Iftruncate_mode
is 'window' it will be changed to 'fixed' - 'windowed': A window is generated and applied using the
window_start
,fade_in
,window_end
, andfade_out
parameters. This is the same process as used by the Frequency Response measurement - 'auto': A window is generated and applied using the same process as the 'windowed' setting, but the windowing parameters are calculated automatically using a process similar to adaptive windowing in the Frequency Response measurement. The window time parameters are ignored and the window for each output point will be based on the wavelength, L, of the lowest chirp frequency, such that
window_start
=L,fade_in
=L,window_end
=2*L, andfade_out
=L
window_start
The total time in milliseconds before the t=0 point of the impulse response to start the impulse response window
fade_in
The time in milliseconds at the beginning of the impulse response window to be constructed with the first half of a Hann window of width 2*fade_in
. If fade_in
is 0, the start of the impulse response window will have a rectangular shape, with all points equal to 1.0. If fade_in
is equal to window_start
the entire impulse response window from -window_start
to t=0 will consist of the first half of a Hann window of width 2*window_start
.
window_end
The total time in milliseconds after the t=0 point of the impulse response to end the impulse response window.
fade_out
the time in milliseconds at the end of the impulse response window to be constructed with the second half of a Hann window of width 2*fade_out
. If fade_out
is 0, the end of the impulse response window will have a rectangular shape, with all points equal to 1.0. If fade_out
is equal to window_end
the entire impulse response window from t=0 to window_end
will consist of the second half of a Hann window of width 2*window_end
ref_channel
The input signal used as the reference when calculating the impulse response
- When set to 0, the internal stimulus signal will be used as the reference. The
timing_channel
parameter can be set to adjust the timing reference - When set to an input channel (that is different from the main project input channel), the signal from that channel will be used as the impulse response reference signal
- When set to the same channel as the main input channel, the impulse response will be calculated, but because the input is referenced to itself the output will be a single sample full scale impulse
Note that a high input signal amplitude and low reference signal amplitude can result in an impulse response that peaks higher than ±1.0, which will be clipped when exported as an audio file. If the absolute impulse response amplitude is not important for your use case, you can set normalize
to True to scale the output file to peak at ±1.0FS
timing_channel
When ref_channel
is 0, the input signal used as a timing reference. This allows you to calculate the impulse response relative to the mean group delay of the timing reference, but using the stimulus signal as the impulse response, so the output impulse response is not impacted by the spectrum of the timing reference signal. For example, it can be useful to use an analog loopback channel as the timing reference, but that loopback signal will typically have a frequency response that rolls off slightly at high and low frequencies, which impacts the impulse response output. The time alignment of the timing reference signal is determined by cross-correlation between the timing reference and the interal stimulus signal
- When set to 0 or the same channel as the main input channel, the main input signal is used as it is detected by the project-level response time alignment, so the main peak of the impulse response will be aligned to t0
- When set to an input channel (that is different from the main project input channel), the signal from that channel will be used as the impulse response reference signal. The main peak of the impulse response will occur before or after the t0 point of the impulse response, corresponding to how much the input signal leads or lags behind the timing reference
Note that for both the ref_channel
and timing_channel
settings if there is a significant delay between the reference or timing reference signal and the input signal you may need to adjust the main chirp analysis pre/post sweep times to ensure the beginning/end of the signals are not cut off
alignment
The raw impulse response is deconvolved using an inverse FFT, which mathematically represents the transfer function with the assumption that the input signal is the internal stimulus signal circularly convolved with the impulse response. This means the t0 point of the raw impulse response occurs at the first sample of the impulse response and any pre-ringing occurs at the end of the impulse response. To ensure any important information that occurs before t0 is included in output files, the alignment
settings control different methods to circularly shift the entire impulse response signal to the right, delaying the impulse response t0 point and bringing the pre-ringing information to the beginning of the output file
- 'window_start': When
window_mode
is 'windowed', the raw impulse response is rolled to the right by the same amount of time aswindow_start
. Whenwindow_mode
is 'auto', the raw impulse response is rolled to the right by the wavelength of the lowest chirp frequency. Whenwindow_mode
is 'raw',alignment
is changed to 'offset' - 't0': The raw impulse response is not shifted at all. This ensures the output impulse response is exactly time-aligned with the timing reference signal, which can sometimes be useful when the impulse response is transformed and used for convolution in the frequency domain, but can cut off important information that occurs before t0 if
truncate_mode
is not 'full' - 'centered': The raw impulse response is rolled to the right by half the total length of the impulse response, which places the t0 point of the impulse response at the halfway point of the output.
truncate_mode
is changed to 'full'. This setting can be useful when convolving signals with impulse responses of variable length, since the signal of interest will end up in the middle of the convolved signal and the amount of time to trim off the beginning and end of the signals is easily determined by the impulse response length - 'offset': The raw impulse response is rolled to the right by the time in ms specified by the
offset
parameter
offset
The amount of time in ms to roll the raw impulse response to the right when alignment
is 'offset'
Output Parameters
Impulse Response data graphed in the GUI will show a measurement noise floor, but the measurement noise floor is not exported to an output audio file. The graph will also be zoomed in to the output file time range determined by the truncation settings, but the remainder of the impulse response data is visible when the time scale is zoomed out
truncate_mode
The raw impulse response length is equal to the chirp stimulus length, pre-, and post-sweep times set in the main project chirp analysis parameters. This time range is usually much longer than is needed to capture any meaninful data in the tail of the impulse response measurement, and it is often desireable to use an impulse response with a short fixed length to reduce the computational requirements of the system that makes use of the impulse response. The truncate
settings let you trim the end of the impulse response signal to control the length of the measurement output audio file.
- 'window_end': The output impulse response signal is truncated to the end of the impulse response window, as determined by the
window_mode
andwindow_end
parameters. Whenwindow_mode
is 'raw',truncate_mode
is changed to 'fixed' - 'fixed': The output impulse response signal is truncated to
truncate_length
ms after the t0 point of the impulse response - 'full': The complete impulse response signal is included in the impulse response output, without any truncation applied
The total length of the impulse response output file is the length of time before the t0, determined by the alignment
and offset
settings, plus the time after the t0 point, determined by the trunctate_mode
and truncate_length
settings.
truncate_length
The time in ms after the t0 point to include in the impulse response output file, when truncate_mode
is 'fixed'
normalize
When True, the impulse response measurement output file will be scaled such that the maximum signal level peaks at ±1.0FS. If normalize
is False and the impulse response signals exceeds ±1.0, the output file will be clipped. The GUI graph will always be plotted at the calculated amplitude, regardless of the normalize
setting
bit_depth
The bit depth of the impulse response measurement output audio file. The options are the same as the main stimulus output and recording options, '16 int', '24 int', '32 int', and '32 float'. The file is always saved at the main project chirp analysis sample rate.
Plot window
The Impulse Response measurement does not have a parameter for plotting the window, but there is a checkbox in the GUI that defaults to control whether the impulse response window is plotted alongside the impulse response output. The window value is always 1.0 at the t0 point, but the window plot is scaled to the same absolute amplitude of the impulse response.
Impulse Response Measurement Calculation
The impulse response of a system is easily derived by taking the inverse FFT of the spectrum of the system's output divided by the spectrum of the input that generated the output
Note that using an inverse FFT to deconvolve the impulse response makes a mathematical assumption that the response is the circular convolution of the stimulus and impulse response. The diagram above shows the main impulse in the center of the impulse response signal, but circular deconvolution results in the t0 point aligned to the first sample of the raw impulse response signal, with any pre-ringing or other important information that appears before the t0 point showing up at the end of the impulse response signal. The sample array can be circularly shifted or rolled to the right to place the t0 sample at a more useful point in the signal. That process is controlled by the alignement settings, and is outlined below.
The ref_channel
and timing_channel
parameters determine the actual response signal that is used as the impulse response reference and the time alignment between that signal and the response signal being analyzed.
If ref_channel
is a channel number, the input signal from the main chirp response detection is used as-is. The channel of the input file or capture specified by ref_channel
is taken as the reference signal, with the delay of the input signal from the main project chirp detection timing used for time alignment.
If ref_channel
is 0, the main project internal chirp stimulus signal is used as-is for the reference signal. The channel of the input file or capture specified by timing_channel
is taken and passed through the same process as the main project chirp detection to determine the timing of the response to use for the response calculation. Instead of using the response signal as determined by the main project chirp detection process, the raw input channel is taken and the timing reference delay determines the section of the input channel that is used as the response signal for the impulse response calculation
This diagram is busy, but covers the reference and response signals used with different ref_channel
and timing_channel
settings and how those signals are time-aligned.
If the window_mode
setting is 'windowed' or 'auto' a window is generated and applied to the raw impulse response, which helps reduce distortion and noise in the output when the impulse response is transformed into the time domain as a frequency or phase response, or when the impulse response is used as a filter kernel.
When window_mode
is 'windowed, the window_start
and window_end
parameters control the total timespan of the window before and after the t0 point, respectively. The fade_in
and fade_out
parameters control the length of time at the beginning and end of the window that is made up of half periods of a Hann window. When window_mode
is 'auto', the window parameters are calculated based on the wavelength of the lowest chirp frequency, similar to the method used for adaptive windowing in the Frequency Response measurement.
After windowing, the impulse response signal is rolled to the right based on the alignment parameters.
If alignment
is 't0', the impulse response is not shifted, leaving the t0 point of the impulse response at the start of the output signal.
If alignment
is 'window_start', the impulse response is shifted to the right by the same length as the window_start
parameter, ensuring the full non-zero period of the impulse response is placed at the start of the output signal. If window_mode
is set to 'raw' while 'alignment' is set to 'window_start', alignment
will be changed to 'offset'
If alignment
is 'offset', the impulse response is shifted to the right by the value manually entered in the offset
parameter. This can result in the beginning of the impulse response being cut off if offset
is set too low.
If alignment
is 'centered', the impulse response will be shifted by half the total length of the impulse response signal, placing the t0 point at the midpoint of the output signal. When alignment
is set to 'centered' the truncate_mode
output parameter is set to 'full'.
After applying windowing and alignment settings, the full impulse response signal is plotted, then truncation parameters are used to set the plot time range and trim the measurement output signal.
If truncate_mode
is 'full', the impulse response signal is not truncated, so the graph is not zoomed and the measurement output file will include the full impulse response signal.
If truncate_mode
is 'window_end', the impulse response is truncated to the end of the impulse response window. If window_mode
is 'raw', truncate_mode
is changed to 'fixed'.
If truncate_mode
is 'fixed', the impulse response is truncated to the time manually specified by the truncate_length
parameter. The truncate_length
time is the length of time after the t0 point of the impulse response, so the graph zoom range and total output signal length includes any time before the t0 point determined by the alignment settings plus truncate_length
. If truncate_length
is too short, then the tail of the main impulse response peak may be cut off.
Finally, when all windowing, alignment, and truncation has been applied, the normalize
and bit_depth
parameters are used during the measurement export process (the normalize
and bit_depth
parameters do not impact the measurement graph). If normalize
is True, the impulse response signal is scaled such that the peak sample is equal to ±1.0FS. If normalize
is False and the impulse response signal exceeds ±1.0 (which is possible in cases where the input signal level is high and the ref_channel
signal level is low), the output audio file will be clipped. The output audio file is always saved at the main project analysis sample rate, with the number of bits and number format determined by the bit_depth
parameter, '16 int'