This function uses the method of least squares to find a best fit line. This point by point calculation takes each new (x,y) value and updates the slope and intercept. This function serves application in Math and Signal processing as well as data reduction. Included in the download is the IP, a windows testbench, and a FPGA emulation test bench.
The method of Least Squares is a standard method for finding the line of best from two or more data points. The equations for the slope (a) and y-intecept (b) are shown in the image below. Each iteration it uses this calcuation to output a new slope and intercept based on the previous calcuation and the new data point. Use the initialize boolean to start the calculation from scratch.
There is a readme file included in the download with more information
Note: this function uses the fixed-point data type in LV FPGA. All controls indicators and functions have been manually set to 64,32, which is an all purpose setting but uses more space than presumably necessary. You may work with the word and integer lengths to optimize this function to serve your input limits and tolerance for error. Additionally, you must download and install the Fixed-Point library at NILabs (ni.com/labs) to use this IP Block.
Other requirements:
This function also requires the Fixed-p oint library found on NILabs (ni.com/labs). It uses a function from this library to implement the divide and pipelined 64-bit multiply
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.