# Low Pass Filter Artifacts

I have created a Low Pass filter (I am trying to understand the topic of DSP, and it's hard.. But moving along with samples, books and a nice post on Stack Overflow).

I am saving the 'output' to a file, and I hear a constant clicking noise (very rapid, medium-pitch). The volume (intensity) of the 'clicking' gets louder as there is more intensity (in the passband of my filter).

I have been reading something about possible Artifacts when designing filters (FIR), but I am wondering if this is the constant clicking noise I hear ? It's not bad for my system, because I try to measure the intensity of the 0..100Hz band, and the clicking increases when the low sound increases. But I am just wondering if it's bad, or a possible symptom of a flaw in my filter ?

Thanks!

My Filter (of-course the getLPCoefficientsButterworth2Pole() is called first):

double ax[3];
double by[3];
double xv[3];
double yv[3];

void getLPCoefficientsButterworth2Pole(const int samplerate, const double cutoff, double* const ax, double* const by)
{
double PI = M_PI;
double sqrt2 = sqrt(2);

double QcRaw  = (2 * PI * cutoff) / samplerate; // Find cutoff frequency in [0..PI]
double QcWarp = tan(QcRaw); // Warp cutoff frequency

double gain = 1 / ( 1 + sqrt2 / QcWarp + 2 / ( QcWarp * QcWarp ) );

by[2] = ( 1 - sqrt2 / QcWarp + 2 / ( QcWarp * QcWarp ) ) * gain;
by[1] = ( 2 - 2 * 2 / ( QcWarp * QcWarp ) ) * gain;
by[0] = 1;

ax[0] = 1 * gain;
ax[1] = 2 * gain;
ax[2] = 1 * gain;
}

void process(MTAudioProcessingTapRef tap, CMItemCount numberFrames,
MTAudioProcessingTapFlags flags, AudioBufferList *bufferListInOut,
CMItemCount *numberFramesOut, MTAudioProcessingTapFlags *flagsOut)
{
OSStatus err = MTAudioProcessingTapGetSourceAudio(tap, numberFrames, bufferListInOut,
flagsOut, NULL, numberFramesOut);

if (err)
NSLog(@"Error from GetSourceAudio: %ld", err);

float leftVolume, rightVolume;

NSLog(@"Test: %f", xv[1]);

for (CMItemCount i = 0; i < bufferListInOut->mNumberBuffers; i++) {
AudioBuffer *pBuffer = &bufferListInOut->mBuffers[i];
int cSamples = numberFrames * pBuffer->mNumberChannels;

float *pData = (float *)pBuffer->mData;
float rms = 0.0f;

for (int j = 0; j < cSamples; j++) {

xv[2] = xv[1];
xv[1] = xv[0];

xv[0] = pData[j];
yv[2] = yv[1];
yv[1] = yv[0];

yv[0] =   (ax[0] * xv[0] + ax[1] * xv[1] + ax[2] * xv[2]
- by[1] * yv[0]
- by[2] * yv[1]);

pData[j] = 20 * yv[0];
rms += yv[0] * yv[0];

}

if (cSamples > 0) {
rms = sqrtf(rms / cSamples);
}

if (0 == i) {
leftVolume = rms;
}

if (1 == i || (0 == i && 1 == bufferListInOut->mNumberBuffers)) {
rightVolume = rms;
}
}
}

• Please post a plot of the output. – Peter K. Mar 28 '13 at 15:54
• "plot of the output" ? Remember that I am a newbie :) – Niek van der Steen Mar 28 '13 at 15:54
• Can you graph the output samples you are saving to a file? – Peter K. Mar 28 '13 at 15:56
• No, I mean a screenshot of the time-domain signal. The clicking noise you are hearing is time-domain, so we need to see what is happening there not in the spectrum. Can you upload the audio file somewhere to share? – Peter K. Mar 28 '13 at 15:59
• soundcloud.com/niek-van-der-steen/low-pass-filter-sample Maybe you can hear it's the first few seconds of the Sintel movie :) – Niek van der Steen Mar 28 '13 at 16:01

From the audio clip posted on soundcloud, it looks like there's a discontinuity in the output every ~2060th sample. I suspect that you process your audio stream by blocks and that you do not save/restore the state variables of your filter between each call to the filtering function - so every time you process a new chunk of audio it is as if it was preceded by zeros - which is not the case obviously.

Related question.

• As you can see, my filter vars are 'global' and thus saved. Am I missing something here ? (added my filter code right now) – Niek van der Steen Mar 29 '13 at 16:14
• You were right. I forgot (of-course) that I also have a left and right channel, and those were mixing up now... But I still have a lot of high sounds left in my sound now.... So it doesn't look like my filter's working ? – Niek van der Steen Mar 29 '13 at 16:43

Common causes of clicking sounds in filter output are clipping and accumulator overflow (the numbers your filter is summing together are integers and go larger than the largest possible integer stored on your device).

Having a plot (or the actual samples) of the output would help identify which issue (of these or others not mentioned) it is.