Nigel Goodwin said:
I would suggest you give full details of exactly what you're wanting to do, as it is people can only guess!.
You're right. I just don't write english very well and I was trying to minimize the writing.
I'm making an ECG (electrocardiogram) synthetizer/simulator. You load the interesting points of a ECG in the uC (you load the position(time since the last point, 0-~100, I don´t remember) and amplitud (0-255) of the PQRST points, and the frequency of the hearth beat) , and this algorithm interpoles the values of the ECG between two consecutives points at 2 ms intervales. For example, you say that Q comes 30 ms after P, and have an amplitud of 20. So the algorithm calculates since2ms , every 2 ms, until 60 ms, the intermediate points. This interpolation is cubic
, and the critic term is:
-2*[ y (T) – y (0) ]*t^3 / T^3
wherte y(t) is the amplitud of the ECG at time t, and T is the duration of the segment (t<T always).
Because I'm using 8bit uC (89s52), this is tricky. I found a math library to multiply or divide two 16 bits numbers, but I must be carefull that the multiplication result doesn't go beyond 16 bits (T^3 >>16bits), or I will not be able to divide. Also, I need to avoid dividing t/T at the begining because result is always zero + reminder. So I first multiply 2*[ y (T) – y (0) ] by t, then divide by T. Then multiply again by t, then divide by T. One more time, *t/T.
This method works pretty fine, with some error when rounding the divisions.
My problem is that 2*[ y (T) – y (0) ]*t can be > than 8 bits... in fact, if I not carefull with the values, can be > than 16 bits.
Well, that's pretty much the picture. Some points:
- The truth is that I need to divide 16 bits by 8 bits, but I didn't find this algorithm, which probably is much faster than 16bits/16bits, and I don't have the knowledge neither the will to try to write it.
- The ECG is periodic, so technically, I can calculate every point at the start of the program, and then just output then. The problem is that the 89s52 has only 256by ram (I think I calculate aprox 400 different values), and I don't want to use external RAM.
I think that the best idea is not to do the cubic interpolation for every point, but just for some at the star of the program (maybe 100 values ) and use linear interpolation for the rest of the values. This could be very interesting, because it would allow me to reduce A LOT the speed of the oscillator (practically as much as I want) , and this is probably the line I will follow
But I still want to hear about cheap, small, and simple 16 bits uC (if they exists), or at least something equivalent to the 89s52 with 16 bits.
Are you still there? Had you read all this? Thank you!