Design inverse filter (FIR) from mono or stereo impulse response ------------------------------------------------------------------------------ description: design inverse filter (FIR) from mono or stereo impulse response ------------------------------------------------------------------------------ inputs overview --------------- type - 1. 'linphase': symmetric two-sided response compensating magnitude while maintaining original phase information 2. 'minphase': one-sided response compensating magnitude with minimal possible group delay 3. 'complex': asymmetric two-sided response compensating magnitude and phase h - mono or stereo impulse response (column vector) Nfft - FFT length for calculating inverse FIR Noct - optional fractional octave smoothing (e.g. Noct=3 => 1/3 octave smooth, Noct=0 => no smoothing) L - length of inverse filter (truncates Nfft-length filter to L) range - frequency range to be inverted (e.g. [32 16000] => 32 Hz to 16 kHz) reg - amount of regularization (in dB) inside (reg(1)) and outside (reg(2)) the specified range (example: reg=[20 -6] => inverts frequency components within 'range' with a max. gain of 20 dB, while dampening frequencies outside 'range' by 6 dB) window - window=1 applies a hanning window to the inverse filter ----------------------------------------------------------------------------------------------- Background information: complex inversion of non-minimum phase impulse responses -------------------------------------------------------- If an acoustical impulse response contains reflections there will be repeated similar magnitude characteristics during sound propagation. This causes the impulse response to consist of a maximum-phase and a minimum phase component. Expressed in trms of z-transformation the min.-phase are within the unit circle while the max.-phase component are outside. Those components can be seen as numerator coefficients of an digital FIR filter. Inversion turnes the numerator coefficients into denumerator coefficients and those outside the unit circle will make the resulting filter (which is now an IIR filter) unstable. Making use of the DFT sets |z|=1 and that means taht the region of convergence now includes the unit circle. Now the inverse filter is stable but non-causal (left handed part of response towards negative times). To compensate this, the resulting response is shifted in time to make the non-causal part causal. But the "true" inverse is still an infinite one but is represented by an finite (Nfft-long) approximation. Due to this fact and due to the periodic nature of the DFT, the Nfft-long "snapshot" of the true invese also contains overlapping components from adjacents periodic repetitions (=> "time aliasing"). Windowing the resulting response helps to suppress aliasing at the edges but does not guarantee that the complete response is aliasing-free. In fact inverting non-minimum phase responses will always cause time aliasing - the question is not "if at all" but "to which amount". Time-aliasing "limiters": - use of short impulse responses to be inverted (=> windowing prior to inverse filter design) - use of longer inverse filters (=> increasing FFT length) - avoide inversion of high-Q (narrow-band spectral drips/peaks with high amplitde) spectral components (=> regularization, smoothing) In addition the parameters should be choosen to minimize the left-sided part of the filter response to minimize perceptual disturbing pre-ringing. ---------------------------------------------------------------- References: - papers of the AES (e.g. from A. Farina, P. Nelson, O. Kirkeby) - Oppenheim, Schafer "Discrete-Time Signal Processing" ----------------------------------------------------------------