Results 1 to 3 of 3

Thread: How to find linear part of measurement data? Calculate linear equation?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default How to find linear part of measurement data? Calculate linear equation?

    Hello,

    i have xy-measurement data that looks like this:

    FindLinearPart.jpg

    I want to find the linear part of a curve and want to draw or calculate the red linear function.
    I have never done this and need some hints how to do that.

    Is there a library (LGPL) that can do this?
    Is there an algorithm for this?

    Any help or hints are welcome.
    Thx

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to find linear part of measurement data? Calculate linear equation?

    What you want to do is called linear regression and you probably should start with the ordinary least squares approach.

    You might find some (heavy duty) library options here: http://stackoverflow.com/questions/2...ression-in-c-c
    I cannot put my hands on a simple function in C right at the moment.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to find linear part of measurement data? Calculate linear equation?

    I agree with ChrisW67 - start with an ordinary least squares approach. Goggle for that, you'll find a googleplex of hits. Probably Wikipedia will be the clearest place for an explanation.

    Least squares fits a straight line to a set of data points in such a way that the total squared deviation (sum of the differences of the actual data value from the fitted value, squared) is a minimum.

    In addition to the error, the least squares method also lets you calculate a regression coefficient. This is a measure of how well the data fall on a straight line. A regression coefficient = 1.0 means a perfect fit, 0 means no fit. The least squares method will produce the equation for a line for any data (except something pathological, where all the points are the same, for example). However, if the data aren't really linear, then you will get a poor regression coefficient.

    The trick in your case is that near the origin, your data deviate strongly from linear. Since you are interested in finding the line that best fits the linear part of your data, you need to tell the least squares algorithm to ignore the non-linear part of your curve. How do you do that? By first calculating the fit using all the data, calculating the regression coefficient, and then iteratively recalculating the fit as you slowly back away from the origin, dropping one point at a time from the fit calculation, until the regression coefficient improves to an acceptable value (i.e. closer to 1.0). You might implement something that compares the current coefficient to the last one, and if it has improved by more than "x" percent, keep going, otherwise stop and sy it's good.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Linear algebra (matrix operations) using Qt5.4 with C++
    By caspardk in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2015, 14:46
  2. Replies: 2
    Last Post: 21st March 2014, 03:44
  3. Linear gradient problem
    By K4ELO in forum Newbie
    Replies: 1
    Last Post: 10th April 2013, 09:57
  4. Linear analog display
    By CoderMan in forum Qt Programming
    Replies: 3
    Last Post: 27th February 2012, 21:30
  5. Non-typical and Non-linear wizard
    By kornicameister in forum Qt Programming
    Replies: 4
    Last Post: 30th December 2010, 16:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.