Can someone help me with codes or function combination to evaluate the Average force from tdms file with four channels? Pls, see codes I applied "manually" to attempt it.

2 visualizzazioni (ultimi 30 giorni)
#1 codes used to extract the tdms file
data1 = tdmsread("20221128131019RUN1force.tdms");
data1 = tdmsread("20221128131019RUN1force.tdms", ...
ChannelGroupName = "Force", ...
ChannelNames = ["Feed force" "Main force" "Passive force" "AERMS"], ...
RowTimes = "ArrTime");
#2 codes used to separate each forces from the channels eg for "Main force" - Cutting force
>> plot(data{1, 1}.(2))
>> plot(data1{1, 1}.(2))
>> main_force1 = data1{1, 1}.(2);
# codes used to compute the average Forces after picking the points Ranges for Fc1, Fc2 and Fc3 as shown the Main force plot figure at the bottom of codes;
>> sep_m1b=main_force1(950000:1592000);
>> sep_Fc1=main_force1(950000:1592000);
>> mean(sep_Fc1)
ans =
-75.6126 % the negative values shows the direction of the force due to position of dynamometer
>> sep_Fc1=main_force1(1741000:1971000);
>> sep_Fc2=main_force1(1741000:1971000);
>> mean(sep_Fc2)
ans =
-63.5206
>> sep_Fc3=main_force1(2051000:2221000);
>> mean(sep_Fc3)
ans =
-64.0661 75.6,
#Question : Can someone assist or suggest codes/functions that will COMBINE codes #1, #2 and #3, such that it Reads the 20221128131019RUN1force.tdms file, Extract any/each of the forces (Feed, Main, Passive or AERMS), Evaluate the Average values from the range and give the values 75.6N, 63.5N and 64.1N respectively skipping the ROUGH JUMPS and NON-cutting signal zones. The link to the tdms file, I have provided in the link. https://drive.google.com/file/d/1as21ZQWwY5RsKSNISNI8m761oG84i89I/view?usp=sharing
  4 Commenti
Mathieu NOE
Mathieu NOE il 11 Gen 2023
hello
no , I don't see any mat file here
you attached a m file that contains the beginning or your code (that we know already from your post above)
Ugifada
Ugifada il 11 Gen 2023
Modificato: Ugifada il 11 Gen 2023
Oh my error. However, I tried to upload the mat file but is very large (39MB) even as a zip or .rar file exceeding the max of 5MB. So I shared with the link from google drive. Can this be helpful.? https://drive.google.com/file/d/1_ooEOQGzYIj_rO88AdiqWKGeV9t77XsQ/view?usp=sharing

Accedi per commentare.

Risposta accettata

