Teach you how to do interpolation algorithm on a single chip microcomputer

Publisher:RadiantGazeLatest update time:2021-07-01 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Step 1: Learn what you need to learn, even if you don’t understand it. Here comes the most boring math formula


In numerical analysis, Lagrange interpolation is a polynomial interpolation method named after the French mathematician Joseph Lagrange in the 18th century. In many practical problems, functions are used to represent some internal connections or laws, and many functions can only be understood through experiments and observations.


For example, if we observe a physical quantity in practice and obtain corresponding observation values ​​at several different places, the Lagrange interpolation method can find a polynomial that takes the observed value at each observation point. Such a polynomial is called a Lagrange (interpolation) polynomial.


Mathematically speaking, the Lagrange interpolation method can give a polynomial function that passes through a number of known points on a two-dimensional plane. The Lagrange interpolation method was first discovered by the British mathematician Edward Waring in 1779, and was rediscovered by Leonhard Euler shortly afterwards (1783). In 1795, Lagrange published this interpolation method in his book "A Course in Elementary Mathematics for Normal Schools", and his name has been associated with this method ever since.

picture

Step 2: Construct the Lagrange interpolation algorithm function and implement it in C/C++
picture

//Predefine the number of interpolation nodes to 1000, and determine the number of interpolation nodes according to the number num input by the console const int N=1000; // Lagrange interpolation algorithm float lglr(float x[], float y[],int n,float t){float yResult=0.0; //LValue[N] stores the general term of the interpolation basis function solved each time float LValue[N]; //Loop variables k, mint k, m; //Up and down multiplications in the interpolation basis function temp1, temp2 float temp1, temp2; for(k=0;k

Step 3: Test the linear interpolation effect
1. Input 3 points of the oblique line to the written algorithm to predict other points in this interval. It is found that the predicted linear value is very good and the linearity is full.


2. Also input 3 points of the sine curve to the written algorithm to predict other points in this interval. It is found that the predicted sine curve is not ideal and the correlation is very poor.



3. Increase the number of points of the sine curve input to the written algorithm to 10 points to predict other points in this interval. It is found that the predicted sine curve has met the requirements and the correlation is very good.


4. The following is an image drawn using matlab, which is an image of the comparison of 3 linear points, sine 3, 5, 10 and the original value.
picture

Step 4: Transplant to the microcontroller and use the serial port output to test the interpolation effect. The effect is OK!
picture

Step 4: Advanced perfection, a little unwilling, using Qt to build an interface and do some visualization.
You can say the effect is good. The Qt interface code is on gitee. If you are interested, please come and improve it together. https://gitee.com/lumengcode/my-qt/tree/master/MathTool/MathTool
picture

Interpolation off-topic:
Regarding the interpolation algorithm: Newton interpolation, cubic spline interpolation, etc. can be further improved. They are all very interesting!
END


Keywords:MCU Reference address:Teach you how to do interpolation algorithm on a single chip microcomputer

Previous article:Some must-read knowledge points for zero-based learning of microcontrollers
Next article:An example of communication between applet and microcontroller (TCP/IP)

Recommended ReadingLatest update time:2024-11-16 11:25

MCU power failure detection and storage
When the microcontroller is working normally, if there is a sudden power failure due to some reason, the data in the data memory (RAM) will be lost. In some applications such as measurement and control, the microcontroller collects and calculates some important data during normal operation, and these important data nee
[Microcontroller]
MCU power failure detection and storage
MCU UART firmware upgrade process
Microcontroller is one of the most basic and commonly used chip types in embedded systems. With the continuous development of technology, the functions and performance of microcontrollers have been increasingly improved, and the size and complexity of firmware are also increasing. In order to ensure the normal operati
[Microcontroller]
Learn MCU in the fastest and best way
As an electronics enthusiast, if you don't understand single-chip microcomputers, no matter you are engaged in maintenance or development, at least you are not a qualified electronics enthusiast now and in the future. I started learning single-chip microcomputers in June 1999, and I think I am okay (I feel good about m
[Microcontroller]
Why not implement the PLC logic on a microcontroller?
A friend wanted to customize a water purifier controller and added some unique functions, but the commercial control board did not have such functions, so he asked me if I could make one. I think the microcontroller can fully meet this simple control need. When I started programming, I suddenly felt that it was very s
[Microcontroller]
Why not implement the PLC logic on a microcontroller?
8051 MCU serial port baud rate and timer 1 initial value calculation
In mode 0 and mode 2, the serial port baud rate is fixed, mode 0 is Fosc/12, mode 2 is Fosc/32 or Fosc/64, which is determined by the SMOD bit of the PCON register. In mode 1 and mode 3, the baud rate is a variable value. The baud rate can be generated by timer 1 (8052 can be generated by timer 2). So what is the baud
[Microcontroller]
#51 MCU #DS18B20 hardware principle and communication working sequence
DS18B20 Hardware Principle - Temperature Memory The temperature measurement range of DS18B20 is -55~+125°C. As shown in the figure above, the DS18B20 temperature memory has two bytes in total. LSB is the low byte, MSB is the high byte. Msb is the high bit, Lsb is the low bit. The S in the figure represents the sign
[Microcontroller]
#51 MCU #DS18B20 hardware principle and communication working sequence
PIC 8-bit microcontroller assembly language common instructions reading
      The instruction system of each major category of single-chip microcomputer is not universal. It is stipulated by the single-chip microcomputer manufacturer, so users must follow the standards stipulated by the manufacturer to achieve the purpose of using the single-chip microcomputer. There   are three levels
[Microcontroller]
Design of intelligent medicine box based on enhanced 51 single chip microcomputer
  This paper introduces the design of an intelligent medicine box based on STC90C516RD+ single-chip microcomputer. The main structures include main control unit, clock unit, alarm unit, display unit, etc. The display unit displays the relevant information of the medicine and the time of taking the medicine, which is c
[Microcontroller]
Design of intelligent medicine box based on enhanced 51 single chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号