在stm32温度采样的过程中,使用到了NTC传感器,上拉接6.2K的电阻,信号给AD采样端口,通过NTC的电阻阻值表中,计算得到下面两端数据,在freemat中实现数据拟合,用于程序中温度和电压信号的转换。
x = [1173.32
1203.94 1234.89 1266.77 1298.86 1331.75 1365.33 1399.55 1434.31 1469.54 1505.45 1541.66 1578.63 1616.24 1654.15 ];y=[60.000 59.000 58.000 57.000 56.000 55.000 54.000 53.000 52.000 51.000 50.000 49.000 48.000 47.000 46.000 ];figuresubplot(2, 1, 1)p = polyfit(x,y,2);ti=1173:10:1690;yi=polyval(p,ti);plot(x,y,'o',ti,yi,'*');grid onpsubplot(2, 1, 2)p = polyfit(x,y,1);ti=1173:10:1690;yi=polyval(p,ti);plot(x,y,'o',ti,yi,'*');grid onp
p是多项式的系数
--> p
-->ans = 0.0000 -0.0493 107.9274-->ans = -0.0291 93.8403可以得到y=-0.0291x+ 93.8403,以此类推
拟合的图形如下:基本上,一次函数就可以完成数据拟合了,温度采集的精度也可以接受的