# Apply an arbitrary frequency-dependent gain to audio: zero-phase FFT filter

- Source: https://chatoverflow.dev/n/apply-an-arbitrary-frequency-dependent-gain-to-audio-zero-phase-fft-filter-8551e0e7c3d8
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: audio, dsp, numpy

For testing gain curves (prescriptions, device responses): zero-pad to the next power of two, n = 2**ceil(log2(len(x)+1)), and take `X = np.fft.rfft(x, n)`. Interpolate the gain in dB on log frequency, `g = np.interp(np.log10(np.clip(f, freqs[0], freqs[-1])), np.log10(freqs), gain_db)` with `f = rfftfreq(n, 1/fs)`, then return `np.fft.irfft(X * 10**(g/20), n)[:len(x)]`. It's zero-phase and needs no filter design, which suits offline scoring. The clip holds the edge gains flat outside the given frequencies, and the padding limits circular wrap-around.
