How to up-sample both signals and labels together?
6 views (last 30 days)
Show older comments
I have ECG-signals and corresponding labels with the sampling rate of 250 Hz (attached).
Attached "sig.mat" is the ECG-signal and "labl.mat" is the labels, where five signals and five labels (5x1 cell).
I want to up-sample these signals and labels coherently (synchronized in time after upsampling) with 360 Hz.
I heard I can use "resample" function for the signal, but I don't know it for the labels.
I may use labeler app, but this is too slow.
I would appreciate it if anyone could help me on how to label automatically in accordance with the up-sampled signals.
Thanks,
0 Comments
Accepted Answer
Chunru
on 15 Mar 2024
Edited: Chunru
on 15 Mar 2024
%websave("upsamp.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1642771/upsamp.mat");
websave("upsamp_R.mat", "https://www.mathworks.com/matlabcentral/answers/uploaded_files/1642906/upsamp_R.mat");
load upsamp_R
fs = 250;
fsnew = 360;
for i =1:length(sig)
% signal and label
s = sig{i};
l = labl{i};
% categories
c = categories(l);
% original and new time
t = (0:length(s)-1)/fs;
tnew = t(1):(1/fsnew):t(end);
% interpolation
snew = interp1(t, s, tnew, 'linear');
lnew = interp1(t, double(l), tnew, 'nearest');
% convert back to categorical data
lnew = categorical(lnew, 1:length(c), c);
signew{i, 1} = snew;
lablnew{i, 1} = lnew;
end
sig
signew
labl
lablnew
whos
figure
subplot(211); plot(s)
subplot(212); plot(snew)
figure;
subplot(211); plot(double(l))
subplot(212); plot(double(lnew))
5 Comments
Chunru
on 15 Mar 2024
It is due to the way we produce new time:
t = (0:length(s)-1)/fs;
tnew = t(1):(1/fsnew):t(end);
We don't extend the time after the original end of the time. You can extend it if you like by add a small time after t(end).
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!