DSPRelated.com
Forums

LowPass filter and sampling rate relation

Started by Unknown June 21, 2007
Hi all,
I have found an algorithm that filters an audio signal. The algorithm
uses LP1 filters and produces exactly what I need. The problem is that
the algorithm I found works at 44100Hz, and for my needs it's too
much, I would like to save some CPU cycles and convert it to 22025Hz
or 11025Hz.

If I downsample the input audio signal and I run the algorithm
unmodified, I do not get the desired result since the coefficients of
the LP1 filters are tuned for 44100Hz, and do not work correctly with
different sampling rates.

The LP1 my algorithm uses is as following (Java Code):

public class LP1 {

	private float last;
	private float coeff;
	private float coeff_inv;
	private float gain;

	public LP1(float coeff, float gain) {
		setCoeff(coeff);
		setGain(gain);
		this.last = 0;
	}

	public void setCoeff(float coeff) {
		this.coeff = coeff;
		this.coeff_inv = 1.0f - coeff;
	}

	public void setGain(float gain) {
		this.gain = gain;
	}

	public float tick(float input) {
		last = (coeff * input + coeff_inv * last);
		return last * gain;
	}
}


How can I convert the LP1 coefficients I use at 44100Hz to the 22050Hz
domain? Consider the following algorithm:

float sound[] = getSoundAt(44100);
float output[] = new float[sound.length];
LP1 filter = new LP1(0.45, 0.998);
for (int i = 0; i < sound.length; i++) {
    ouput[i] = filter.tick(sound[i]);
}

If I change the input sampling rate to 22050, which coefficient should
I put in the LP1 filter in order to have the "same" result? I have
empirically found that 0.6 produces a similar result, I would like to
understand how the LP1 coefficients change in relation to the sampling
rate...

Every hint/comment is greatly appreciated
Thanks a lot in advance
Andrea

ciaccia@gmail.com wrote:
> Hi all, > I have found an algorithm that filters an audio signal. The algorithm > uses LP1 filters and produces exactly what I need. The problem is that > the algorithm I found works at 44100Hz, and for my needs it's too > much, I would like to save some CPU cycles and convert it to 22025Hz > or 11025Hz. > > If I downsample the input audio signal and I run the algorithm > unmodified, I do not get the desired result since the coefficients of > the LP1 filters are tuned for 44100Hz, and do not work correctly with > different sampling rates. > > The LP1 my algorithm uses is as following (Java Code): > > public class LP1 { > > private float last; > private float coeff; > private float coeff_inv; > private float gain; > > public LP1(float coeff, float gain) { > setCoeff(coeff); > setGain(gain); > this.last = 0; > } > > public void setCoeff(float coeff) { > this.coeff = coeff; > this.coeff_inv = 1.0f - coeff; > } > > public void setGain(float gain) { > this.gain = gain; > } > > public float tick(float input) { > last = (coeff * input + coeff_inv * last); > return last * gain; > } > } > > > How can I convert the LP1 coefficients I use at 44100Hz to the 22050Hz > domain? Consider the following algorithm: > > float sound[] = getSoundAt(44100); > float output[] = new float[sound.length]; > LP1 filter = new LP1(0.45, 0.998); > for (int i = 0; i < sound.length; i++) { > ouput[i] = filter.tick(sound[i]); > } > > If I change the input sampling rate to 22050, which coefficient should > I put in the LP1 filter in order to have the "same" result? I have > empirically found that 0.6 produces a similar result, I would like to > understand how the LP1 coefficients change in relation to the sampling > rate... > > Every hint/comment is greatly appreciated > Thanks a lot in advance
You are in the unfortunate position of a barbecue host who needs 6-ounce hamburger patties but the store has only half pounders. The host needs to learn to make patties from bulk chopped meat; you need to learn to generate appropriate coefficients from scratch or to adjust the initial sample rate to suit your needs. The code "LP1 filter = new LP1(0.45, 0.998);" affects the signal in proportion to its sample rate. I.e., if it blocks most of the upper half of a signal at 44100, it will block most of the upper half of a signal at any other rate. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
On Jun 21, 1:24 am, ciac...@gmail.com wrote:
> Hi all, > I have found an algorithm that filters an audio signal. The algorithm > uses LP1 filters and produces exactly what I need. The problem is that > the algorithm I found works at 44100Hz, and for my needs it's too > much, I would like to save some CPU cycles and convert it to 22025Hz > or 11025Hz. > > If I downsample the input audio signal and I run the algorithm > unmodified, I do not get the desired result since the coefficients of > the LP1 filters are tuned for 44100Hz, and do not work correctly with > different sampling rates.
Let's say the cutoff for the filter working at 44.1kHz is fc... then at a clock of 22.05kHz, it will simply be fc/2. If you really wanted a filter to cut-off at fc when working at 22.05kHz, you need to find a filter that cuts off at 2fc while working at clock of 44.1kHz. The coefficients you need for this are best found by designing from scratch. Also, when you say you downsample, I would be a little cautious. Unless you are 100% certain the 44.1kHz audio doesn'd contain any signal above 11.025kHz, downsampling to 22.05kHz will introduce aliasing from frequencies > 11.025kHz in the original signal wrapping into the new baseband of 11.025kHz. The first step to downsampling is first low-pass filtering... so you might be stuck with a LPF running at 44.1kHz one way or the other.
On 2007-06-21, ciaccia@gmail.com <ciaccia@gmail.com> wrote:
> > If I downsample the input audio signal
How do you plan to downsample the input? If you can't afford to run your very simple filter at 44kHz, how are you going to reduce the sample rate? If you are careless in that step, your filter that "produces exactly what you need" might not do you any good anyway. -- Ben Jackson AD7GD <ben@ben.com> http://www.ben.com/