Emg Signal analysis, Mean value filter Threshold analysis

149 views (last 30 days)
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
Lisa
Lisa on 6 Nov 2022
Moved: Star Strider on 6 Nov 2022
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.
Lisa
Lisa on 6 Nov 2022
Edited: Walter Roberson on 6 Nov 2022
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

Star Strider
Star Strider on 6 Nov 2022
@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
Star Strider
Star Strider on 8 Nov 2022
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!