code no longer working but was fully functional and changed nothing

15 Ansichten (letzte 30 Tage)
hi all
my code was working perfectly yesturday and today it is not working it is saying that there is an issue with the filtfilt
i have no idea why it stoped working when i have another code bascially identical to this one works complety fine and the filtfilt works so it is not a licensing issue
any help would be amazing as i have been staring at this trying to fix it all morning
this is the bit of code with the filtfilt
%usign butterworth to filta the data
%selecting the cut of frequency
%cut of frequency will be the smame for both
Force_cutfreq=7;
%setting the code for both standard and squat jump
[b,a]=butter(2,Force_cutfreq/(Freq1/2),'low');
%for the standard jump jump
Sjforce_filtered=filtfilt(b,a,SjForce);
%for the squat jump
Sqforce_filtered=filtfilt(b,a,SqForce);
below is the error that keeps on popping up
Error using filtfilt
Expected input to be finite.
Error in filtfilt>efiltfilt (line 123)
validateattributes(x,{'double','single'},{'finite','nonempty'},'filtfilt');
Error in filtfilt (line 102)
y = efiltfilt(b,a,x);
Error in group_04 (line 197)
Sjforce_filtered=filtfilt(b,a,SjForce);
below is the full code
clear;
% code to import the data collected from experiment
%data collected from both the stright jump and squat
%being imported below
%all data/variables refering to stright jump will begin with Sj-(variable)
%all data/variables referign to squat jump will begin with Sq-(variables)
%to import the force pate of the stright jump data
Sjx=readmatrix("G2 CM 04.csv");
%to remove the first 5 lines of information from the data as it is
%irrelvant goes to 6225 as that is the last info for the force plate
SjForce=-Sjx(6:6225, 5);
%Force=readmatrix("froce plate.csv",opts);
% data of the trajectories only for the stright jump
opts=detectImportOptions("Sj_trajectories04.csv","NumHeaderLines",3);
Sjtraj=readmatrix("Sj_trajectories04.csv",opts);
%importing the data for the squat jump
%force plate data
Sqx=readmatrix("G2 SQ 04.csv");
%removing first 5 lines as they are not nesscary
SqForce=-Sqx(6:4065, 5);
%importing the data of the trajectories
opts1=detectImportOptions("Sq_trajectories04.csv","NumHeaderLines",3);
Sqtraj=readmatrix("Sq_trajectories04.csv",opts1);
%the weight of particeptat
%Force
% code for the consttraints
% code need to find the amount of frames
%for the force palte in the stright jump
[f_max,~]=size(SjForce);
%Force plate for the squat jumps
[f_max1,~]=size(SqForce);
%for the trajectorie in the stright jump
[f_max2,~]=size(Sjtraj);
%for the trajectories in the squat jump
[f_max3,~]=size(Sqtraj);
% sampling frequency
% due to two frequencys being used there will
%be two frequency codes
%sampling frerquency for the force plate 1000 frequency
%it is the same for both squat jump and standard jump
Freq1=1000;
time_step=1/Freq1;
%code for the standard jump flight
Sjflight=(f_max-nnz(SjForce))*time_step;
%code for the squat jump flight
Sqflight=(f_max1-nnz(SqForce))*time_step;
% t1=(4:f_max)/Freq1;
%for the standard jump
Sjt=(1:f_max)*time_step;
t1=Sjt;
%for the squat jump
Sqt=(1:f_max1)*time_step;
y=Sqt;
%sampling data for the motion captured set at 100 frequency
%this frequency is the saem for the standard and squat jump
Freq2=100;
%for the standard jump
t2=(4:f_max)/Freq2;
%for the squat jumpo
y2=(4:f_max1)/Freq2;
%the forces markers
%trajectorie markers seperated for the standard jump
SjLFHD=Sjtraj(:,1:3);
SjRFHD=Sjtraj(:,4:6);
SjLBHD=Sjtraj(:,7:9);
SjRBHD=Sjtraj(:,10:12);
SjC7=Sjtraj(:,13:15);
SjT10=Sjtraj(:,16:18);
SjCLAV=Sjtraj(:,19:21);
SjSTRN=Sjtraj(:,22:24);
SjRBAK=Sjtraj(:,25:27);
SjLSHO=Sjtraj(:,28:30);
SjLUPA=Sjtraj(:,31:33);
SjLELB=Sjtraj(:,34:36);
SjLFRM=Sjtraj(:,37:39);
SjLWRA=Sjtraj(:,40:42);
SjLWRB=Sjtraj(:,43:45);
SjLFIN=Sjtraj(:,46:48);
SjRSHO=Sjtraj(:,49:51);
SjRUPA=Sjtraj(:,52:54);
SjRELB=Sjtraj(:,55:57);
SjRFRM=Sjtraj(:,58:60);
SjRWRA=Sjtraj(:,61:63);
SjRWRB=Sjtraj(:,64:66);
SjRFIN=Sjtraj(:,67:69);
SjLASI=Sjtraj(:,70:72);
SjRASI=Sjtraj(:,73:75);
SjLPSI=Sjtraj(:,76:78);
SjRPSI=Sjtraj(:,79:81);
SjLTHI=Sjtraj(:,82:84);
SjLKNE=Sjtraj(:,85:87);
SjLTIB=Sjtraj(:,88:90);
SjLANK=Sjtraj(:,91:93);
SjLHEE=Sjtraj(:,94:96);
SjLTOE=Sjtraj(:,97:99);
SjRTHI=Sjtraj(:,100:102);
SjRKNE=Sjtraj(:,103:105);
SjRTIB=Sjtraj(:,106:108);
SjRANK=Sjtraj(:,109:111);
SjRHEE=Sjtraj(:,112:114);
SjRTOE=Sjtraj(:,115:117);
%trajectories makrers for the squat jump
SqLFHD=Sqtraj(:,1:3);
SqRFHD=Sqtraj(:,4:6);
SqLBHD=Sqtraj(:,7:9);
SqRBHD=Sqtraj(:,10:12);
SqC7=Sqtraj(:,13:15);
SqT10=Sqtraj(:,16:18);
SqCLAV=Sqtraj(:,19:21);
SqSTRN=Sqtraj(:,22:24);
SqRBAK=Sqtraj(:,25:27);
SqLSHO=Sqtraj(:,28:30);
SqLUPA=Sqtraj(:,31:33);
SqLELB=Sqtraj(:,34:36);
SqLFRM=Sqtraj(:,37:39);
SqLWRA=Sqtraj(:,40:42);
SqLWRB=Sqtraj(:,43:45);
SqLFIN=Sqtraj(:,46:48);
SqRSHO=Sqtraj(:,49:51);
SqRUPA=Sqtraj(:,52:54);
SqRELB=Sqtraj(:,55:57);
SqRFRM=Sqtraj(:,58:60);
SqRWRA=Sqtraj(:,61:63);
SqRWRB=Sqtraj(:,64:66);
SqRFIN=Sqtraj(:,67:69);
SqLASI=Sqtraj(:,70:72);
SqRASI=Sqtraj(:,73:75);
SqLPSI=Sqtraj(:,76:78);
SqRPSI=Sqtraj(:,79:81);
SqLTHI=Sqtraj(:,82:84);
SqLKNE=Sqtraj(:,85:87);
SqLTIB=Sqtraj(:,88:90);
SqLANK=Sqtraj(:,91:93);
SqLHEE=Sqtraj(:,94:96);
SqLTOE=Sqtraj(:,97:99);
SqRTHI=Sqtraj(:,100:102);
SqRKNE=Sqtraj(:,103:105);
SqRTIB=Sqtraj(:,106:108);
SqRANK=Sqtraj(:,109:111);
SqRHEE=Sqtraj(:,112:114);
SqRTOE=Sqtraj(:,115:117);
% Davis hip model
% code to find interior ASIS Distance
% function applies to all of the rows in the matrix
%for the satnadard jump
Sjpelvic_w=SjLASI-SjRASI;
SjASIS_Dist=sqrt(sum(Sjpelvic_w.^2,2));
%for the squat jump
Sqpelvic_w=SqLASI-SqRASI;
SqASIS_Dist=sqrt(sum(Sqpelvic_w.^2,2));
% to get average trajectory
%after average is found it is divided 1000
%to convert to meters
%for the standard jump
SjASIS_Dist=mean(SjASIS_Dist)/1000;
%for the squat jump
SqASIS_Dist=mean(SqASIS_Dist)/1000;
%usign butterworth to filta the data
%selecting the cut of frequency
%cut of frequency will be the smame for both
Force_cutfreq=7;
%setting the code for both standard and squat jump
[b,a]=butter(2,Force_cutfreq/(Freq1/2),'low');
%for the standard jump jump
Sjforce_filtered=filtfilt(b,a,SjForce);
%for the squat jump
Sqforce_filtered=filtfilt(b,a,SqForce);
%code to obtain the mass of person m=f/gravity(9.81)
%gravity variable
%G= gravity whihc is 9.81
G=9.81;
%for the standard jump
Sjmass=mean(Sjforce_filtered(1:10))/G;
%for the Squat jump
Sqmass=mean(Sqforce_filtered(1:10))/G;
%code to obtain accerlation
%for the standard jump
Sjaccerlation=(Sjforce_filtered/Sjmass)-G;
%For the squat jump
Sqaccerlation=(Sqforce_filtered/Sqmass)-G;
%finding the velocity
%for the standard jump
Sjvelocity=cumtrapz(Sjt,Sjaccerlation);
%for the squat jump
Sqvelocity=cumtrapz(Sqt,Sqaccerlation);
%code to intergrate the the velocity
%for the standard jump
Sjcom_position=cumtrapz(Sjt,Sjvelocity);
%for the sqaut jump
Sqcom_position=cumtrapz(Sqvelocity);
%double intergration is needed
%also the height calculation
%for the standard height
Sjheight_intdou=max(Sjcom_position)-mean(Sjcom_position(1:10));
%for the squat jump
Sqheight_intdou=max(Sqcom_position)-mean(Sjcom_position(1:10));
%height calculation using the flight time method
%code to calculat the highest velocity number
%for the standrad jump
Sjtakeoff=max(Sjvelocity);
Sjflight_time_height=((Sjtakeoff*Sjflight)/2)-(0.5*G*(0.5*Sjflight)^2);
%for the sqaut jump
Sqtakeoff=max(Sqvelocity);
Sqflight_time_height=((Sqtakeoff*Sqflight)/2)-(0.5*G*(0.5*Sqflight)^2);
%height calculation uisng conservation of energy
%for the standrad jump
Sjenergy_height=0.5*((Sjtakeoff)^2/G);
%for the squat jump
Sqenergy_height=0.5*((Sqtakeoff)^2/G);

Akzeptierte Antwort

Steven Lord
Steven Lord am 28 Feb. 2024
Somewhere before this line of code:
Sjforce_filtered=filtfilt(b,a,SjForce);
at least one element of SjForce became non-finite (Inf or NaN.)
That variable gets created earlier in the code:
Sjx=readmatrix("G2 CM 04.csv");
%to remove the first 5 lines of information from the data as it is
%irrelvant goes to 6225 as that is the last info for the force plate
SjForce=-Sjx(6:6225, 5);
and no element of SjForce is changed between that line and when you try to use it in filtfilt. So I'd look at your "G2 CM 04.csv" data file and make sure it contains the data you think it does in the format you think it should be using.
Your code may not have changed, but it seems like your data did.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by