MATLAB Answers

EMG RMS Time Interval Calculations

44 views (last 30 days)
Parth T.A.
Parth T.A. on 30 Jul 2020
Commented: dpb on 31 Jul 2020
I am writing code to analyze EMG data and need to specifically measure the RMS envelope of the signal. After this, I need to analyze each prominent envelope's duration/time interval and the RMS value within that envelope itself. I already obtained the general RMS envelope of the signal, but I can't isolate the envelopes that matter and calucate their RMS values. How can I accomplish this?
Below is my code:
%% load data
[filename, path, sureORcancel] = uigetfile('.mat', 'Choose the data for processing');
data = load(strcat(path,filename));
names = fieldnames(data);
EMG_valuesO = data.(names{9,1}).values; %the EMG values data
EMG_values = doFilter(EMG_valuesO);
%define the sampling rate
sampling_rate = 1000;
length_EMG_values = length(EMG_values);
time = [0:1:length_EMG_values-1] * (1/sampling_rate);
plot(time, EMG_values)
% find the peaks of EMG_signals, both postive peaks and negtive peaks
[EMG_values_pks_pos,EMG_values_locs_pos] = findpeaks(EMG_values, 'minpeakheight', 0.1);
[EMG_values_pks_neg,EMG_values_locs_neg] = findpeaks(-EMG_values, 'minpeakheight', 0.1);
%% combine them together
EMG_values_locs = [EMG_values_locs_pos; EMG_values_locs_neg];
[EMG_values_locs, index] = sort(EMG_values_locs);
EMG_values_pks = [EMG_values_pks_pos; -EMG_values_pks_neg];
EMG_values_pks = EMG_values_pks(index);
timediff = [];
% window length is 200 points(0.1s)
RMS = [];
RMS_time = [];
for i = 1:length(EMG_values_locs)-1
EMG_values_samples = EMG_values(EMG_values_locs(i):EMG_values_locs(i)+199);
%find the low peaks
if EMG_values_pks(i) > 0 %the high peak value is a postive value
[Minus_EMG_values_samples_pks,Minus_EMG_values_samples_locs] = findpeaks(-EMG_values_samples, 'SortStr','descend');
else %the high peak value is a negtive value
[Minus_EMG_values_samples_pks,Minus_EMG_values_samples_locs] = findpeaks(EMG_values_samples, 'SortStr','descend');
% figure
% findpeaks(-EMG_values_samples, 'SortStr','descend')
% extract the data between high peak and low peak
RMS_EMG_values_samples = EMG_values_samples(1:Minus_EMG_values_samples_locs(1));
RMS = [RMS, rms(RMS_EMG_values_samples)];
RMS_time = [RMS_time, EMG_values_locs(i)];
xlsx_filename = strrep(filename, '.mat', '.xlsx');
xlswrite(strcat(path,xlsx_filename),[RMS_time; RMS]');
envelope (EMG_values, 1000, 'rms');
function y = doFilter(x)
%DOFILTER Filters input x and returns output y.
% Generated by MATLAB(R) 9.8 and DSP System Toolbox 9.10.
% Generated on: 25-Jul-2020 18:24:50
persistent Hd;
if isempty(Hd)
N = 2; % Order
Fpass1 = 30; % First Passband Frequency
Fpass2 = 100; % Second Passband Frequency
Astop1 = 60; % First Stopband Attenuation (dB)
Apass = 1; % Passband Ripple (dB)
Astop2 = 60; % Second Stopband Attenuation (dB)
Fs = 1000; % Sampling Frequency
h = fdesign.bandpass('n,fp1,fp2,ast1,ap,ast2', N, Fpass1, Fpass2, ...
Astop1, Apass, Astop2, Fs);
Hd = design(h, 'ellip', ...
'SOSScaleNorm', 'Linf');
y = filter(Hd,x);

  1 Comment

dpb on 31 Jul 2020
Only way anybody could do anything to help here would be to have data to see and for you to illustrate what it is you have and are trying to isolate...

Sign in to comment.

Answers (0)




Community Treasure Hunt

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

Start Hunting!