Clear Filters
Clear Filters

Help creating RMS Window

4 views (last 30 days)
Isaac Garcia
Isaac Garcia on 11 May 2024
Commented: Mathieu NOE on 28 May 2024 at 17:38
Hello,
I am supposed to import data from 10 Excel files then filter, rectify and create a RMS window for the data, but I am stuck at the last step. I am not very good at MATLAB, but I believe that I am on the right track so far. Any help would be extremely appreciated. I included what I have so far; the commented section at the end is what I am supposed to work off of. I tried a similar loop like the ones prior but did not succeed. Thank you in advance!
clear all; clc
fileName ={'Gait_normal01.csv';'Gait_normal02.csv';'Gait_rightlimp01.csv';'Gait_rightlimp02.csv';'MVC_Extension01.csv';...
'MVC_Extension02.csv';'MVC_Flexion01.csv';'MVC_Flexion02.csv';'SitStand01.csv';'Squat01.csv'}
% read in Data
for i=1:10
EMGraw_data{i,1} =dlmread(fileName{i,1},',',5,2);
end
%filter
for i=1:10
i
for j=1:4
j
[B,A]=butter(2,[10/500 350/500],'bandpass');
EMGf{i,1}(:,j) = filtfilt(B,A,EMGraw_data{i,1}(:,j));
end
end
% rectify
for i=1:10
i
for j=1:4
j
EMGrec{i,1}(:,j) = abs(EMGf{i,1}(:,j));
end
end
% %Root mean square
% winlength = 299; %input 1-desired window length
% EMGrms=zeros(length(EMGrec)-winlength,1);
% for i=1:length(EMGrec)-winlength;
% win=EMGrec(i:i+winlength);
% EMGrms(i+(winlength+1)/2)=sqrt(sum(win.^2)/winlength);
% end

Answers (1)

Mathieu NOE
Mathieu NOE on 13 May 2024
hello
here some demo code FYI
% dummy data
n = 1000;
Fs = 100;
dt = 1/Fs;
t=(0:n-1)*dt;
y = max(0.707,abs(cos(t))+0.1*rand(size(t)));
buffer = Fs; % 1 second buffer (size in samples)
overlap = round(0.5*Fs); % overlap (here 50 % of buffer size) (size in samples)
[t_rms,y_rms] = my_rms(t,y,buffer,overlap);
figure(1),
plot(t,y,t_rms,y_rms,'r-*');
legend('raw data','1 s rms');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [t_rms,x_rms] = my_rms(t,x,buffer,overlap)
%%%% main loop %%%%
m = length(x);
dt = mean(diff(t));
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
t_rms(ci) = dt*(start_index+stop_index)/2; % time (centered in buffer)
x_rms(ci) = sqrt(mean(x(start_index:stop_index).^2));
end
end
  2 Comments
Mathieu NOE
Mathieu NOE on 16 May 2024
problem solved ?
Mathieu NOE
Mathieu NOE on 28 May 2024 at 17:38
hello again
problem solved ?

Sign in to comment.

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!