我目前正在处理在不同条件下在二头肌卷曲运动中获得的肌电信号。在我的代码结束时,我将每个条件的标准化信号替换为时间的函数。我的问题是,在这个叠加过程中,由于参与者没有在同一时间开始锻炼而且时间从一条曲线移动到另一条曲线,所以我想“重新校准”(我不知道我不确定这是每个收缩的同时开始和结束的时间曲线(在蓝色曲线上最后收缩更多)
这就是我的代码现在的样子
%% Process EMG dynamique
clc, clear all, close all
%% Haltère 10 Kg
%% Filtrage, centrage et rectication du signal
data_EMG = load([''10kg_haltere-Philippe.txt'']); % Load file EMG
fe_EMG = 1000; % sampling frequency Acceleration Hz
timeEMG_10 = (0:1/fe_EMG:(length(data_EMG)-1)*(1/fe_EMG))'; % Time vector
for m = 1 : 2
[B,A] = butter(8/2,[15*1.247 400*1.247]/(fe_EMG/2),'bandpass'); % filter butterworth band pass 20 à 400 Hz d'ordre 4
data_EMG_filt = filtfilt(B,A,data_EMG(:,m)); % filtring pass band
data_EMG_filt_1 = data_EMG_filt - ones(length(data_EMG_filt),1)*mean(data_EMG_filt); %Centering of the EMG signal around the individual mean of each muscle
data_EMG_filt_rectified = abs(data_EMG_filt_1); % Rectification of the EMG signal = Full wave rectification
%% courbe RMS/EMG
rms_window = 1300;
for i = (rms_window/2)+1 : length(data_EMG)-(rms_window/2)
rms_data_EMG(i) = rms(data_EMG_filt_rectified([i-(rms_window/2):i+(rms_window/2)]));
end
[B,A] = butter(4/2,[5*1.247]/(fe_EMG/2),'low'); % filter butterworth band pass 20 à 400 Hz d'ordre 4
data_EMG_filt_rectified_filtbutter = filtfilt(B,A,data_EMG_filt_rectified); % filtring pass band
EMG_max = max(data_EMG_filt_rectified_filtbutter);
data_EMG_filt_rectified_filtbutter_norm_10 = (data_EMG_filt_rectified_filtbutter.*100)./EMG_max;
% Stockage
RMS(:,m) = rms_data_EMG;
EMG_filt(:,m) = data_EMG_filt_rectified;
EMG_filtbutter(:,m) = data_EMG_filt_rectified_filtbutter;
EMG_filtbutter_norm(:,m) = data_EMG_filt_rectified_filtbutter_norm_10;
end
%% Haltère 5 kg
%% Filtrage, centrage et rectication du signal
data_EMG = load(['5kg_haltere-Philippe.txt']); % Load file EMG
fe_EMG = 1000; % sampling frequency Acceleration Hz
timeEMG_5 = (0:1/fe_EMG:(length(data_EMG)-1)*(1/fe_EMG))'; % Time vector
for m = 1 : 2
[B,A] = butter(4/2,[15*1.247 400*1.247]/(fe_EMG/2),'bandpass'); % filter butterworth band pass 20 à 400 Hz d'ordre 4
data_EMG_filt = filtfilt(B,A,data_EMG(:,m)); % filtring pass band
data_EMG_filt_1 = data_EMG_filt - ones(length(data_EMG_filt),1)*mean(data_EMG_filt); %Centering of the EMG signal around the individual mean of each muscle
data_EMG_filt_rectified = abs(data_EMG_filt_1); % Rectification of the EMG signal = Full wave rectification
%% courbe RMS/EMG
rms_window = 1300;
for i = (rms_window/2)+1 : length(data_EMG)-(rms_window/2)
rms_data_EMG(i) = rms(data_EMG_filt_rectified([i-(rms_window/2):i+(rms_window/2)]));
end
% Application d'un deuxième filtre (pour analyser les bouffé EMG) à la place de lp filter
[B,A] = butter(8/2,[5*1.247]/(fe_EMG/2),'low');
data_EMG_filt_rectified_filtbutter = filtfilt(B,A,data_EMG_filt_rectified);
EMG_max = max(data_EMG_filt_rectified_filtbutter);
data_EMG_filt_rectified_filtbutter_norm_5 = (data_EMG_filt_rectified_filtbutter.*100)./EMG_max;
% Stockage
RMS(:,m) = rms_data_EMG;
EMG_filt(:,m) = data_EMG_filt_rectified;
EMG_filtbutter(:,m) = data_EMG_filt_rectified_filtbutter;
EMG_filtbutter_norm_5(:,m) = data_EMG_filt_rectified_filtbutter_norm_5;
end
figure
plot(timeEMG_10,EMG_filtbutter_norm(:,1))
hold on
plot(timeEMG_5,data_EMG_filt_rectified_filtbutter_norm_5)
hold off
答案 0 :(得分:1)
我为类似的东西编写了自己的函数。我相信可能有更好的方法来做到这一点,但它大部分时间都有效。基本思路是将一条线一次一点地移动(限制在某些+/-范围内),然后检查两条线之间的RMSE。记录最低RMSE发生的位置,以及应移动的距离。
时间对齐功能:
function [time2] = dataSync(data1, data2, time2, maxShift)
minError = inf;
shiftPoint = NaN;
for ii = -maxShift:maxShift
if ii <= 0 %Shift data 2 to the left
RMSE = sqrt(mean((data1(1:end+ii) - data2(1-ii:end)).^2));
else %Shift data 2 to the right (...or data 1 left)
RMSE = sqrt(mean((data1(1+ii:end) - data2(1:end-ii)).^2));
end
if RMSE < minError
minError = RMSE;
shiftPoint = ii;
end
end
if shiftPoint ~= 0
time2 = time2 + time2(abs(shiftPoint))*sign(shiftPoint);
end
将其放入您的代码中 请注意,我将转换限制为+/- 5000个样本。
figure
plot(timeEMG_10,EMG_filtbutter_norm(:,1))
hold on
%% Try to line up the times.
[timeSync] = dataSync(EMG_filtbutter_norm(:,1), data_EMG_filt_rectified_filtbutter_norm_5, timeEMG_5, 5000);
% plot(timeEMG_5,data_EMG_filt_rectified_filtbutter_norm_5)
% hold off
plot(timeSync,data_EMG_filt_rectified_filtbutter_norm_5,'g')
hold off
请注意,您没有相同数量的峰值,但这可能是您可以做到的最佳峰值。此外,假设2个数据阵列具有相同数量的元素,相同的原始时间向量等,这些可能并非总是如此。