Help creating RMS Window

조회 수: 2 (최근 30일)
Isaac Garcia
Isaac Garcia 2024년 5월 11일
편집: Mathieu NOE 2025년 1월 2일
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

답변 (1개)

Mathieu NOE
Mathieu NOE 2024년 5월 13일
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
  댓글 수: 4
Alessandro
Alessandro 2024년 12월 26일
I did and i'd like to cite you in my thesis. How do i do it?
Mathieu NOE
Mathieu NOE 2025년 1월 2일
편집: Mathieu NOE 2025년 1월 2일
hello and happy new year
it's maybe a too great honor to be cited in your thesis
I would simply prefer you to press the "accept" button (you should see a box that says "Accept this answer." )

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by