Skip to content

Feedforward Compensator

The Feedforward Compensator is an advanced signal processing widget designed to apply real-time or offline nonlinear distortion compensation to audio signals based on a Parallel Hammerstein model.

By loading a Hammerstein model (1st to 5th order impulse response kernels) measured and extracted by modules such as the Nonlinear Analyzer, it generates a compensated signal with inverse distortion to actively cancel (reduce) the distortion of physical audio devices.


💡 How It Works: LICFF (Linear-Inverse Compensated Feedforward)

This module implements the LICFF (Linear-Inverse Compensated Feedforward) algorithm, which assumes a Parallel Hammerstein model.

1. Designing the Linear Inverse Filter

Letting the frequency response of the 1st-order (linear) kernel h1h_1 from the model be Q1(f)Q_1(f), its linear inverse response Finv(f)F_{inv}(f) is designed using a regularization parameter ϵf\epsilon_f as follows:

Finv(f)=Q1(f)Q1(f)2+ϵfbp_filter(f) F_{inv}(f) = \frac{Q_1^*(f)}{|Q_1(f)|^2 + \epsilon_f} \cdot bp\_filter(f)

Where:

  • Q1(f)Q_1^*(f) is the complex conjugate of Q1(f)Q_1(f).
  • ϵf\epsilon_f is a frequency-dependent regularization parameter to prevent extreme amplification in stopbands. It is set to be very small inside the active band (ϵin=106\epsilon_{in} = 10^{-6} where bp_filter=1bp\_filter = 1) and larger outside (ϵout=0.5\epsilon_{out} = 0.5).
  • bp_filter(f)bp\_filter(f) is a bandpass filter that smoothly attenuates outside the user-configured active band (fminfmaxf_{min} \sim f_{max}) using a cosine roll-off. This prevents excessive boosting of low-frequency and high-frequency noise.

2. Iterative Distortion Compensation

To compensate for distortion caused by nonlinear components, the following iterative calculation is performed on the input signal uinu_{in}:

  1. First, set the baseline input signal restricted to the active band: [ u_{comp}^{(0)} = \text{IFFT}(U_{in}(f) \cdot bp_filter(f)) ]
  2. At iteration step kk, predict the distortion spectrum Ynl(f)Y_{nl}(f) generated by running the current compensated signal ucomp(k)u_{comp}^{(k)} through the nonlinear kernels (2nd to 5th order harmonics) of the Hammerstein model via forward simulation.
  3. Multiply the predicted distortion components by the linear inverse filter Finv(f)F_{inv}(f) and feed it back to the input side to subtract the distortion: [ u_{comp}^{(k+1)} = u_{comp}^{(0)} - \text{IFFT}(Y_{nl}(f) \cdot F_{inv}(f)) ]
  4. Repeat this process for the specified number of times (default is 3) to obtain a compensated signal ucompu_{comp} in which high-order harmonic distortions are significantly canceled out.

Settings

Model Source

  • Load Forward Model JSON... Button: Loads a Hammerstein model JSON file (containing kernels h1 through h5) exported from the Nonlinear Analyzer.
  • Status: Displays the load status of the model.
  • Rate: Displays the sampling rate of the loaded model.
  • N Samples: Displays the number of samples (model length) of the kernels (impulse responses).

Compensation Settings

  • Linear-Only Compensation: If checked, skips nonlinear distortion compensation (2nd to 5th order) and only applies an equalizer (inverse filter) to flatten the 1st-order (linear) frequency response.
  • Enable Iterative Compensation: If checked, uses the iterative algorithm to calculate nonlinear distortion cancellation.
  • Iterations: Configures the number of iterations for distortion compensation (1 to 20). Typically, 3 to 5 iterations are sufficient for convergence.
  • Active Band Fmin (Hz) / Fmax (Hz): Sets the lower (Fmin) and upper (Fmax) frequency limits to enable the inverse compensation filter. Protective roll-offs are automatically applied outside this range.
  • Linear Smoothing: Smooths the linear inverse filter using a moving average based on logarithmic frequency bins to suppress narrow peaks caused by measurement noise. Helps prevent ringing in the time domain.
  • Out-of-band Mode: Defines how frequencies outside the active band are handled (Cut, Bypass (Pure), Bypass (Aligned)).
  • Regularization Mode: Configures how the ϵf\epsilon_f parameter is determined (Auto (Broadband / Music), Auto (Pure Tones), Manual (Max Boost), Manual (Tikhonov)).
  • Reg. Value: Setting for the manual regularization modes.
  • Abort on Instability: A checkbox to halt offline processing if filter runaway or oscillation is detected.

