Segregating an EMG signal based on activation
3 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I have two arrays, one of which stores EMG readings in mV from a hand and the second storing time in seconds. I have plotted these against eachother and am now trying to segregate the signal into separate cycles. I want to segragate the signal from the start of 1 activity to the beginning of the next activation (please see attached photo). Please could you give me any ideas of how I might do this.
Thanks,
0 件のコメント
採用された回答
Star Strider
2024 年 9 月 11 日
It would help to ahve the data. Lacking it, I’ll create some.
I generally approach ensemble problems such as yours like this —
imshow(imread('2024-09-11_14-28-09.png'))
L = 25;
Fs = 1000;
t = linspace(0, Fs*L, Fs*L).'/Fs;
s = zeros(2500,10);
s(1000:1500,:) = randn(501,10);
s = s(:)*1E-3;
figure
plot(t,s)
grid
xlabel('Time (s)')
ylabel('EMG (V)')
[eu,ed] = envelope(s, 100, 'rms'); % Create Signal Envelope (Can Also Use 'peak')
eut = +(eu>1E-4); % Set Threshold
% nnz(eut)
figure
hps = plot(t,s, 'DisplayName','EMG');
hold on
hpe = plot(t, [eu,ed], '-r', 'DisplayName','Envelope');
hpt = plot(t, eut*5E-3,'-c', 'DisplayName','Threshold');
hold off
grid
xlabel('Time (s)')
ylabel('EMG (V)')
ylim('padded')
legend([hps, hpe(1), hpt]), 'Location','best'
ps = islocalmax(eut, 'flatselection','first', 'MinProminence',0.5); % Start Of Threshold
% nnz(ps)
psn = find(ps);
pe = islocalmax(eut, 'flatselection','last', 'MinProminence',0.5); % End Of Threshold
% nnz(pe)
pen = find(pe);
for k = 1:numel(psn)
segment{k} = [t(psn(k)-10 : pen(k)+10) s(psn(k)-10 : pen(k)+10)]; % Isolate Segments
end
figure % Plot Individual Segments
tiledlayout(fix(numel(segment)/2),2)
for k = 1:numel(segment)
nexttile
plot(segment{k}(:,1), segment{k}(:,2))
grid
xlabel('Time (s)')
ylabel('EMG (V)')
title("Segment "+k)
end
Make appropriate changes to get the result you want.
.
2 件のコメント
その他の回答 (1 件)
Sugandhi
2024 年 9 月 11 日
To segregate EMG signals into separate cycles in MATLAB, you can follow these steps:
1. Determine a threshold value to identify when the EMG signal is active. This could be based on a percentage of the maximum signal value or a standard deviation above the mean.
2. Use the `find` function to locate indices where the signal crosses the threshold, indicating the start and end of an activity.
3. Loop through the activation points to segment the signal into cycles. You can store these segments in a cell array for easy access.
4. Plot the segmented cycles to visually verify that they are correctly identified.
Here's a simple MATLAB code snippet to get you started:
% Example EMG and time data
emgData = [your_EMG_data];
timeData = [your_time_data];
% Define threshold
threshold = getThershold(emgData);
% Find indices where signal crosses threshold
activationIndices = find(emgData > threshold);
% Initialize cycle start points
cycleStartIndices = [activationIndices(1)];
for i = 2:length(activationIndices)
if activationIndices(i) > activationIndices(i-1) + 1
cycleStartIndices = [cycleStartIndices, activationIndices(i)];
end
end
% Segment the EMG signal
cycles = {};
for i = 1:length(cycleStartIndices)-1
startIdx = cycleStartIndices(i);
endIdx = cycleStartIndices(i+1) - 1;
cycles{i} = emgData(startIdx:endIdx);
end
% Plot segmented cycles
figure;
hold on;
for i = 1:length(cycles)
plot(timeData(cycleStartIndices(i):cycleStartIndices(i+1)-1), cycles{i});
end
hold off;
title('Segmented EMG Cycles');
xlabel('Time (s)');
ylabel('EMG (mV)');
参考
カテゴリ
Help Center および File Exchange で Spectral Measurements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!