IIRFilter Bandpass Filter Unexpected Behavior

Hey their,

I am trying to create a short ultrasonic chirp frequency bound to between 36-44khz. I figured I would do this by creating a 36-44khz chirp and then using a Butterworth bandpass filter to filter out all unwanted frequencies outside of my 36-44khz range. The filter works at filtering out most frequencies however it seems to struggle to filter out 80khz and 10hz. I’m not sure why this is, am I doing it wrong or is this a limitation of the filter in general? Note: the chirp is only 288 samples long at a sample rate of 192khz.

Any help is appreciated!

Thanks :slight_smile:

	    	for (int index = 0; index < chirpLengthInSamples; index++) {
				const auto output = sin(phaseValue * (2.0 * double_Pi));
				//const auto frequency = m_min_f * exp((log(m_max_f / m_min_f) / chirpLengthInSamples) * index); //eponential
				const auto frequency = ((((m_max_f - m_min_f) / chirpLengthInSamples)*index)+m_min_f); //linear growth
				phaseValue += frequency / sampleRate;

				if (phaseValue > 1.0) {
					phaseValue -= 1.0;
				//save value to the chirp array
				ChirpSignalArr[index] = output;

		}//end chirp generation
IIRFilter bandpassFilter;
		IIRCoefficients coefficent;
		int rollOffBandPass = 1; //the steapness of the rollof of frequencies outside the desired band
		int rollOffWindow = 4;
		double middleFrequency = ((m_max_f - m_min_f) / 2.0) + m_min_f; //finds the middle frequency between Fmax and Fmin
		double frequencyResponse = sqrt((m_max_f * m_min_f)); //finds the frequency responce
		double bandWidth = m_max_f - m_min_f; //calculates the bandwidth
		double QFactor = frequencyResponse / bandWidth; //finds the overall Q factor to be used

		//Apply the bandpass filter on the calculated signal
		bandpassFilter.setCoefficients(coefficent.makeBandPass(currentSampleRate, frequencyResponse, QFactor));
		for (int i = 0; i < rollOffBandPass; i++) {
			bandpassFilter.processSamples(ChirpSignalArr, chirpLengthInSamples);

		//apply hamming window
		for (int i = 0; i < rollOffWindow; i++) {
			window.multiplyWithWindowingTable(ChirpSignalArr, chirpLengthInSamples);

Did you check the response before filtering? Maybe they’re just too loud from the start.

I tried normalizing everything to between 1 to -1 around a 0 center at different spots and one run with everything normalized whenever weight was applied to the signal and still no dice :confused: doesn’t look like the issue is caused by it being too loud or a rounding error.

I meant if you checked the frequency response of the chirp before the bandpass, to see if it already peaked at 10 and 80k. The bandpass will only go to 0 at 0 and sr/2.

You could bandpass multiple times, but I think the problem is the chirp starts and stops instantly at 0 and chirpLengthInSamples which will generate other frequencies. Make sure the chirp signal ends at a zero crossing. Smoothly fading the chirp in and out will improve things, but then you have to decide if you expand the frequency range a bit so it’s loud enough over the frequency range you want.