# Help on implementing an IIR filter

I am new to signal processing and and having difficulty understanding how to implement an IIR filter. The reference is athttp://www.dxatlas.com/rocky/Advanced.asp in the Band scope section. It concerns applying an IIR filter to a power spectrum with this equation:

FilteredSpectrum[i] = FilteredSpectrum[i]*(1-gain) + NewSpectrum[i] * gain

I understand that this is a classic 1st order IIR filter but to implement this, are you working data point by data point or are you using one complete spectra and then waiting for the next one (NewSpectrum) and calculating a whole new spectrum from the existing one and the new one that just came in? I tried it this way, waiting to obtain the data for a whole spectrum, then waiting for the next one to come in and then doing the calculation. I then plot the resulting spectrum. This then becomes the FilteredSpectrum while I wait for the next NewSpectrum. Is this being done in the correct way? I programmed this but saw no effect on the noise in the spectrum contrary to the article. Can anyone tell me where I am going wrong? Thanks

The spectrum NewSpectrum appears to be the output of the FFT of the current data block, and FilteredSpectrum on the right-hand side of the equation is the filtered spectrum of the previous block. The index i is the frequency index, so you use this recursion for each frequency point. Note that the value of gain is crucial. It should be in the range $(0,1)$, where a value of $1$ means no filtering at all, and $0$ means no update at all.