How to fit a common linear trend observed across multiple sensors?
6 ビュー (過去 30 日間)
古いコメントを表示
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');
0 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!