How to up-sample both signals and labels together?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Chunru
2024-3-15
编辑:Chunru
2024-3-15
%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 个评论
Chunru
2024-3-15
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!