Bring some signals to the same start value and end value

4 次查看(过去 30 天)
Hello,
I need some help. I want to bring some Signals to the same start end value. How I can do this quickly and easy?
Here is our code to plot the signals in one plot:
clear all
close all
F = 2000;
load('Spiro_4.mat');
data4 = data;
Atemfluss4 = data(1:end,1);
Volumen4 = data(1:end,2);
F = 2000; % sampling frequency
T4= 1/F; %Periodendauer
t4= ([0:T4:25.889]); % time vector
load('Spiro_3.mat');
data3 = data;
Atemfluss3 = data(1:end,1);
Volumen3 = data(1:end,2);
F = 2000; % sampling frequency
T3= 1/F; %Periodendauer
t3= ([0:T3:28.444999]); % time vector
load('Spiro_2.mat');
data2 = data;
Atemfluss2 = data(1:end,1);
Volumen2 = data(1:end,2);
F = 2000; % sampling frequency
T2= 1/F; %Periodendauer
t2= ([0:T2:25.979999]); % time vector
load('Spiro_1.mat');
data1 = data;
Atemfluss1 = data(1:end,1);
Volumen1 = data(1:end,2);
F = 2000; % sampling frequency
T1= 1/F; %Periodendauer
t1= ([0:T1:33.414]); % time vector
figure;
plot(t1,Volumen1,t2,Volumen2,t3,Volumen3,t4,Volumen4);
ylabel('Volume in litres');
xlabel('Zeit in s');
Thank you for support.
[EDITED, Jan, Code formatted]
  7 个评论
dpb
dpb 2020-11-25
Well then, post the Answer, don't just leave it hanging...altho never did fully define the solution wanted.
Daniel Sedlaczek
Daniel Sedlaczek 2020-11-26
编辑:Daniel Sedlaczek 2020-11-26
I have solve it with a Best fit line like this:
x1=1;
x2=length(VolumenDeTrend);
y1=VolumenDeTrend(x1);
y2=VolumenDeTrend(x2);
m = (y2-y1)/(x2-x1);
b = y1-(m*x1);
x=[x1:1:x2];
z = m*x+b;
g = z';
VolumenDA = VolumenDeTrend - g;

请先登录,再进行评论。

回答(2 个)

Mathieu NOE
Mathieu NOE 2020-11-24
hello
if you want all data to start and stop at the same values , you can do that : it works even sampling rates are different
if it 's ok for you I'll be glad if you would accept my answer
% define common start and stop time values
start = 0;
stop = 1; % for example
ind1 = find(t1>=start & t1<=stop)
ind2 = find(t2>=start & t2<=stop)
ind3 = find(t3>=start & t3<=stop)
ind4 = find(t4>=start & t4<=stop)
figure;
plot(t1(ind1),Volumen1(ind1),t2(ind2),Volumen2(ind2),t3(ind3),Volumen3(ind3),t4(ind4),Volumen4(ind4));
ylabel('Volume in litres');
xlabel('Zeit in s');

dpb
dpb 2020-11-24
Presuming it is to just stretch the shorter to the same time as the longest, something like:
y1=randn(size(t1)); Y1=movmean(y1,6000);
y4=randn(size(t4)); Y4=movmean(y4,6000);
plot(t1,Y1,t4,Y4)
% sample data completed, "stretch" Y4 to length/time of Y1
Y4adj=resample(Y4,numel(t1),numel(t4));
% and show result
hold on
plot(t1,Y4adj)
legend('Y1','Y4','Y4adj')
produced
A little noisy signal but can see stretched the original red curve out to same length as the blue one. Rinse and repeat.

Community Treasure Hunt

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

Start Hunting!

Translated by