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!