I need to collect data from a sensor and compress (lossy) about 2 to 1. I would like to aim for under 50 lines of C code. The signal is from a 4 bit A/D converter and is roughly a sine wave with slightly erratic amplitude and frequency. There are occasional times where the signal is erratic.
-
Output every other sample. – Mark Adler Apr 08 '17 at 13:56
-
I already increased the sampling period to the max so that would not help. – Jim Lewis Apr 08 '17 at 17:18
1 Answers
"Lossy" is pretty broad and allows for anything. Half the samples. Half the bits. Anything else is going to be a bit involved.
You would have to a) predict the next sample as best you can from the previous samples, b) subtract the prediction from the sample, and c) transmit that difference in two bits or less, on average. Doing this lossy will cause the result to drift, requiring periodic re-centering with the original four-bit sample.
A simple quadratic predictor would be a - 3b + 3c where a, b, c are the last three samples. A sine-wave predictor would be more complex, fitting the frequency and phase and adjusting as you go along.
If your data is noisy, and its only four-bits in resolution to begin with, it is doubtful that you will get any mileage from this.

- 101,978
- 13
- 118
- 158
-
I'd like to play with the a-3b+3c idea - it sounds like it might help. Can you point me to a page that details that a bit more? Did you miss a ^2 somewhere? Which is the oldest sample? – Jim Lewis Apr 08 '17 at 20:45
-
The sample order would be a, b, c, d, evenly spaced in time, with a-3b+3c being the prediction for d. – Mark Adler Apr 08 '17 at 22:33
-
You can easily derive it yourself, fitting a 2nd order polynomial to three evenly spaced points, and then plugging in the position of the fourth point. – Mark Adler Apr 08 '17 at 22:34