interpreting a wave from clipped sensor data
March 11, 2009 6:56 PM
Subscribe
interpreting a wave from sensor data - what to do about maxed out sensors that are clipping the wave - an absurdly complex question
hello hive mind,
this is the most ridiculously complex question I have ever asked here,
but the ability of metafites to slice through unreasonably convoluted quandaries with graceful ease,
has lead me to fear I have not been doing my share to feed the hive with sufficiently challenging questions
I shall now attempt to remedy this.
I am writing a small program to reads in sample data from a sensor, which is measuring the force on an object which is moving backwards and forwards.
These force values seem - to my surprise- to usually be a bit like a sawtooth wave, I just figured they would be a sine wave.
I've never done anything like this before so I've done a lot of re-inventing of the wheel along the way.
The samples from the sensor have a timestamp.
The samples are:
fairly evenly time spaced, but not perfect.
are digitised to one of 256 values, so are not perfectly accurate
the wave is a quite uneven:
it usually seems to be closer to a sawtooth that a sinewave, but its hard to tell sometimes especially when its clipped
amplitude and frequency wobble all over the place
My program tries to make sense of the wave in realtime.
The program takes particular notice of:
the high and low peaks and
the zero crossings,
From this it creates a sort of sawtooth description of the wave.
The zero isn't perfectly calibrated, but i think its good enough.
To know when the wave has reached a high peak, I wait until the size of the sample value starts to fall, and figure that the highest point was the peak.
This usually works, although sometimes there are wobbles in the signal that confuse the algorithm into thinking the wave has peaked early.
To get around this I have used a threshold "minimum fall from peak value" before I designate a peak has occurred.
Now for the tricky park:
Often the sensor gets maxed out, so my wave gets clipped, which makes it hard to work out where the peak is.
And it makes it really hard to work it out in realtime while the samples are still in the clipped zone.
If a peak is clipped, the next one is usually clipped too.
this what I am currently doing:
if a wave peak was clipped, then next time I cross zero:
I extrapolate a line from the zero crossing point before the peak, through the last good unclipped sample before the peak
I extrapolate another line from the zero crossing point after the peak, through the first good unclipped sample after the peak.
where these lines cross, is where I assume the peak was
this seems to work ok, but if I had some way of better analysing the waveform I'd use it.
This was just the best I came up with (also it all needs to happen in realtime on a not very fast chip)
When my wave moves to the opposite peak, I have a pretty good estimation of the previous peak.
If when approaching the next peak the sensor maxes out, then I assume, that peak is going to be somewhere on the trajectory I am currently on:
If I extrapolate a line from:
the zero point
through:
the last good unclipped sample before the peak.
that the peak will fall somewhere on this line
but I need to know how far along the trajectory the peak will be.
To predict this I've assumed that the peak force on the object occurs at the extremes of its motion, which also mean that the peak force occurs when the object is stationary
As the object is going from rest to motion to rest again, I assume that acceleration impulse and the deceleration impulse from peak to peak must be of equal magnitude.
using:
the time of the previous peak
the size of the previous peak
the time of the zero crossing
I can estimate the impulse which accelerates object
and that the impulse which stops the object must have the same magnitude
rate of increase of deceleration force = good sample value /(good sample time - zero time);
time object will decelerate = square root( (zero time - previous peak time) * previous peak height / rate of increase of deceleration force)
This produces an answer that's not ridiculously wrong, but not bang on either.
so I use this as a tentative value until, next time the samples fall back to zero, when I recalculate the peak size and time.
neither my predicted or later retrospectively calculated answers are perfect, but the retrospective ones 'look' better
I'm not sure where my biggest errors are:
perhaps its treating the wave as a sawtooth?
perhaps its placing too much faith in a single sample when extrapolating trends?
I've been trying to compare my predicted peaks, with the peaks I calculate later after the peak is finished, and try to adaptively adjust the predictions
Any suggestions on what I could do better?
How I could best adaptively adjust my predictions?
cheers
mathew
oh p.s. there is nothing i can do to the sensors or their placement to prevent them from clipping
posted by compound eye to science & nature (13 comments total)
also, i don't think i understand what your ultimate goal is here. are you trying to determine (for example) the dominant frequency of the wave? Or something else? Your question reads to me like you've picked your current path on the way to something else that you haven't described, because you think if you can sort this out then you'll solve the other problem. Sometimes it's useful to state the ultimate goal, because then other people can propose entirely different strategies.
For example, if you're looking for a dominant frequency, it's often simpler to compute the Fourier transform (using FFT is common in digital signal processing. In that case, i'd start by searching for details about tricks for coping with clipped signals in an Fourier transform. Or you could just discard the clipped data, and look around for tricks about Fourier transforms with missing data.
Sorry that this doesn't fully answer the question; hope it gets you closer, though!
posted by dkg at 7:18 PM on March 11