MATLAB:表读数错误

时间:2015-01-15 16:02:49

标签: matlab

我目前正在编写一个程序,用于读取和校正从阻抗计读取的值。为此目的,存储校正表并预先保存为.txt文件。在测量期间,这充当了校正的资源。它选择校正值并从原始数据中减去它。像这样:

%This is just to create a MWE for self-imploration.
low_freqs = (0.005:0.001:0.500)'; 
mid_freqs = (100:50:1000)'; 
high_freqs = (1500:500:10000)';
TestFreq = [low_freqs; mid_freqs; high_freqs];

Residual_R = ones(length(TestFreq), 1);
Residual_X = ones(length(TestFreq), 1);
configtable = table(TestFreq, Residual_R, Residual_X);

%Input arguments, usually fed into the function:
MeasFreq = 0.01;
ValueDisplayA_raw = 0.4;
ValueDisplayB_clean = 0.2;

%Here begins the actual correction loop, as it operates in the function.
if MeasFreq <= 0.500 %5 - 500 Hz 
    freq_req = LFIMPMETERFreqSelector(MeasFreq, 0.001);
    ValueDisplayA_clean = ValueDisplayA_raw - configtable{configtable.TestFreq == freq_req, 'Residual_R'};
    ValueDisplayB_clean = ValueDisplayB_raw - configtable{configtable.TestFreq == freq_req, 'Residual_X'};
elseif MeasFreq <= 100 %500 Hz - 100 kHz 
    ValueDisplayA_clean = ValueDisplayA_raw - configtable{configtable.TestFreq == 100, 'Residual_R'};
    ValueDisplayB_clean = ValueDisplayB_raw - configtable{configtable.TestFreq == 100, 'Residual_X'};
elseif MeasFreq <= 1000 %100 kHz - 1 MHz 
    freq_req = LFIMPMETERFreqSelector(MeasFreq, 50);
    ValueDisplayA_clean = ValueDisplayA_raw - configtable{configtable.TestFreq == freq_req, 'Residual_R'}*sqrt(MeasFreq)/sqrt(freq_req);
    ValueDisplayB_clean = ValueDisplayB_raw - configtable{configtable.TestFreq == freq_req, 'Residual_X'}*MeasFreq/freq_req;
elseif MeasFreq <= 10000 %1 MHz - 10 MHz 
    freq_req = LFIMPMETERFreqSelector(MeasFreq, 500);
    ValueDisplayA_clean = ValueDisplayA_raw - configtable{configtable.TestFreq == freq_req, 'Residual_R'}*sqrt(MeasFreq)/sqrt(freq_req);
    ValueDisplayB_clean = ValueDisplayB_raw - configtable{configtable.TestFreq == freq_req, 'Residual_X'}*MeasFreq/freq_req;
elseif MeasFreq > 10000 %10 MHz - 13 MHz 
    ValueDisplayA_clean = ValueDisplayA_raw - configtable{configtable.TestFreq == 10000, 'Residual_R'}*sqrt(MeasFreq)/sqrt(10000);
    ValueDisplayB_clean = ValueDisplayB_raw - configtable{configtable.TestFreq == 10000, 'Residual_X'}*MeasFreq/10000;
end

LFIMPFreqSelector功能:

function [Freq_wanted] = LFIMPMETERFreqSelector(input, scale)
input_low = input - mod(input, scale);
input_high = input + scale - mod((input+scale), scale);

 if abs(input - input_high) < abs(input - input_low);
  Freq_wanted = input_high;
 else
  Freq_wanted = input_low;
 end
end

ValueDisplayA_clean(或B)分别是更正后的值。为了确定应用哪种校正,我采用了if-loop,因为不同的频率范围需要不同的校正公式。 “LFIMPMETERFreqSelector”函数只取一个值,对其进行舍入并返回舍入到最接近的0.001(或50或500,取决于第二个输入变量)的值。

无论如何,configtable是从预定的修正文件中读取的表。阅读过程不是问题,并且整个功能在10个案例中有7个完美运行。其他3只是没有纠正任何事情。我现在有一个解决方法可以解决未修正的值,但我真的很想知道它为什么有时找不到所需的值。这是我到目前为止尝试过的快速修复列表: - 将MeasFreq保存为常量,以便更快地从表中读取数据 - 将表分成几个部分(再次,加快阅读过程) - 舍入变量freq_req和MeasFreq - 强制循环暂停,直到找到表中的值

最后导致循环崩溃,只要它在与freq_req对应的TestFreq列中找不到值。

我在我的智慧结束,但也许你们中的一个人知道可能出现什么问题。它有时可以工作,但可靠地不能用于相同的低(<10 MHz)频率。如果有人知道发生了什么,我将非常感激。

0 个答案:

没有答案