Tabs

1. Simulation

Simulates the effect of distortion compensation on test signals using the loaded model.

  • Test Signal: Selects the type of test signal.
    • 1kHz Tone: A pure 1kHz sine wave.
    • 3kHz Tone (Untrained): A pure 3kHz sine wave to check compensation capability outside the model's training band or non-fundamental frequencies.
    • Two-Tone (1.0k + 1.5k): A two-tone signal to verify intermodulation distortion (IMD) compensation.
    • Multi-Tone (5 freqs): A complex multi-tone signal.
    • Broadband Noise: Wideband noise.
  • Amplitude: Sets the amplitude of the test signal.
  • Run Simulation Button: Runs the simulation and updates the plots. Simulation also automatically updates when you change the test signal type or amplitude.
  • Output Information: Displays the simulated Total Harmonic Distortion (THD) and total distortion ratios (equivalent to THD+N) before and after compensation, presented in an easy-to-read HTML table.

  • Plots:

    • Uncompensated (Red): The output spectrum when the signal passes through the model without compensation (harmonic distortion peaks are visible).
    • Compensated (Green): The output spectrum when distortion compensation is applied before passing through the model (harmonic distortion peaks are significantly reduced).
    • Ideal Linear (Blue): The spectrum when passing through an ideal linear response without any distortion.

2. Transient Simulation

Simulates and visualizes the time-domain transient response (e.g., Step Response, Impulse Response) of the compensation.

  • Show Band-Limited Ideal Reference: If checked, plots the ideal linear response band-limited by the active band filter (fminfmaxf_{min} \sim f_{max}) to serve as a realistic reference for step response targets.
  • Plots:
    • Uncompensated (Red): The transient response when passing through the uncompensated model.
    • Compensated (Green): The transient response after compensation is applied.
    • Ideal Linear (Blue): The ideal, theoretically perfect linear transient response.
    • Band-Limited Ideal (Cyan): The ideal reference constrained by the active band filter.

Note: Step transitions cause Gibbs ringing due to the Active Band filter (fminfmaxf_{min} \sim f_{max}) required for inverse filter stability.

3. Linear Response

Displays the characteristics of the linear inverse filter and the overall compensated linear response.

  • Magnitude Response:
    • Uncompensated (Linear) (Red): The 1st-order transfer function of the loaded model (original frequency response).
    • Inverse Filter (Green): The designed inverse filter response (you can see the gain limits in the stopbands).
    • Compensated (Overall) (Blue): The overall combined response of the original system and the inverse filter (flat response).
  • Phase Response:
    • Displays the phase response for each condition.
    • Phase Rotation Correction: To prevent apparent rapid phase rotation caused by delay components (such as gate pre-alignment offsets) introduced during measurement, the curves are plotted using the peak location of the 1st-order kernel h1h_1 as the time reference. This allows clear observation of physical phase changes.
    • Noise Masking: In frequency ranges where the signal level is extremely low (below -60 dB), phase values are automatically masked to prevent wild oscillations caused by noise, ensuring clean visualization and preventing plotting library crashes.

4. Offline Processing

Applies the distortion compensation algorithm offline to a WAV audio file and saves the result.

  • Input Wav / Output Wav: Specifies the input and destination files. You can also drag and drop a .wav file into the application window to automatically set these paths.
  • Process & Save Button: Starts processing on a background thread. The button label changes to "Cancel" during processing, allowing you to abort the operation.
    • Automatic resampling is performed if the input audio's sampling rate differs from the model's rate.
    • Segmented processing with sufficient overlap is used to prevent boundary artifacts during block-by-block processing.
    • If the processed peak level exceeds 0 dBFS and digital clipping is about to occur, normalization is automatically applied, and a warning message is shown.