Mathieu NOE
Mathieu NOE il 11 Gen 2023
Ok so this is what I can offer you today
1/ I noticed your sampling rate could be much lower (at least factor 1000) without any loss of information !! so this could reduce your file size and further processing time by large amount
2/ the rest is quite simple : we look for the positive and negative transitions and use that time stamps to extract the "flat" sections of data , and take the mean value of them . a bit of smoothing is applied before derivation
last , I prefer peakseek over the built in findpeaks but it's everyone taste so pick either one or the other....
results :
force_mean = -75.6448 -63.6153 -64.4441
plot
code
load('ExpRUN1.mat');
ForceData = table2array(ForceData{1,1}); % ["Feed force" "Main force" "Passive force" "AERMS"], ...
mainforce = ForceData(:,2);
samples = numel(mainforce);
t = (1:samples);
%% task 1 : decimate (because we don't need that much data !!)
decim = 1000;
mainforce2 = decimate(mainforce,decim);
samples2 = numel(mainforce2);
t2 = (decim/2:decim:samples);
% figure(1),
% plot(t,mainforce,t2,mainforce2);
%% task 2 : find start / stop indexes for flat signal areas
clear ForceData mainforce samples t % we don't need the hude initial data anymore so let's clear some memory
% smooth the signal
mainforce2s = smoothdata(mainforce2,'gaussian',50);
% derivation for finding transients
d = gradient(mainforce2s);
% positive peaks
minpeakdist = 100;
minpeakh = max(d)/3;
[locspos, pkspos]=peakseek(d,minpeakdist,minpeakh);
t2pos = t2(locspos);
% negative peaks
minpeakdist = 100;
minpeakh = -min(d)/3;
[locsneg, pksneg]=peakseek(-d,minpeakdist,minpeakh);
t2neg = t2(locsneg);
pksneg = -pksneg;
figure(2),
subplot(2,1,1),plot(t2,mainforce2,t2,mainforce2s);
hold on
for k = 1:numel(pksneg)
ind_start = locsneg(k);
ind_stop = locspos(k);
length=(ind_stop-ind_start);
samples2remove = round(0.15*length); % remove this amount of samples at the beginning and end of this data buffer
ind_start = ind_start+samples2remove;
ind_stop = ind_stop-samples2remove;
%duration(k)=(ind_stop-ind_start);
time = t2(ind_start:ind_stop);
data = mainforce2s(ind_start:ind_stop);
subplot(2,1,1),plot(time,data,'*-');
time_mean(k) = mean(time);
force_mean(k) = mean(data);
end
subplot(2,1,1),plot(time_mean,force_mean,'dr','Markersize',15);
legend('signal decimated','signal decimated and smoothed','data segment 1','data segment 2','data segment 3','force mean')
subplot(2,1,2),plot(t2,d,t2pos,pkspos,'dg',t2neg,pksneg,'dk','Markersize',10);
legend('signal derivative','positive peaks','negative peaks')
hold off
force_mean
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [locs, pks]=peakseek(x,minpeakdist,minpeakh)
% x is a vector input (generally a timecourse)
% minpeakdist is the minimum desired distance between peaks (optional, defaults to 1)
% minpeakh is the minimum height of a peak (optional)
%
% (c) 2010
% Peter O'Connor
% peter<dot>ed<dot>oconnor .AT. gmail<dot>com
if size(x,2)==1, x=x'; end
% Find all maxima and ties
locs=find(x(2:end-1)>=x(1:end-2) & x(2:end-1)>=x(3:end))+1;
if nargin<2, minpeakdist=1; end % If no minpeakdist specified, default to 1.
if nargin>2 % If there's a minpeakheight
locs(x(locs)<=minpeakh)=[];
end
if minpeakdist>1
while 1
del=diff(locs)<minpeakdist;
if ~any(del), break; end
pks=x(locs);
[garb, mins]=min([pks(del) ; pks([false del])]); %#ok<ASGLU>
deln=find(del);
deln=[deln(mins==1) deln(mins==2)+1];
locs(deln)=[];
end
end
if nargout>1
pks=x(locs);
end
end
  13 Commenti
Ugifada
Ugifada il 19 Gen 2023
Dear @Mathieu NOE, please pardon me, I have been on exams at school and other end of semester tasks. However, I have about 27 RUNS of the experiment and I have tested on RUN1 to RUN4 before the tight engagments. I discovered as you said that I need to vary these particular lines duration time, and segment ....
duration_min = (10-30); % minimal duration in samples (shorter signal are not considered valid)
ind_slope = abs(d)< ms/(10-200); % check if factor 10 is enough or too high
% find segment of non zero force
ind_force = abs(force2s)> mf/(10-200); % check if factor 10 is enough or too high
% combine both conditions
For instance in RUN4 ( channel 3 was giving mean force = 116 127 NaN ) but after adjusting I got value 116, although when manually one is 204. Similarly(channel 2 gave -34.7770 -38.7909 NaN) after adjusting a got value 116 but when manually done -80N.
Therefore, I would say the last codes you provided seems to be perfect but ONE NEED TO CAREFULLY ADJUST TIME AND SEGMENTS, and I will complete the remaining RUN5-27 and give a feedback once am done with it.
Thank you so much, and I appreciate the follow up! You are a good teacher.
Mathieu NOE
Mathieu NOE il 19 Gen 2023
hello again
hope you have succeeded your exams !
I was just wondering if this new approach was better , more robust than the previous one
yes for sure, you may have to tweak some parameters according to your data
as soon as the main code structure is fine, that's a good point and i am glad I could help you on that
good luck for the future !

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by