Does anyone know of a software library (source code) that I could port to
the PIC for real-time filtering? I'm grabbing A/D data and want to do some
basic artifact removal in software (real-time hopefully, before sending it
to another processor) but I need a starting place of some working code. Any
language would be fine...
> Does anyone know of a software library (source code) that I could port to
> the PIC for real-time filtering? I'm grabbing A/D data and want to do some
> basic artifact removal in software (real-time hopefully, before sending it
> to another processor) but I need a starting place of some working code. Any
> language would be fine...
Could you be more specific? Are you wanting to implement a low-pass,
high-pass, iir,fir,correlation, median, OT, or what filter?
Except for OT filters, solutions of each of these has been presented one
time or another on the Piclist.
> Could you be more specific? Are you wanting to implement a low-pass,
> high-pass, iir,fir,correlation, median, OT, or what filter?
>
> Except for OT filters, solutions of each of these has been presented one
> time or another on the Piclist.
>
Low-pass, high-pass, notch.... I did a general web search and didn't come
up with much. Thanks though - I'll check the archives for more info.
> On Fri, 21 Jan 2000, Jeffrey Siegel wrote:
>
> > Does anyone know of a software library (source code) that I could port to
> > the PIC for real-time filtering? I'm grabbing A/D data and want to do some
> > basic artifact removal in software (real-time hopefully, before sending it
> > to another processor) but I need a starting place of some working code. Any
> > language would be fine...
I accidently deleted you're other response... dammit.
Let me ask the question more specifically. In the low-pass filter case,
for example, do you want to implement an FIR or an IIR? What kind of
signal bandwidth are you seeking. How much passband ripple are you willing
to tolerate? Are you just trying to remove some sampling clock artifact?
What's the application?
If you're looking for general purpose signal processing, then you probably
don't want to waste your time with pics - at least not the 12 and 14 bit
cores. Digital signal processing (as taught at your college) relies
heavily on multiply and accumulate operations. The low end pics don't have
a multiplier, the high end ones do, but can't do a single cycle MAC. Butt,
there's always a trick. Unfortunately, the tricks are seldom generic. For
example, the 'twist' routine I posted the other day, can be used as
low-pass, one-tap, IIR filter. It implements this 'transfer function':
f = (m*x + n*y)/N
Subject to the conditions:
log2(N) is an integer (N is a power of 2, e.g. 16, 32, 64...)
m + n = N
x and y are the inputs and f is the output.
Now if you make f = y, which is to say that for the next iteration through
the filter, you use the results of the previous iteration for y, you'll
have a low pass recursive (IIR) filter. The pole can be adjusted by
varying the coefficients. I haven't performed any kind of frequency
analysis on this, but if you take the z transform:
f = y(i+1) = (m*x(i) + n*y(i))/N
zY(z) = (m*X(z) + n*Y(Z))/N
m*X(z) = (N*z - n)Y(z)
Y(z) m m/N
----- = -------- = --------
X(z) N*z - n z - n/N
The pole, n/N, is always less than one and thus within the 'unit circle'.
Consequently the filter is stable. If you make n small, you get a slower
response. As n approaches N and the pole gets closer to one, the response
is faster.
Now it's possible to cascade these blocks too, and somewhat tailor your
filter's cutoff, ripple, etc...
But theory aside, this simple example ignores many practical issues. The
original code I posted used N=16. This gives you only 4 bits of dynamic
range on your coefficients. You'd be hard pressed getting arbitrary pole
placement with this much dynamic range. Quantization erro will kill you.
But again, it depends on your application.
Putting in my own two pennies worth, I have an application
that might benefit from a digital lag filter. Though I can find
a theoretical description, it isn't enough to suggest what
the actual code might be. Any pointers?
Brian Aase
May be all you need is math library. If all you want to remove from
signal is short peaks, exponential filter is enough. It has the
following transfer function
1
W(s)= ------
Ts + 1
Calculation scheme is very simple.
Let us call x the result from ADC and filtered result.
Alpha is ]0,1[ and determines time constant T. The bigger is alpha,
the smaller is T.
0) measurement ( x = ADC_result )
1) y = x
2) y_before = y
3) measurement ( x = ADC_result )
4) delta = x - y_before
5) y = y_before + alpha*delta ---> the next filtered number is ready
6) goto 3
So all you need is signed addition and multiplication. Be aware of
number of binary digits used to store y_before and to do all
calculation. If your ADC is 8-bit, I think you need 16-bit to get true
exponential filter. Your filter's step response shall look like this
JS> Does anyone know of a software library (source code) that I could port to
JS> the PIC for real-time filtering? I'm grabbing A/D data and want to do some
JS> basic artifact removal in software (real-time hopefully, before sending it
JS> to another processor) but I need a starting place of some working code. Any
JS> language would be fine...