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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!