This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Determine acquired signal slope

Determine acquired signal slope

Hello:

 

I’m not sure as to where this post should me inserted so I ask the moderators to feel free to change the post insertion forum if they find it convenient.

I’m using msp430 launchpad and I’m acquiring a very slow rising signal. It takes up to 24h to go from zero to 5v. I’m sampling the signal in this way (it is just an example, timings may vary):

               1 – I take 16 samples with a  1second interval and store the average value;

               2 – The processor sleeps for 10 s and the process is repeated.

               3 –After 1 minute  I have six samples

               4  - After 1 hour I have one array  of 360 samples.

               5 – I may go on…as after 10 hours I have 3600 samples…

How do I determine the signal slope? Any ideas?

I’m running on harvested energy so I must have a very efficient code but for now I just want to have ideas on how to determine the signal slope. By the way, it’s always a rising slope…

Tks for your time,

Pedro

  • The slope of a voltage signal is given in Volts/second.

    You need some way to keep track of time since start of acquisition, so keep a counter value that increments every 10 seconds.

    Then your slope is simple (end_value - start_value) / time

    You will probably want to avoid floating point math. If so, consider looking into a fixed point format such as Q3.12 (or whatever you need for resolution) for the math. Division function will be your most inefficient part of the calculation.

  • That is a basic math question. Two points (or 3600, doesn't matter) on an X/Y diagram. X is time, Y is value. What is the slope? Take a ruler and see yourself. Then convert this into an algorithm (a one-liner should be sufficient)

    You really should be able to figure out on your own. Being able to do things like this was prerequisite for the engineers math course at university.

    However, taking 16 samples over 16 seconds (1s interval) and then 10s pause gives a rather distorted curve. But I guess, you just explained it wrong, as taking 16 samples with 1s interval and then sleeping 10s gives you only 2.4 samples per minute and not 6.

  • You do not have enough SRAM to keep more than 250 samples. (And you do not need to either. You can make a Least-Squares Fit to estimate the slope along the way without storing the samples in an array.)

    If it takes 24 hours to go from zero to full scale of your ADC10, it takes 84 and some seconds to see the ADC10 readings to change by 1 count.

  • Hello:

    Tks everybody for your answers. 

    I was looking for an answer like the one old_cow_yellow gave. Indeed I have scattered data and the matter is not as simple as using a ruler (I was able to figure this out all by myself :) ), in fact, ADC10 readings do vary before 84 seconds so data is averaged after 16 times 1 second reading. Moreover my timings are quite flexible so I just described an example without giving much thought to it. On the other hand I do have memory issues as stated by old_cow_yellow. 

    Can someone point out some application note or other documentation to a least mean square fit algorithm implemented using a microcontroller (msp430, 8051...)

     

    Tks again,

    Pedro

  • The Least Square Fix of the slop of N pairs of x and y is:

    Slope = (N*Sum(x*Y) – Sum(x)*Sum(y)) / (N*Sum(x^2) – (Sum(x))^2);

    You can make your life easier by taking equal steps in x. (Of whatever length in time periods.)

    x = 1, 2, 3, ... , N;

    In this case, you only need to accumulate Sum(y) and Sum(x*y) along the way. The calculations of Sum(x) and Sum(x^2) can be carried out at compilation time (as oppose to run time):

    Sum(x) = N*(N+1) / 2;
    Sum(x^2) = N*(N+1)*(2*N+1) / 6;

  • I'm sorry for the delay.

    I've implemented the solution you proposed but I still don't have conclusive results. I need further tests to understand what is happening. For now my slope is taking some time to reach a reasonable value. The first calculi are clearly bogus and I still could not understand why...

    I'll post an update as soon as I have conclusive results.

    I implemented the following code

      s1 += sendData.NIndex;                      //sendData.NIndex -> x value

      s2 += sendData.NIndex * sendData.NIndex;

      s3 += sendData.VstorageValue;

      s4 += sendData.NIndex * sendData.VstorageValue;

                         

       if (denom = sendData.NIndex * s2 - s1 * s1)

           {

                  sendData.slope = (s3 * s2 - s1 * s4) / denom;

            }

          sendData.NIndex++;

    And all my variables are declared as int. Would it make any difference if I declared them as uint?

    I'll test and post results...

  • Watch out for what is the expected values of x and y when you try to do the accumulation and calculations. Using int may overflow and wrap around. You may need to use long or even long long.

**Attention** This is a public forum