温度补偿计算公式_温度补偿,matlab 计算
計算908的溫度擬合曲線
%%
close all;
clc;
clear;
%%
str = 'E:\matlab\kc908_temp_data\';%獲取路徑
files = dir(strcat(str,'*.txt'));%掃描當(dāng)前文件夾下的txt文件
number_files = length(files);%獲取文件數(shù)量
%%
list_freq = zeros(number_files);
for i=1:number_files
freq(i) = str2num(files(i).name(regexp(files(i).name,'\d')));%獲取字符串中的數(shù)字,并轉(zhuǎn)換為數(shù)字
end
[B,index]=sort(freq);
%%
N = 6;
a = zeros(number_files,N+1);
fun_name = blanks(number_files);%申請一個字符串?dāng)?shù)組
%%
for i=1:number_files
str1 = sprintf('%s%s',str,files(index(i)).name);
[temp,lev] = textread(str1,'%f,%f');%讀取指定文件
L = length(temp);
x = temp;
if(x(1) - x(end) > 0)
diff = lev(end);
else
diff = lev(1);
end
y = lev - diff;
% y(i,:) = lev;
a(i,:) = polyfit(x,y,N)%獲取多項式
figure;
plot(x,y);%畫圖
freq = str2num(files(index(i)).name(regexp(files(index(i)).name,'\d')));%獲取字符串中的數(shù)字,并轉(zhuǎn)換為數(shù)字
if (freq < 1e3)
str2 = sprintf('%s%.1f%s','頻率:',freq,'Hz');
elseif(freq <1e6)
str2 = sprintf('%s%.4f%s','頻率:',freq/1e3,'kHz');
elseif(freq < 1e9)
str2 = sprintf('%s%.7f%s','頻率:',freq/1e6,'MHz');
else
str2 = sprintf('%s%.10f%s','頻率:',freq/1e9,'GHz');
end
title(str2);
legend('溫度-幅度');%曲線內(nèi)容
xlabel('溫度');
ylabel('幅度');
end
%%
% zz = (1:number_files);
% xx = x(zz,:);
% yy = y(zz,:);
% figure;
% plot3(xx,yy,zz,'.b');
% grid on;
% figure;
% mesh(zz,xx,yy);
%%
%階數(shù)判斷
% for i=1:5
% y2=polyfit(x,y,i);
% Y=polyval(y2,x);%計算擬合函數(shù)在x處的值。
% if sum((Y-y).^2)<0.1
% c=i
% break;
% end
% end
% clear;
% clc;
close all;
% a = [
% -0.0000 0.0000 -0.0000 0.0002 -0.0383 -0.0294
% 0.0000 -0.0000 0.0000 -0.0000 -0.0355 0.0785
% 0.0000 -0.0000 0.0000 0.0001 -0.0389 0.0752
% 0.0000 -0.0000 0.0000 -0.0004 -0.0280 0.2828
% 0.0000 -0.0000 0.0000 -0.0005 0.0160 -0.0965
% -0.0000 0.0000 0.0000 -0.0005 -0.0152 0.1324
% -0.0000 0.0000 0.0000 -0.0030 0.0125 -0.0170];
tempr = 0:1:70;
N = 7;
bb = zeros(N,length(tempr));
for i = 1:N
c = a(i,N-6) .* tempr.^6 +a(i,N-5) .* tempr.^5 + a(i,N-4) .* tempr.^4 + a(i,N-3) .* tempr.^3 ...
+ a(i,N-2) .* tempr.^2 + a(i,N-1) .* tempr.^1 + a(i,N) .* tempr.^0;
figure;
plot(tempr,c);
end
總結(jié)
以上是生活随笔為你收集整理的温度补偿计算公式_温度补偿,matlab 计算的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 树莓派ibus输入法无法输入中韩文
- 下一篇: mac系统终端命令行设置自动关机/重启/