(一)数据处理1.按照最小二乘法原理编写matlab程序;x=[-200-10001002003004005006007008009001000110012001300]y=[-5.8914-3.553604.09628.138512.208616.397120.644324.905529.12933.275437.325941.275645.118748.838252.4103]n=16;sx=sum(x);sy=sum(y);sxx=sum(x*x');sxy=sum(x*y');k=(n*sxy-sx*sy)/(n*sxx-sx*sx);a0=(sxx*sy-sx*sxy)/(n*sxx-sx*sx);sprintf('y=%d+(%d)*x',a0,k)x=-200:100:1300;y=a0+k*x;plot(x,y)%绘出曲线运行结果:ans=y=6.191137e-001+(4.027415e-002)*x2.采用matlab自带的拟合函数进行线性你和,对前面的结果进行验证;x=[-200-10001002003004005006007008009001000110012001300]y=[-5.8914-3.553604.09628.138512.208616.397120.644324.905529.12933.275437.325941.275645.118748.838252.4103]p=polyfit(x,y,1);vpa(poly2sym(p),4)x0=-200:100:1300;-2000200400600800100012001400-100102030405060y0=polyval(p,x0);subplot(2,1,1)plot(x,y,'*r',x0,y0,'-b')xlabel('x');ylabel('y');title('一阶线性拟合');gridsubplot(2,1,2)plot(x0,y0,'-b')xlabel('x');ylabel('y');title('原理图与线性拟合对比');grid运行结果:ans=0.04027*x+0.6191经过与(1)中结果的对比,证明了程序的正确性。3.采用matlab自带的拟合函数进行二次曲线拟合,并给出线性拟合的误差分析;x=[-200-10001002003004005006007008009001000110012001300]y=[-5.8914-3.553604.09628.138512.208616.397120.644324.905529.12933.275437.325941.275645.118748.838252.4103]p=polyfit(x,y,2);vpa(poly2sym(p),4)x0=-200:100:1300;y0=polyval(p,x0);subplot(2,1,1)plot(x,y,'*r',x0,y0,'-b'),legend('拟合曲线','样本点')xlabel('x');ylabel('y');title('二阶线性拟合');grid运行结果:ans=0.0000004701*x^2+0.03976*x+0.6614-2000200400600800100012001400-200204060xy一阶线性拟合-2000200400600800100012001400-200204060xy原理图与线性拟合对比误差分析x=-200:100:1300;y1=[-5.8914-3.553604.09628.138512.208616.397120.644324.905529.12933.275437.325941.275645.118748.838252.4103];y=0.0398*x+0.6614;d=y-y1;m=max(d)Y=m/(1300*0.0398-0.0398*(-200))%线性度运行结果:m=0.6614Y=0.0111线性拟合后的灵敏度为0.398mV/℃,最大偏差0.66614mV,线性度1.11%。通过比较,直线拟合的平均误差与二次曲线拟合的平均误差近似,但前者误差较大。-2000200400600800100012001400-100102030405060xy二阶线性拟合拟合曲线样本点(二)传感器动态特性分析;1.对零阶传感器的动态特性进行仿真,并对仿真结果进行讨论;用matlab、simulink搭建的仿真图:仿真结果:零阶传感器输入与输出呈正比关系,并且与频率无关,无相位失真和幅值失真问题。51TransferFcn151TransferFcnsimout1ToWorkspace1simoutToWorkspaceStepSineWaveScope1Scope01020304050600246阶跃信号零阶传感器动态特性0102030405060-505正弦信号零阶传感器动态特性2.对一阶传感器的动态特性进行仿真,并对仿真结果进行讨论;用matlab、simulink搭建的仿真图:由图可知,随时间的推移,输出最终与输入呈正比。一阶传感器具有一定的延迟。5s+1TransferFcn15s+1TransferFcnsimout1ToWorkspace1simoutToWorkspaceStepSineWaveScope1Scope01020304050600246阶跃信号一阶传感器动态特性0102030405060-4-2024正弦信号一阶传感器动态特性3.对二阶传感器的动态特性进行仿真,并对仿真结果进行讨论,特别需要对阻尼比系数分情况进行讨论。用matlab、simulink搭建的仿真图:阻尼比:=0.5此为欠阻尼情况,阶跃响应峰值超过稳态值,出现过峰现象。4s+2s+42TransferFcn14s+2s+42TransferFcnsimout1ToWorkspace1simoutToWorkspaceStepSineWaveScope1Scope010203040506000.511.5阶跃信号二阶传感器动态特性0102030405060-2-1012正弦信号二阶传感器动态特性阻尼比:=1此为临界阻尼系统,阶跃响应不出现过冲;4s+4s+42TransferFcn14s+4s+42TransferFcnsimout1ToWorkspace1simoutToWorkspaceStepSineWaveScope1Scope010203040506000.51阶跃信号二阶传感器动态特性0102030405060-1-0.500.51正弦信号二阶传感器动态特性=2.0此为过阻尼系统,阶跃响应不出现过冲。通过比较欠阻尼,临界阻尼,过阻尼,得知随着阻尼比的增大,响应曲线的幅值不断变小,且出现滞后,延迟时间增长。4s+8s+42TransferFcn14s+8s+42TransferFcnsimout1ToWorkspace1simoutToWorkspaceStepSineWaveScope1Scope010203040506000.51阶跃信号二阶传感器动态特性0102030405060-1-0.500.51正弦信号二阶传感器动态特性