Emg Signal analysis, Mean value filter Threshold analysis

Hello all,
I need your help. I have changed my course of study and have just started programming. Now I have to hand in a code by tomorrow morning and present the charts on Tuesday. I have received a code from a fellow student, which I do not understand and need to change.
It is about analyzing the Emg measurement data. To do a threshold analysis preferably with a for loop and say at what points the muscle is active. Either over time or test a value. There was something about squaring and amount.
I want to learn it, unfortunately it was all way too fast. I don't have enough programming knowledge for it yet.
I would really appreciate your help because I am completely desperate.
I already doubt my decision and my personality.
I thank all who have read the post at least to this point....
clear all;
close all;
% Laden der Messdaten
load('Romanov (ABMT).mat');
% Definition der Variablen
F = 2000; % Abtastfrequenz in Hz
T = 1/F; % Abtastperiode in s; T = 1/2000
K = length(data(:,1)); % Länge der Datenpunkte
t = [0:K-1]*T; % Abtastzeitpunkte
f = [0:1/(K-1):1]*F; % Frequenzstützstellen
N = 3000; % Ordnung, Sampellänge
FG = 40; % Grenzfrequenz
emg1 = data(:,1); % Daten der ersten Spalte
EMG1 = fft(emg1); % Fast Fourier Transformation der EMG_1-Daten
aTP = fir1(N,FG/(F/2)); % Berechnung TP Filterkoeffizienten
emg1TP = filter(aTP,1,emg1); % Mittelwertbildung über (NMittel+1)- Werte
NMittel = 1000; % Filterordnung eines FIR-Mittelwertfilters
aMittel = ones(1,NMittel+1);
emg1envelopMittel = sqrt(filter(aMittel,1,emg1TP.^2) / (NMittel+1));
% emg1envelopMittel = filter(aMittel,1,abs(emg1TP)) / (NMittel+1);
d = designfilt('bandstopiir','FilterOrder',2, ...
'HalfPowerFrequency1',49,'HalfPowerFrequency2',51, ...
'DesignMethod','butter','SampleRate',F);
fvtool(d,'Fs',F);
filtered = filtfilt(d,emg1);
subplot(111), plot(f,abs(EMG1),'b',f,abs(filtered),'r');
xlim([0 F/2]);
xlabel('f in Hz');
ylabel('|EMG_1(f)|');
xlabel('f in Hz');
legend('Unfiltered','Filtered');
title('Spektralverlauf des EMG-Signals');
figure;
plot(t,emg1,t,filtered,t,emg1envelopMittel,'k',t,-emg1envelopMittel,'k');
xlabel('t in s');
ylabel('emg_1(t), gefiltert und Einhüllende in mV');
grpdelay(d,N,F)
delay = mean(grpdelay(d))
figure;
plot(t,emg1,t,filtered,t - delay,emg1envelopMittel,'k',t- delay,-emg1envelopMittel,'k')
xlabel('t in s');
ylabel('emg_1(t), ungefiltert und Einhüllende in mV');

3 Comments

It will be necessary for you to provide the .mat file (and a description of its contents) and a description of what the analysis is intended to accomplish.
Thanks for the answer!
The mat file contains raw data of an EMG measurement. A muscle movement of the forearm muscle during contraction of a handtranig device was measured.
The task is to smooth the data and mark the points where the muscle is active. Create a mean filter.
the data in the image is given.
clear all
load('Romanov (ABMT).mat')
emg1 = data(:,1);
F = 2000;
T = 1/F;
K = length(emg1);
>> t = [0:K-1]*T;
>> plot(t,emg);
Unrecognized function or variable 'emg'.
Did you mean:
>> plot(t,emg1);
>> close all
>> plot (t,emg1);
f=[0:F/(E-1):F];
EMG1 = fft(emg1);
figure;
plot(f,abs(EMG1));
this was also given.

Sign in to comment.

 Accepted Answer

@Lisa — I looked at the data, and I have no idea what you want to do with it. I also have no idea what the second column of ‘data’ is, or how it relates to this. It might be possible to use the envelope results to estimate the thresholds and amplitudes.
LD = load(websave('Romanov%20(ABMT)','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1183258/Romanov%20(ABMT).mat'))
LD = struct with fields:
data: [132020×2 double] units: [2×2 char] labels: [2×16 char] isi: 0.5000 isi_units: 'ms' start_sample: 0
data = LD.data;
Fs = 2000;
Fn = Fs/2;
L = size(data,1);
t = linspace(0, L-1, L).'/Fs;
[envh,envl] = envelope(data(:,1), 250, 'peak');
figure
plot(t, data(:,1), 'DisplayName','Data')
hold on
plot(t, envh, 'DisplayName','Upper Envelope')
plot(t, envl, 'DisplayName','Lower Envelope')
hold off
grid
xlabel('Time (s)')
ylabel('Amp[litude (mV)')
legend('Location','best')
.

9 Comments

Hey
I talked to my fellow student and found out a few things.
Have written the code mix in.
it should show the mean value.
My problem now is that it doesn't plot everything. Not all images are shown.
And i have to define a value there now and say from when it peaks as being active muscle and when it is not. So define a threshold and show it.
My fellow student has sent me his solution, it is relatively clear, but I must not have the same as him.
it's also okay if I only submit this file. Only with me not all plots can be opened.
it's also okay if I only submit this file. Only with me not all plots can be opened.
I have no idea what you want to do. I simply suggested an approach to finding the activation segments and some of their characteristics.
Okay thanks! :)
One more question. Do you know how to display the plots. There are several in a row but they can not be displayed. Only if I write them separately.
Before each plot call use the figure function. It looks like that is already done, however the first figure has only one subplot call, creating only one subplot that fills the figure. There appear to be three figures, some of which plot multiple vectors.
Thank you! It works now.
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!