Maker Pro
Maker Pro

fixed point digital low pass filters

J

Jamie Morken

Jan 1, 1970
0
Hi,


I used this digital filter design tool:
http://www-users.cs.york.ac.uk/~fisher/mkfilter/

to generate code for a first order Butterworth floating point
low pass filter with 250kHz sampling frequency, and a 100kHz
corner frequency.

This would require a DSP to run on, since I need 6 of these
filters running in parallel, so is there a way to do the same
filtering with fixed point code to run on a microcontroller?
The input values to the filters are fixed point 16bit ADC values.

Can I convert the floating point code to fixed point?

Here's the floating point code that mkfilter generates:


//filter code
#define NZEROS 1
#define NPOLES 1
#define GAIN 1.324919696e+00

static float xv[NZEROS+1], yv[NPOLES+1];

static void filterloop()
{ for (;;)
{ xv[0] = xv[1];
xv[1] = next input value / GAIN;
yv[0] = yv[1];
yv[1] = (xv[0] + xv[1])
+ ( -0.5095254495 * yv[0]);
next output value = yv[1];
}
}
//end of filter code



cheers,
Jamie
 
V

Vladimir Vassilevsky

Jan 1, 1970
0
Jamie Morken said:
Hi,


I used this digital filter design tool:
http://www-users.cs.york.ac.uk/~fisher/mkfilter/

to generate code for a first order Butterworth floating point

The first order filter is just the first order filter. It can't be worth
butter or anything.
low pass filter with 250kHz sampling frequency, and a 100kHz
corner frequency. This would require a DSP to run on, since I need 6 of these
filters running in parallel, so is there a way to do the same
filtering with fixed point code to run on a microcontroller?

Probably even MSP430 or 68HCS12 could be sufficient.
The input values to the filters are fixed point 16bit ADC values.

The real question is what are you trying to accomplish by this filtering. A
first order corner at 100kHz at a sample rate of 250kHz doesn't seem to make
much sense.
Can I convert the floating point code to fixed point?

It is certainly possible, however I don't know if you can :)
Here's the floating point code that mkfilter generates:

[...]

What a horrid code.

VLV
 
T

Tim Wescott

Jan 1, 1970
0
The first order filter is just the first order filter. It can't be worth
butter or anything.


Probably even MSP430 or 68HCS12 could be sufficient.

IIRC both of these processors top out at about 40MHz clock speed. So
you're saying he can run six second-order, 32-bit precision filters in
160 clock ticks on a 16-bit processor?

Interesting.
The real question is what are you trying to accomplish by this
filtering. A first order corner at 100kHz at a sample rate of 250kHz
doesn't seem to make much sense.


It is certainly possible, however I don't know if you can :)

One can make this conversion with proper guidance; I don't know if anyone
could with Vladimir as his only source of information.
Here's the floating point code that mkfilter generates:

[...]

What a horrid code.

And thank you for increasing world knowledge by saying why.

--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
 
T

Tim Wescott

Jan 1, 1970
0
Hi,


I used this digital filter design tool:
http://www-users.cs.york.ac.uk/~fisher/mkfilter/

to generate code for a first order Butterworth floating point low pass
filter with 250kHz sampling frequency, and a 100kHz corner frequency.

I find it odd that your corner frequency is only 80% of your Nyquist
rate. You really aren't going to be achieving much by filtering this
data.

Perhaps you should go over exactly what you're planning to achieve, and
with what data.
This would require a DSP to run on, since I need 6 of these filters
running in parallel, so is there a way to do the same filtering with
fixed point code to run on a microcontroller? The input values to the
filters are fixed point 16bit ADC values.

This is going to consume a lot of clock ticks on either a microprocessor
or a DSP chip. Expect to need to use 32-bit arithmetic (or 24, if you
like old Motorola DSP chips). Plan on benchmarking this, and don't
expect to do it on a cruddy old PIC.
Can I convert the floating point code to fixed point?

Yes you can. Search around on the web, see if you can find an article
about fixed-point or fractional arithmetic. All the processors that I've
used support some sort of fractional arithmetic, at least indirectly --
DSP chips support it directly, and 'regular' processors support it by
coughing up both (or selectable) parts of the double-precision result you
get when multiplying two single-precision numbers (I.e. if the processor
is a 16-bit one, an integer multiply will either fill two registers with
the high and low parts, or there will be two integer multiplies, one for
each part).

Otherwise Really Fast Processors can take multiple clock ticks to do
multiplication (never mind divide), so remember to benchmark or count
clock ticks when you investigate doing this in fractional arithmetic.
Here's the floating point code that mkfilter generates:


//filter code
#define NZEROS 1
#define NPOLES 1
#define GAIN 1.324919696e+00

static float xv[NZEROS+1], yv[NPOLES+1];

static void filterloop()
{ for (;;)
{ xv[0] = xv[1];
xv[1] = next input value / GAIN;
yv[0] = yv[1];
yv[1] = (xv[0] + xv[1])
+ ( -0.5095254495 * yv[0]);
next output value = yv[1];
}
}
//end of filter code

This is _not_ the best code, although I presume it works. Here again,
you could do well to search the web for IIR filter information. I'd
suggest you think about getting a copy of "Understanding Digital Signal
Processing" by Rick Lyons as well -- there's a whole chapter on choosing
which IIR filter is the right one in what circumstance.

--
Tim Wescott
Control systems and communications consulting
http://www.wescottdesign.com

Need to learn how to apply control theory in your embedded system?
"Applied Control Theory for Embedded Systems" by Tim Wescott
Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
 
V

Vladimir Vassilevsky

Jan 1, 1970
0
IIRC both of these processors top out at about 40MHz clock speed. So
you're saying he can run six second-order, 32-bit precision filters in
160 clock ticks on a 16-bit processor?

Where did the second order and 32 bit precision come from?
What I said that it could be possible to fit six first order filters @ 16
bits @ 250kHz into HCS12 or MSP430.
Interesting.

"If you give me $1000, I will do it much better and more efficiently" (tm)
One can make this conversion with proper guidance; I don't know if anyone
could with Vladimir as his only source of information.

Wasn't that an exact answer to the question asked?
Here's the floating point code that mkfilter generates:
[...]
What a horrid code.

And thank you for increasing world knowledge by saying why.

I certainly kneel before the prophets who can preach about 2 x 2 = 4, and
who can say a lot without telling anything.

VLV
 
Top