How to fit a common linear trend observed across multiple sensors?

6 ビュー (過去 30 日間)
KAE
KAE 2020 年 4 月 15 日
コメント済み: KAE 2020 年 4 月 15 日
Let's say I have 10 noisy sensors measuring temperature vs time, and I want to fit a linear trend which is common across all 10 sensors. How do I do this? (I believe I shouldn't average the sensors' values at each time step and then fit a trend to the resulting average, since that doesn't seem to be the same thing, but let me know if it is). Here is an example of the data I want to fit,
%% Make some fake noisy measurements
timeStep = 1:100; % Time step
for iSensor = 1:10 % Loop through sensors
% Dimensions of Temperature: nSensors x nTime
Temperature(iSensor,:) = (5 + rand(1,1))*timeStep + ...% Add noise to the true slope of 5
(rand(1, length(timeStep))-0.5)*100 + 7; % Add noise to the true offset of 7
end
figure;
plot(timeStep, Temperature);
xlabel('Time'); ylabel('Temperature'); title('Noisy Temperature');
All the usual linear regression functions (polyfit, fitlm, regress) seem to assume that Temperature is a vector with dimensions nTime x 1, rather than a matrix of nSensors x nTime.

採用された回答

Rik
Rik 2020 年 4 月 15 日
You can just replicate the x-values and linearize all your data:
%% Make some fake noisy measurements
timeStep = 1:100; % Time step
nSensors=10;
Temperature=zeros(nSensors,numel(timeStep));
for iSensor = 1:nSensors % Loop through sensors
% Dimensions of Temperature: nSensors x nTime
Temperature(iSensor,:) = (5 + rand(1,1))*timeStep + ...% Add noise to the true slope of 5
(rand(1, length(timeStep))-0.5)*100 + 7; % Add noise to the true offset of 7
end
figure(1),clf(1)
plot(timeStep, Temperature);
xlabel('Time'); ylabel('Temperature'); title('Noisy Temperature');
timeStep2=ones(size(Temperature)).*timeStep;%lazy repmat
p=polyfit(timeStep2(:),Temperature(:),1);
hold on
plot(timeStep,polyval(p,timeStep),'--k')
hold off
  1 件のコメント
KAE
KAE 2020 年 4 月 15 日
Great idea. This should be in the documentation, I think.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResampling Techniques についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by