⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tem_c.m

📁 一个用于建立温度模型的线性回归的温度模型算法
💻 M
字号:
function Tem_c(f)
clear;
clc;
close all;
select=3;
Tdata_files=dir('data/*.dat');
for file_i= 1:length(Tdata_files)
    ff=Tdata_files(file_i).name;
    data = load(fullfile('data/',ff));
    [l,n]=size(data);
    gyro=data(10:l,5:7);
    Tem=data(10:l,8:10);
    ETem=data(10:l,11);
    %%%%%%%%%%%%%%%得标定值%%%%%%%%%%%%%%%%%%%%%%%
%     Kgx=3.912156103;
%     Kgy=-3.894883767;
%     Kgz=3.898891999;
%     Egxy=0.002720;
%     Egxz=0.003296;
%     Egyx=-0.003333;
%     Egyz=0.003296;
%     Egzx=-0.003333;
%     Egzy=-0.003508;
%     D0x = 0.720663;
%     D0y = -2.2;
%     D0z = -0.045417;
%     B=[1  Egxz  Egxy;
%         Egyz  1  Egyx;
%         Egzy  Egzx  1]; 
%     B=inv(B);
%     gyro(:,1)=gyro(:,1)/Kgx-D0x;
%     gyro(:,2)=gyro(:,2)/Kgy-D0y;
%     gyro(:,3)=gyro(:,3)/Kgz-D0z;
%     gyro=gyro';
%     gyro=(B*gyro)'/3600;
    for i=1:3
        t=1:length(gyro(:,i));t=t';
        gyro1(:,i)=gyro(:,i);%wden(gyro(:,i),'minimaxi','s','one',6,'db3');
        p1=polyfit(t,Tem(:,i),3);
        Tem1(:,i)=wden(Tem(:,i),'minimaxi','s','one',3,'db3');
        dTem(:,i)=3*p1(1)*t.^2+2*p1(2)*t+p1(3);
    end
    if file_i==1
        in_all=[gyro1 Tem1 dTem ones(length(gyro1(:,1)),1) ETem];
        m=length(gyro1(:,i));
        record=[0;m];
    else
        in_all=[in_all;gyro1 Tem1 dTem ones(length(gyro1(:,1)),1) ETem];
        m=m+length(gyro1(:,i));
        record=[record;m];
    end
    clear gyro;clear Tem;clear gyro1;clear Tem1;clear dgyro;clear dTem;clear gyro2;
end

% minx1=min((min(in_all(:,4:6)))');
% maxx1=max((max(in_all(:,4:6)))');
% in_all(:,4:6)=(in_all(:,4:6)-minx1)/(maxx1-minx1)-0.5;
% minx2=min((min(in_all(:,7:9)))');
% maxx2=max((max(in_all(:,7:9)))');
% in_all(:,7:9)=(in_all(:,7:9)-minx2)/(maxx2-minx2)-0.5;
% minx3=min((min(in_all(:,11)))');
% maxx3=max((max(in_all(:,11)))');
% in_all(:,11)=(in_all(:,11)-minx3)/(maxx3-minx3)-0.5;
for i=1:3
    A(:,i)=regress(in_all(:,i),in_all(:,4:11));
end
out_all=in_all(:,4:11)*A;
t=1:length(out_all(:,1));
figure(4);
subplot(3,2,1);plot(t,in_all(:,1),'g',t,out_all(:,1),'r');title('r-估计值,g-期望值');ylabel('陀螺1');
subplot(3,2,2);plot(t,in_all(:,1)-out_all(:,1),'m');title('估计误差');ylabel('陀螺1');    
subplot(3,2,3);plot(t,in_all(:,2),'g',t,out_all(:,2),'r');title('r-估计值,g-期望值');ylabel('陀螺2');
subplot(3,2,4);plot(t,in_all(:,2)-out_all(:,2),'m');title('估计误差');ylabel('陀螺2');   
subplot(3,2,5);plot(t,in_all(:,3),'g',t,out_all(:,3),'r');title('r-估计值,g-期望值');ylabel('陀螺3');
subplot(3,2,6);plot(t,in_all(:,3)-out_all(:,3),'m');title('估计误差');ylabel('陀螺3');
error(1,1:3)=std(in_all(:,1:3));
error(2,1:3)=std(out_all(:,1:3));
clear in_all;clear out_all;
Tdata_files=dir('test/*.dat');
for file_i= 1:length(Tdata_files)
    ff=Tdata_files(file_i).name;
    data = load(fullfile('test/',ff));
    [l,n]=size(data);
    gyro=data(10:l,5:7);
    Tem=data(10:l,8:10);
    ETem=data(10:l,11);
    for i=1:3
        t=1:length(gyro(:,i));t=t';
        gyro1(:,i)=gyro(:,i);%wden(gyro(:,i),'minimaxi','s','one',6,'db3');
        p1=polyfit(t,Tem(:,i),3);
        Tem1(:,i)=wden(Tem(:,i),'minimaxi','s','one',3,'db3');;
        dTem(:,i)=3*p1(1)*t.^2+2*p1(2)*t+p1(3);
    end
    if file_i==1
        in_all=[gyro1 Tem1 dTem ones(length(gyro1(:,1)),1) ETem];
        m=length(gyro1(:,i));
        record=[0;m];
    else
        in_all=[in_all;gyro1 Tem1 dTem ones(length(gyro1(:,1)),1) ETem];
        m=m+length(gyro1(:,i));
        record=[record;m];
    end
    clear gyro;clear Tem;clear gyro1;clear Tem1;clear dgyro;clear dTem;clear gyro2;
end

% in_all(:,4:6)=(in_all(:,4:6)-minx1)/(maxx1-minx1)-0.5;
% in_all(:,7:9)=(in_all(:,7:9)-minx2)/(maxx2-minx2)-0.5;
% in_all(:,11)=(in_all(:,11)-minx3)/(maxx3-minx3)-0.5;
out_all=in_all(:,4:11)*A;
t=1:length(out_all(:,1));
figure(5);
subplot(3,2,1);plot(t,in_all(:,1),'g',t,out_all(:,1),'r');title('r-估计值,g-期望值');ylabel('陀螺1');
subplot(3,2,2);plot(t,in_all(:,1)-out_all(:,1),'m');title('估计误差');ylabel('陀螺1');    
subplot(3,2,3);plot(t,in_all(:,2),'g',t,out_all(:,2),'r');title('r-估计值,g-期望值');ylabel('陀螺2');
subplot(3,2,4);plot(t,in_all(:,2)-out_all(:,2),'m');title('估计误差');ylabel('陀螺2');   
subplot(3,2,5);plot(t,in_all(:,3),'g',t,out_all(:,3),'r');title('r-估计值,g-期望值');ylabel('陀螺3');
subplot(3,2,6);plot(t,in_all(:,3)-out_all(:,3),'m');title('估计误差');ylabel('陀螺3');
error(3,1:3)=std(in_all(:,1:3));
error(4,1:3)=std(out_all(:,1:3));
error=error

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -