Frequency response (source code)

= Frequency response
{title2=$H(\omega)=\sum_jh[j]e^{-\mathrm i\omega j}$}
{wiki}

The frequency response gives the change in <complex amplitude> of a sustained oscillation under a <linear time-invariant system>. If the <impulse response> is finite or has <absolute summability>, substituting $x[n]=e^{\mathrm i\omega n}$ into its <discrete convolution> yields
$$
y[n]=\sum_jh[j]e^{\mathrm i\omega(n-j)}
=H(\omega)e^{\mathrm i\omega n},\qquad
H(\omega)=\sum_jh[j]e^{-\mathrm i\omega j}.
$$
Thus $|H(\omega)|$ is the amplitude gain and its <complex argument> is the phase change. Real sinusoids follow by taking real or imaginary parts. Here $\omega$ is radians per sample; $\omega=2\pi f$ for $f$ cycles per sample. A physical sampling rate converts that normalized frequency into cycles per second.

For a trailing <moving average>,
$$
H(\omega)=\frac1M\sum_{j=0}^{M-1}e^{-\mathrm i\omega j}
=e^{-\mathrm i\omega(M-1)/2}\frac{\sin(M\omega/2)}{M\sin(\omega/2)},
$$
with removable singularities evaluated from the finite sum. In particular $H(0)=1$. For $M=5$ and $\omega=2\pi/5$, the five <roots of unity> sum to zero, so the oscillation is canceled. At small positive frequencies in the first pass region, the real sine ratio is positive and the phase factor gives a delay of $(M-1)/2$ samples.

\Image[/moving-average-frequency-response.png]
{title=Moving-average gain curves and five phase contributions that cancel at one frequency}

Increasing $M$ moves the first zero to $\omega=2\pi/M$, narrowing the main region of large gain. It does not create an ideal low-frequency cutoff: later side lobes transmit some higher-frequency components, and suppressing a component is only helpful when that component is unwanted. The frequency plot is the same operation as the delayed-sample average; the five-vector diagram explains one exact zero geometrically.