Correcting effects of Humidity on sensors

66 ビュー (過去 30 日間)
Dharmesh
Dharmesh 2025 年 10 月 23 日
コメント済み: Star Strider 2025 年 11 月 17 日 21:09
Hi All
I have gas sensor, that gets effected by hummdity that needs to be corrected. So was hoping to see if we can correct this ?
How can i run my code on the this support forum with my data file, so it can be run?

回答 (1 件)

Star Strider
Star Strider 2025 年 10 月 23 日
What sort of correction do you want to do to your data?
Do you also have the humidity data?
Are there any published ways to correct the readings for humidity? If so, please share them.
To run your code with your data here, first upload the data file, using the 'paperclip' icon in the top toolbar (just to the right of the Σ). Click on the 'insert a line of doce' icon in the top toolbar (farthest left icon in the CODE section, or ALT+ENTER) to create a code line, then type or copy-paste your code in it. To run it, press the green arrrow in the top toolbar.
x = linspace(0, 2*pi);
y = sin(x) .* cos(x);
figure
plot(x, y)
grid
Your code should run here essentially the same way it runs on your computer, including reading the file.
,
  22 件のコメント
Dharmesh
Dharmesh 2025 年 11 月 11 日 9:31
Hi,
Thank you for your help.
Regarding your understanding — yes, each sensor outputs a voltage that is affected by both temperature and humidity. There are transients caused independently by each of these factors, but I don’t necessarily know if the stabilisation time is 10 minutes, less, or more, as this depends on the characteristics of the sensor.
At the moment, in relation to gas concentration, we are testing in zero gas, which means we are simply establishing a corrected baseline. The baseline signifies the voltage at each temperature step when the gas concentration is zero. When we subtract this baseline from the actual signal (with gas present) and divide by the manufacturer’s sensitivity factor, we obtain the actual gas concentration. So at this stage, we are focusing only on the baseline to better understand how humidity and temperature affect the voltage output.
The period between 14:00 and 14:24 is the most stable, and I believe the decay you are observing indicates that the sensor is stabilising gradually compared to other periods, as the humidity is not fluctuating much.
Regarding inputs and outputs — the inputs would be temperature and humidity, and the output would be the WE signal. However, for the model, we would need to teach it what we expect so it can learn the compensation relationship.
In the case of NO₂, for example, the inputs might be temperature, humidity, and WE, and the output could be a signal around 233 mV — not exactly flat but with minor variations. I might be mistaken, but perhaps expressing this as a percentage could help, so that when there are peaks caused by gas concentration, they are not interpreted as transients.
I believe you are from MATLAB Support? Do you have the option for an online call?
Star Strider
Star Strider 2025 年 11 月 17 日 21:09
My pleasure!
At this point, I actually have something useful. You will need to have access to the System Identification Toolbox for this. I cannot simulate it any other way, even after having extracted the parameters (transfer function coefficients in this instance). The reason of course for using this approach is the dynamic nature of the signals and the system itself. I did all of it in MATLAB Online.
This is your code, with my addition being everything in the 'System Identification & Parameter Estimation' section. I initially began with a state=space identification, since that is usually preferable in my experience. It was not here. So I switched to transfer function identification, and got a decent result. The input to it is '[Temperature Humidity WE]' and the output was simply 'WE'. I then identified it with the appropriate parameter estimation to get the identified system. To get the Temperature-Humidity offset signal, I used the same identified system, however setting the 'WE' signal to a vector of zeros. I then subtracted that from the 'WE' signal in every situation to get the corrected 'WE' signal. Those results are plotted here.
I believe that I returned the correct signalss from 'makeFig' however I cannot guarantee that. I added outputs to itto get the results you originally plotted, then resampled them to a reasonable time interval, and then used that for the system identification dat. With rare exceptions, all such signal processing, system identification, and parameter estimation routines require regularly sampled signals. The relevant functions assume that the signaols are consistently samples, and will produce erroneous results if the signals are not consistently sampled. That is the reason for the table2timetable calls and the resulting restime calls.
The 'NumMtx' and 'DenMtx' are the numerator and denominator transfer function coefficients, in the event you want to experiment with them, perhaps using the transfer functions as filters for the 'WE' signal for each variable (Temperature and Humidity). I experimented with this, however I could not get that approach to work, the reason that I implement all of this in the System Identificatioon Toolbox. Tthe Control System Toolbox could also work.)
The 'NO' result is the best, so my approach works, at least for it. For the others, the result is less convincing, leading me to believe that in those, the Temperature and Humidity may be of lesser importance.
It is not easy for me to understand your code, however I did my best to understand it and provide a reasonable result.
Try this --
clear all
close all
matFile = websave('HumditydataS2.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1842936/HumditydataS2.mat');
% Source Habs: https://www.reddit.com/r/embedded/comments/f4iino/whats_the_right_way_to_convert_relative_humidity/
Habs = @(RH,T) 216.7*(RH/100 .* 6.112 .* exp((17.62.*T)./(243.12+T)))./(273.15+T); %Units: g/m^3
% HumAbs = Habs(T.('Humidity (%)'), T.('Temperature (°C)'));
% files = dir('*.mat');
% folder = files.folder;
%
% %matFile = fullfile(folder, 'SensorLog_ALLS2.mat');
% matFile = fullfile(folder, 'HumditydataS2.mat');
temperature_test = false; % set to true for the original dataset
% --- Load the combined table ---
S = load(matFile);
fn = fieldnames(S);
T = S.(fn{find(structfun(@istable, S), 1)});
VN = T.Properties.VariableNames;
% --- Time & environment ---
if ~isdatetime(T.Timestamp)
T.Timestamp = datetime(T.Timestamp,'InputFormat','yyyy-MM-dd HH:mm:ss');
end
time = T.Timestamp;
TempC = T.("Temperature (°C)");
Hum = T.("Humidity (%)");
HumAbs = Habs(T.('Humidity (%)'), T.('Temperature (°C)')); % Calculate Approximate Absolute Humidity
% ================== CALIBRATION CONSTANTS ==================
% ---------- ELECTRONICS OFFSETS (hardware bias; set if measured) ----------
ELEC.NO_WE = 0.292; ELEC.NO_AUX = 0.259;
ELEC.OX_WE = 0.229; ELEC.OX_AUX = 0.227; % OX uses O3 columns
ELEC.NO2_WE = 0.238; ELEC.NO2_AUX = 0.225;
% ---------- SENSOR ZERO BASELINES (clean air, include electronics if measured that way) ----------
ZERO.NO_WE = 0.3158; ZERO.NO_AUX = 0.3017; % NO-B4
ZERO.OX_WE = 0.2366; ZERO.OX_AUX = 0.2278; % OX-A431 (O3)
ZERO.NO2_WE = 0.2396; ZERO.NO2_AUX = 0.2253; % NO2-B43F
% ===========================================================
% --- Ensure expected columns exist (adjust here if names differ) ---
need = ["NO WE","NO AUX","O3 WE","O3 AUX","NO2 WE","NO2 AUX"];
have = string(T.Properties.VariableNames);
if ~all(ismember(need, have))
error('Missing columns. Expected: %s\nHave: %s', strjoin(need,', '), strjoin(have,', '));
end
% --- Initialise structs to avoid dot-indexing errors ---
WE = struct(); AE = struct(); WEo = struct(); AEo = struct();
% --- Convert zeros to sensor-only baselines (remove electronics bias) ---
WEo.NO = ZERO.NO_WE - ELEC.NO_WE; AEo.NO = ZERO.NO_AUX - ELEC.NO_AUX;
WEo.OX = ZERO.OX_WE - ELEC.OX_WE; AEo.OX = ZERO.OX_AUX - ELEC.OX_AUX;
WEo.NO2 = ZERO.NO2_WE - ELEC.NO2_WE; AEo.NO2 = ZERO.NO2_AUX - ELEC.NO2_AUX;
% --- Raw -> electronics-corrected live readings ---
WE.NO = T.("NO WE") - ELEC.NO_WE; AE.NO = T.("NO AUX") - ELEC.NO_AUX;
WE.OX = T.("O3 WE") - ELEC.OX_WE; AE.OX = T.("O3 AUX") - ELEC.OX_AUX;
WE.NO2 = T.("NO2 WE") - ELEC.NO2_WE; AE.NO2 = T.("NO2 AUX") - ELEC.NO2_AUX;
% ---------------- Temperature compensation tables ----------------
T_pts = [-30 -20 -10 0 10 20 30 40 50];
% NO (kT, ratio model)
kT_NO = interp1(T_pts, [1.8 1.8 1.4 1.1 1.1 1.0 0.9 0.9 0.8], TempC, 'linear','extrap');
% NO2 & OX (nT, simple model) – replace OX row with your own if you have it
nT_NO2 = interp1(T_pts, [1.3 1.3 1.3 1.3 1.0 0.6 0.4 0.2 -1.5], TempC, 'linear','extrap');
nT_OX = interp1(T_pts, [1.3 1.3 1.3 1.3 1.0 0.6 0.4 0.2 -1.5], TempC, 'linear','extrap');
% ---------------- Apply algorithms ----------------
% NO (Algorithm 2 / ratio): WEc = (WEu - WEe) - kT*(WEo/AEo)*(AEu - AEe)
WEc_NO = (WE.NO) - kT_NO .* (ZERO.NO_WE ./ZERO.NO_AUX ) .* (AE.NO );
NO_NET = T.("NO WE") -T.("NO AUX") ;
% NO2 (Algorithm 1 / nT): WEc = (WEu - WEe) - nT*(AEu - AEe)
%WEc_NO2 = (WE.NO2 - WEo.NO2) - nT_NO2 .* (AE.NO2 - AEo.NO2);
WEc_NO2 = (WE.NO2) - nT_NO2 .* (AE.NO2);
NO2_NET = T.("NO2 WE") - T.("NO2 AUX");
% OX (Algorithm 1 / nT): WEc = (WEu - WEe) - nT*(AEu - AEe)
WEc_OX = (WE.OX ) - nT_OX .* (AE.OX );
OX_NET = T.("O3 WE") - T.("O3 AUX");
% ---------------- Plot sets ----------------
[tq{1},tc_fq{1},NET_fq{1},WE_fq{1},Humq{1},nameq{1}] = makeFig("NO (k_T ratio)", time, TempC, Hum, T.("NO WE") , T.("NO AUX"), WEc_NO,NO_NET,temperature_test);
[tq{2},tc_fq{2},NET_fq{2},WE_fq{2},Humq{2},nameq{2}] = makeFig("NO2 (n_T simple)",time, TempC, Hum, T.("NO2 WE") , T.("NO2 AUX"), WEc_NO2,NO2_NET,temperature_test);
[tq{3},tc_fq{3},NET_fq{3},WE_fq{3},Humq{3},nameq{3}] = makeFig("OX/O3 (n_T simple)",time,TempC, Hum, T.("O3 WE") , T.("O3 AUX"), WEc_OX,OX_NET,temperature_test);
% ========== System Identification & Parameter Estimation ==========
fprintf('\nStart time: %s\n\n',datetime('now'))
Start time: 17-Nov-2025 20:49:55
tic
SysOrdSS = [6; 6; 6];
SysOrdTF = [12; 14; 10];
for k = 1:numel(tq)
fprintf('\n====================\nk = %d\nName: %s --\n\n',k,nameq{k})
Tss = mean(diff(tq{k}));
Tss.Format = "hh:mm:ss.SSS"
Tsv(k) = floor(seconds(Tss));
Fs = 1/Tsv(k)
Tss = seconds(Tsv(k))
DataTable{k} = table(tq{k},tc_fq{k},NET_fq{k},WE_fq{k},Humq{k}, VariableNames=["Timestamp","Temperature (°C)","NET","WE","Humidity (%)"]);
HumAbs = Habs(Humq{k},tc_fq{k});
Tr1 = DataTable{k};
Tr1 = addvars(Tr1, HumAbs, NewVariableNames='Absolute Humidity');
% TTr1 = table2timetable(Tr1(:,1:end-1));
TTr1 = table2timetable(Tr1);
fprintf('\nResampled Data --\n')
TTr2 = retime(TTr1, 'regular', 'linear', TimeStep=Tss)
y = TTr2.WE;
% u = [TTr2.("Temperature (°C)") TTr2.("Absolute Humidity")];
u = [TTr2.("Temperature (°C)"), TTr2.("Humidity (%)"), TTr2.WE];
SIData = iddata(y,u,Tsv(k));
% Sys{k} = ssest(SIData,SysOrdSS(k),Ts=Tsv(k));
Sys{k} = tfest(SIData,SysOrdTF(k), Ts=Tsv(k));
% fprintf('\n====================\nk = %d\nName: %s --\n\n',k,nameq{k})
IDSystem = Sys{k}
Parameters = IDSystem.Report.Parameters.ParVector;
NPar = numel(Parameters)
% PQ = [(1:NPar).' Parameters]
% Szu = size(u)
NPmtx = reshape(Parameters, [], size(u,2));
% SzNP = size(NPmtx)
% NPmtx2 = [(1:size(NPmtx,1)).' NPmtx]
NumMtx = NPmtx(2:SysOrdTF(k),:)
DenMtx = NPmtx(SysOrdTF(k)+1:size(NPmtx,1)-1,:)
figure
compare(SIData, Sys{k})
hc = get(gca);
xv = hc.Children(1).Children.XData;
% for k2 = 1:2
% ofstvct = [-1 ones(1, size(DenMtx,1)-1)];
% partsys = tf(NumMtx(:,k2).', [1 (ofstvct .* DenMtx(:,k2).')], Ts=Tsv(k))
% out(:,k2) = lsim(partsys, u(:,k2).', xv(:).');
% end
% QQ = out
u2 = u;
u2(:,3) = zeros(size(u,1),1);
out = lsim(Sys{k}, u2, xv);
figure
plot(xv, out, LineWidth=2)
grid
ylim([-1 1]*0.05)
xlabel('Time')
ylabel('Temperature (°C) + Humidity (%) Offset Signal')
title(nameq{k})
figure
plot(xv, TTr2.WE-out)
grid
xlabel('Time')
ylabel('WE Signal - (Temperature (°C) + Humidity (%) Offset Signal)')
title(nameq{k})
% return
end
==================== k = 1 Name: NO (k_T ratio) --
Tss = duration
00:00:05.685
Fs = 0.2000
Tss = duration
5 sec
Resampled Data --
TTr2 = 3223×5 timetable
Timestamp Temperature (°C) NET WE Humidity (%) Absolute Humidity ___________________ ________________ _______ ______ ____________ _________________ 2025-11-07 11:24:20 20.214 -0.0094 0.2882 74.248 12.963 2025-11-07 11:24:25 20.104 -0.0084 0.2852 74.128 12.86 2025-11-07 11:24:30 19.994 -0.0086 0.281 74.026 12.76 2025-11-07 11:24:35 19.896 -0.0078 0.2766 73.972 12.678 2025-11-07 11:24:40 19.8 -0.0076 0.272 73.942 12.601 2025-11-07 11:24:45 19.652 -0.0086 0.2682 73.954 12.495 2025-11-07 11:24:50 19.54 -0.009 0.266 74 12.421 2025-11-07 11:24:55 19.472 -0.009 0.2646 74.054 12.38 2025-11-07 11:25:00 19.402 -0.0098 0.2632 74.126 12.341 2025-11-07 11:25:05 19.336 -0.0114 0.2608 74.212 12.308 2025-11-07 11:25:10 19.276 -0.012 0.259 74.296 12.278 2025-11-07 11:25:15 19.22 -0.0144 0.257 74.382 12.252 2025-11-07 11:25:20 19.174 -0.0176 0.2532 74.466 12.233 2025-11-07 11:25:25 19.134 -0.0166 0.252 74.556 12.219 2025-11-07 11:25:30 19.094 -0.016 0.2516 74.65 12.205 2025-11-07 11:25:35 19.058 -0.0164 0.251 74.75 12.196
IDSystem = From input "u1" to output "y1": 0.0108 z^-1 - 0.01825 z^-2 + 0.006978 z^-3 + 0.01401 z^-4 - 0.01089 z^-5 - 0.002783 z^-6 - 0.009682 z^-7 + 0.01425 z^-8 + 0.0008552 z^-9 - 0.02089 z^-10 + 0.0156 z^-11 ------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 + 0.082 z^-1 - 0.3421 z^-2 + 0.3774 z^-3 + 0.1827 z^-4 + 0.09624 z^-5 - 0.7252 z^-6 - 0.253 z^-7 + 0.4788 z^-8 - 0.4241 z^-9 - 0.1422 z^-10 - 0.1586 z^-11 - 0.1139 z^-12 From input "u2" to output "y1": -9.514e-05 z^-1 + 0.0002647 z^-2 - 0.0001822 z^-3 - 0.0001455 z^-4 + 0.0002082 z^-5 - 5.979e-06 z^-6 - 3.486e-05 z^-7 + 7.935e-05 z^-8 - 0.0001754 z^-9 + 7.717e-05 z^-10 + 9.644e-06 z^-11 ------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 - 0.6568 z^-1 - 0.577 z^-2 + 0.3794 z^-3 - 0.4464 z^-4 - 0.2022 z^-5 - 0.0663 z^-6 + 0.1396 z^-7 + 0.5433 z^-8 - 0.3393 z^-9 + 0.4507 z^-10 + 0.6686 z^-11 - 0.8935 z^-12 From input "u3" to output "y1": 1.119 z^-1 - 0.5246 z^-2 + 0.5787 z^-3 - 0.307 z^-4 + 0.7303 z^-5 - 0.4016 z^-6 + 0.6047 z^-7 - 0.4135 z^-8 + 0.8077 z^-9 - 0.5584 z^-10 + 0.04216 z^-11 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 1 - 0.2666 z^-1 + 0.3026 z^-2 - 0.09455 z^-3 + 0.5163 z^-4 - 0.1507 z^-5 + 0.3424 z^-6 - 0.1697 z^-7 + 0.5862 z^-8 - 0.2027 z^-9 - 0.05469 z^-10 + 0.08059 z^-11 - 0.1727 z^-12 Sample time: 5 seconds Discrete-time identified transfer function. Parameterization: Number of poles: [12 12 12] Number of zeros: [11 11 11] Number of free coefficients: 69 Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using TFEST on time domain data "SIData". Fit to estimation data: 91.21% FPE: 4.954e-07, MSE: 4.641e-07
NPar = 75
NumMtx = 11×3
0.0108 -0.0001 1.1192 -0.0183 0.0003 -0.5246 0.0070 -0.0002 0.5787 0.0140 -0.0001 -0.3070 -0.0109 0.0002 0.7303 -0.0028 -0.0000 -0.4016 -0.0097 -0.0000 0.6047 0.0143 0.0001 -0.4135 0.0009 -0.0002 0.8077 -0.0209 0.0001 -0.5584 0.0156 0.0000 0.0422
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
DenMtx = 12×3
0.0820 -0.6568 -0.2666 -0.3421 -0.5770 0.3026 0.3774 0.3794 -0.0946 0.1827 -0.4464 0.5163 0.0962 -0.2022 -0.1507 -0.7252 -0.0663 0.3424 -0.2530 0.1396 -0.1697 0.4788 0.5433 0.5862 -0.4241 -0.3393 -0.2027 -0.1422 0.4507 -0.0547 -0.1586 0.6686 0.0806 -0.1139 -0.8935 -0.1727
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
==================== k = 2 Name: NO2 (n_T simple) --
Tss = duration
00:00:05.685
Fs = 0.2000
Tss = duration
5 sec
Resampled Data --
TTr2 = 3223×5 timetable
Timestamp Temperature (°C) NET WE Humidity (%) Absolute Humidity ___________________ ________________ _______ ______ ____________ _________________ 2025-11-07 11:24:20 20.214 -0.0254 0.2086 74.248 12.963 2025-11-07 11:24:25 20.104 -0.0244 0.2096 74.128 12.86 2025-11-07 11:24:30 19.994 -0.0252 0.21 74.026 12.76 2025-11-07 11:24:35 19.896 -0.0254 0.2106 73.972 12.678 2025-11-07 11:24:40 19.8 -0.0244 0.2122 73.942 12.601 2025-11-07 11:24:45 19.652 -0.0228 0.2148 73.954 12.495 2025-11-07 11:24:50 19.54 -0.021 0.217 74 12.421 2025-11-07 11:24:55 19.472 -0.02 0.218 74.054 12.38 2025-11-07 11:25:00 19.402 -0.02 0.2184 74.126 12.341 2025-11-07 11:25:05 19.336 -0.0196 0.2198 74.212 12.308 2025-11-07 11:25:10 19.276 -0.0186 0.2214 74.296 12.278 2025-11-07 11:25:15 19.22 -0.0172 0.2228 74.382 12.252 2025-11-07 11:25:20 19.174 -0.0164 0.2244 74.466 12.233 2025-11-07 11:25:25 19.134 -0.0166 0.2254 74.556 12.219 2025-11-07 11:25:30 19.094 -0.0152 0.2264 74.65 12.205 2025-11-07 11:25:35 19.058 -0.0136 0.2278 74.75 12.196
IDSystem = From input "u1" to output "y1": -0.0005966 z^-1 + 0.002684 z^-2 - 0.002937 z^-3 + 0.001092 z^-4 - 0.001974 z^-5 + 0.002478 z^-6 - 0.0009937 z^-7 + 0.001086 z^-8 - 0.002645 z^-9 + 0.002546 z^-10 - 0.0008166 z^-11 + 0.0007472 z^-12 - 0.0006697 z^-13 ------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 - 1.444 z^-1 + 0.05416 z^-2 + 0.7511 z^-3 - 0.1106 z^-4 - 0.5981 z^-5 + 0.4543 z^-6 - 0.6751 z^-7 + 1.145 z^-8 - 0.2812 z^-9 - 0.8826 z^-10 + 0.7122 z^-11 + 0.2981 z^-12 - 0.6721 z^-13 + 0.2593 z^-14 From input "u2" to output "y1": 0.001145 z^-1 - 0.001986 z^-2 + 0.0002689 z^-3 + 0.001286 z^-4 - 0.001076 z^-5 + 0.0004332 z^-6 - 0.0002389 z^-7 - 9.016e-05 z^-8 + 0.0007838 z^ -9 - 0.001072 z^-10 + 2.319e-05 z^-11 + 0.001357 z^-12 - 0.0008357 z^-13 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 1 - 0.7576 z^-1 - 0.5825 z^-2 + 0.8611 z^-3 - 0.2566 z^-4 - 0.06305 z^-5 - 0.1491 z^-6 - 0.2316 z^-7 + 0.4486 z^-8 - 0.3881 z^-9 - 0.4974 z^-10 + 0.7163 z^-11 - 0.002167 z^-12 - 0.1959 z^-13 + 0.1362 z^-14 From input "u3" to output "y1": 1.179 z^-1 + 0.0958 z^-2 - 0.003798 z^-3 - 0.1792 z^-4 + 0.4969 z^-5 + 0.1418 z^-6 - 0.03119 z^-7 + 0.4185 z^-8 - 0.264 z^-9 + 0.162 z^-10 - 0.1246 z^-11 + 0.159 z^-12 + 0.01494 z^-13 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 1 + 0.2766 z^-1 - 0.02588 z^-2 - 0.1642 z^-3 + 0.3952 z^-4 + 0.2188 z^-5 + 0.007276 z^-6 + 0.3659 z^-7 - 0.1889 z^-8 + 0.1354 z^-9 - 0.02257 z^-10 + 0.1082 z^-11 - 0.05823 z^-12 - 0.00718 z^-13 + 0.0211 z^-14 Sample time: 5 seconds Discrete-time identified transfer function. Parameterization: Number of poles: [14 14 14] Number of zeros: [13 13 13] Number of free coefficients: 81 Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using TFEST on time domain data "SIData". Fit to estimation data: 27.21% FPE: 2.117e-05, MSE: 2.013e-05
NPar = 87
NumMtx = 13×3
-0.0006 0.0011 1.1786 0.0027 -0.0020 0.0958 -0.0029 0.0003 -0.0038 0.0011 0.0013 -0.1792 -0.0020 -0.0011 0.4969 0.0025 0.0004 0.1418 -0.0010 -0.0002 -0.0312 0.0011 -0.0001 0.4185 -0.0026 0.0008 -0.2640 0.0025 -0.0011 0.1620 -0.0008 0.0000 -0.1246 0.0007 0.0014 0.1590 -0.0007 -0.0008 0.0149
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
DenMtx = 14×3
-1.4443 -0.7576 0.2766 0.0542 -0.5825 -0.0259 0.7511 0.8611 -0.1642 -0.1106 -0.2566 0.3952 -0.5981 -0.0631 0.2188 0.4543 -0.1491 0.0073 -0.6751 -0.2316 0.3659 1.1447 0.4486 -0.1889 -0.2812 -0.3881 0.1354 -0.8826 -0.4974 -0.0226 0.7122 0.7163 0.1082 0.2981 -0.0022 -0.0582 -0.6721 -0.1959 -0.0072 0.2593 0.1362 0.0211
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
==================== k = 3 Name: OX/O3 (n_T simple) --
Tss = duration
00:00:05.685
Fs = 0.2000
Tss = duration
5 sec
Resampled Data --
TTr2 = 3223×5 timetable
Timestamp Temperature (°C) NET WE Humidity (%) Absolute Humidity ___________________ ________________ _______ ______ ____________ _________________ 2025-11-07 11:24:20 20.214 -0.0244 0.207 74.248 12.963 2025-11-07 11:24:25 20.104 -0.0234 0.207 74.128 12.86 2025-11-07 11:24:30 19.994 -0.023 0.2064 74.026 12.76 2025-11-07 11:24:35 19.896 -0.0224 0.2066 73.972 12.678 2025-11-07 11:24:40 19.8 -0.022 0.207 73.942 12.601 2025-11-07 11:24:45 19.652 -0.0214 0.2076 73.954 12.495 2025-11-07 11:24:50 19.54 -0.02 0.2085 74 12.421 2025-11-07 11:24:55 19.472 -0.0186 0.2094 74.054 12.38 2025-11-07 11:25:00 19.402 -0.0176 0.2104 74.126 12.341 2025-11-07 11:25:05 19.336 -0.017 0.2114 74.212 12.308 2025-11-07 11:25:10 19.276 -0.017 0.212 74.296 12.278 2025-11-07 11:25:15 19.22 -0.0166 0.2124 74.382 12.252 2025-11-07 11:25:20 19.174 -0.0156 0.2134 74.466 12.233 2025-11-07 11:25:25 19.134 -0.015 0.214 74.556 12.219 2025-11-07 11:25:30 19.094 -0.0146 0.2144 74.65 12.205 2025-11-07 11:25:35 19.058 -0.014 0.2154 74.75 12.196
IDSystem = From input "u1" to output "y1": -0.0001083 z^-1 + 8.177e-05 z^-2 - 8.476e-05 z^-3 + 0.0001396 z^-4 - 5.401e-05 z^-5 + 4.415e-05 z^-6 - 3.235e-05 z^-7 - 1.972e-05 z^-8 + 3.465e-05 z^-9 ------------------------------------------------------------------------------------------------------------------------------------------------------- 1 - 0.7071 z^-1 - 0.3312 z^-2 - 0.001249 z^-3 - 0.04412 z^-4 + 0.4732 z^-5 - 0.04704 z^-6 + 0.3481 z^-7 - 0.7103 z^-8 - 0.3272 z^-9 + 0.5477 z^-10 From input "u2" to output "y1": 0.0007567 z^-1 - 0.001473 z^-2 + 0.001213 z^-3 - 0.00145 z^-4 + 0.001413 z^-5 - 0.0008355 z^-6 + 0.0008114 z^-7 - 0.0005198 z^-8 + 8.41e-05 z^-9 ------------------------------------------------------------------------------------------------------------------------------------------------ 1 - 0.7872 z^-1 + 0.1703 z^-2 - 0.6647 z^-3 + 0.2157 z^-4 + 0.1862 z^-5 + 0.1994 z^-6 - 0.1049 z^-7 - 0.1325 z^-8 - 0.05429 z^-9 + 0.09688 z^-10 From input "u3" to output "y1": 1.314 z^-1 - 2.064 z^-2 + 0.5294 z^-3 + 0.4738 z^-4 + 0.8795 z^-5 - 1.669 z^-6 + 1.05 z^-7 - 0.3542 z^-8 + 0.01494 z^-9 --------------------------------------------------------------------------------------------------------------------------------------------- 1 - 1.309 z^-1 - 0.03812 z^-2 + 0.5617 z^-3 + 0.725 z^-4 - 1.177 z^-5 + 0.485 z^-6 + 0.0509 z^-7 - 0.1108 z^-8 - 0.03958 z^-9 + 0.02717 z^-10 Sample time: 5 seconds Discrete-time identified transfer function. Parameterization: Number of poles: [10 10 10] Number of zeros: [9 9 9] Number of free coefficients: 57 Use "tfdata", "getpvec", "getcov" for parameters and their uncertainties. Status: Estimated using TFEST on time domain data "SIData". Fit to estimation data: 38.14% FPE: 1.936e-05, MSE: 1.869e-05
NPar = 63
NumMtx = 9×3
-0.0001 0.0008 1.3145 0.0001 -0.0015 -2.0643 -0.0001 0.0012 0.5294 0.0001 -0.0014 0.4738 -0.0001 0.0014 0.8795 0.0000 -0.0008 -1.6685 -0.0000 0.0008 1.0499 -0.0000 -0.0005 -0.3542 0.0000 0.0001 0.0149
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
DenMtx = 10×3
-0.7071 -0.7872 -1.3094 -0.3312 0.1703 -0.0381 -0.0012 -0.6647 0.5617 -0.0441 0.2157 0.7250 0.4732 0.1862 -1.1772 -0.0470 0.1994 0.4850 0.3481 -0.1049 0.0509 -0.7103 -0.1325 -0.1108 -0.3272 -0.0543 -0.0396 0.5477 0.0969 0.0272
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fprintf('\n\nFinish time: %s\n\n',datetime('now'))
Finish time: 17-Nov-2025 20:50:16
toc
Elapsed time is 21.123490 seconds.
fprintf('\n\nFinished!\n==========\n')
Finished! ==========
%% --------------- Plot helper ---------------
function [t,tc_f,NET_f,WE_f,hum,name] = makeFig(name,t,tc,hum,WE,AUX,WEc,NET,temperature_test)
% if ~exist('temperature_test','var')
% temperature_test = false; % default
% end
f = figure('Name',name,'Color','w');
tl = tiledlayout(f,2,1,'TileSpacing','compact','Padding','compact');
% Top: Temperature & Humidity
ax1 = nexttile(tl);
yyaxis left, plot(t,tc,'LineWidth',1.2), ylabel('Temperature (°C)')
yyaxis right, plot(t,hum,'LineWidth',1.2), ylabel('Humidity (%)')
grid on, title([name,' — Temp & Humidity'])
% Bottom: WE/AUX vs Corrected
ax2 = nexttile(tl);
yyaxis left
if temperature_test
plot(t,WE,'LineWidth',1.2); hold on
plot(t,AUX,'LineWidth',1.2); ylabel('Raw Sensor (V)')
else
plot(t, WE, 'b', 'LineWidth', 1.2); hold on % blue line for WE
plot(t, AUX, 'r', 'LineWidth', 1.2); % red line for AUX
ylabel('Raw Sensor (V)');
end;
if temperature_test
yyaxis right
plot(t,WEc,'LineWidth',1.5); ylabel('Corrected WE_c (V)'); hold on
%plot(t,NET,'LineWidth',1.5);
plot(t, NET, 'LineWidth', 1.5, 'Color', 'g', 'LineStyle', '-');
end
xlabel('Time'), grid on
title([name,' — WE/AUX (left), WE_c (right)'])
if temperature_test
legend({'WE','AUX','WE Corrected*(Alpha Model)','Net Corrected'},'Location','best')
else
legend({'WE','AUX'},'Location','best')
end
linkaxes([ax1 ax2],'x');
%f2 = figure('Name',[name ' — NET vs Temperature'],'Color','w');
% Use fixed window for the original temperature test; otherwise use full span
if temperature_test
% --- Fixed window for original dataset ---
t0 = datetime(2025,10,30,11,41,0);
t1 = datetime(2025,10,30,15,05,0);
else
% --- Full-range window for current data (with a small padding) ---
tt = t(~isnat(t)); % remove NaT, if any
if isempty(tt)
warning('No valid timestamps in t; skipping.');
return
end
t0 = min(tt) - minutes(1);
t1 = max(tt) + minutes(1);
end
% --- Build one mask only ---
inwin = (t >= t0) & (t <= t1);
good = isfinite(tc) & isfinite(NET) & isfinite(WE); % include WE since you use WE_f too
mask = inwin & good;
% --- Filtered vectors ---
tc_f = tc(mask);
NET_f = NET(mask);
WE_f = WE(mask);
if temperature_test
% --- Plot scatter ---
figure('Color','w');
%scatter(tc_f, NET_f, 5, 'filled'); grid on; hold on
scatter(tc_f, WE_f, 5, 'filled'); grid on; hold on
xlabel('Temperature (°C)');
ylabel('NET (V)');
title("NET vs Temperature — " + string(name));
% --- Polynomial fit (choose degree) ---
deg = 3; % << change degree here
deg = min([deg, numel(tc_f)-1, 6]); % guard: enough points & avoid wild fits
% Fit and trend line
p = polyfit(tc_f(:), WE_f(:), deg); % coefficients, highest power first
xfit = linspace(min(tc_f), max(tc_f), 400);
yfit = polyval(p, xfit);
plot(xfit, yfit, 'LineWidth', 1.6);
% R^2
yhat = polyval(p, tc_f(:));
SSres = sum((WE_f(:) - yhat).^2);
SStot = sum((WE_f(:) - mean(WE_f(:))).^2);
R2 = 1 - SSres/SStot;
% Legend: show full equation for deg <= 3, otherwise compact label
if deg == 1
eqStr = sprintf('y = %.3g x %+ .3g (R^2 = %.3f)', p(1), p(2), R2);
elseif deg == 2
a=p(1); b=p(2); c=p(3);
eqStr = sprintf('y = %.3g x^2 %+ .3g x %+ .3g (R^2 = %.3f)', a,b,c,R2);
elseif deg == 3
a=p(1); b=p(2); c=p(3); d=p(4);
eqStr = sprintf('y = %.3g x^3 %+ .3g x^2 %+ .3g x %+ .3g (R^2 = %.3f)', a,b,c,d,R2);
else
eqStr = sprintf('Poly%d fit (R^2 = %.3f)', deg, R2);
end
legend('Data', eqStr, 'Location','best');
end
end
% =========================================================================
This is the best I can do with your data to provide the result you want.
.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAI for Signals についてさらに検索

タグ

製品


リリース

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by