hello, I have a project and I'm extracting the features from emg signal, accelerometer signal and goniometer signal.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I extracting feature from 7 signals in a row for each signal, my question is how can I save the feature extracted for every signal in for loop because when I want to see the features, its showing the features of the 7th signal only
I will share accelerometer code and goniometer code.
accelerometer code:
clear all; close all;
for i = 1:7
eq = load ((['TBGACCPATIENT',num2str(i),'.txt']))';
Fs=400; % frequence d'echantillonage
len=length(eq);
mini=min(eq);
maxi=max(eq);
moy= mean(eq);
vari=var(eq);
stda= std(eq);
h = spectrum.welch; % Create a Welch spectral estimator.
Hpsd = psd(h,eq,'Fs',Fs); % Calculate the PSD
dd=Hpsd.Data;
Freq=Hpsd.Frequencies;
f=Freq;
Df=f(2)-f(1);
s=dd;
len1=length(dd);
M0=sum(s); %power of the signal
M1=sum(f.*s); % 2MPF
mpf=M1/M0; % mean frequency
cd1= sum((f-mpf).^3.*s);
cd2=sum((f-mpf).^2.*s);
Cd=cd1/sqrt(cd2^3);
% median of frequency Fmed
fm=0;
milieu=sum(dd)/2;
i=1;
fm=0;
while (( fm< milieu) & (i< length(eq)-1));
fm=fm+s(i);
i=i+1;
end
fmed=i*Df;
% kurtosis
ca1= sum((f-mpf).^4.*s);
ca2= sum((f-mpf).^2.*s);
Ca=ca1/(ca2^2);
% peak of frequency
pf = find(dd==max(dd));
pf=pf*Df;
% calcul of spectral entropy H
H=0;
ll=length(eq);
ss=length(s);
for i=1:length(s)
HH=length(H);
H=H+(s(i)*log(s(i)));
HHH=length(H);
end
%percentiles or fractiles fk
ss=cumsum(s);
frp=[];
for i=1:9
f1=find(ss>=(i/10)*sum(s));
frp=[frp;f1(1)*Df];
end
% % % relative energy by frequency band
Len=length(s) ;
Lseg=Len/10 ;
for i=0:9
w(i+1)=sum(s(Lseg*i+1:Lseg*(i+1)));
end
w1=w/M0;
[c,l]=wavedec(eq,5,'sym1');
ap5=appcoef(c,l,'sym1',5);
ap4=appcoef(c,l,'sym1',4);
ap3=appcoef(c,l,'sym1',3);
ap2=appcoef(c,l,'sym1',2);
ap1=appcoef(c,l,'sym1',1);
d5=detcoef(c,l,5);
d4=detcoef(c,l,4);
d3=detcoef(c,l,3);
d2=detcoef(c,l,2);
d1=detcoef(c,l,1);
format long g
V5=var(d5);
V4=var(d4);
V3=var(d3);
V2=var(d2);
V1=var(d1);
ftu=[mini;maxi;moy;vari;Cd;pf; stda ;mpf; fmed; Ca; H; V1; V2; V3; V4; V5;frp;w1'];
end
goniometer code:
clear all;close all;
for i = 1:7
x = load ((['TBGGONIOPATIENT',num2str(i),'.txt']))';
plot (x);
Fs = 4*1000; %Hz -- put in real data
t = (0 : length(x) - 1) / Fs;
%cftool (t,x)
[xData, yData] = prepareCurveData( t, x );
% Set up fittype and options.
ft = fittype( 'sin8' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf 0 -Inf -Inf 0 -Inf -Inf 0 -Inf -Inf 0 -Inf -Inf 0 -Inf -Inf 0 -Inf -Inf 0 -Inf -Inf 0 -Inf];
opts.StartPoint = [260.175794786051 1.25676273770969 0.0629107881533813 113.29478585637 2.51352547541938 1.59529193400343 22.4164334568717 5.02705095083875 1.45853359383986 12.9543596116753 20.108203803355 2.49920460557347 8.23752641768903 7.54057642625813 1.2050686662606 7.53966278924057 17.5946783279356 0.399135169386131 5.17482134679428 12.5676273770969 1.54711062715199 5.17211566529762 15.0811528525163 1.05486183464122];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit i' );
h = plot( fitresult, xData, yData );
legend( h, 'x vs. t', 'untitled fit i', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 't', 'Interpreter', 'none' );
ylabel( 'x', 'Interpreter', 'none' );
%pause;
end
3 Kommentare
dpb
am 15 Mai 2022
Yes, I just described the changes you need to make to do so...you have to create arrays of some sort inside the loop for the computed results of each step you need to save.
These are the most basic of concepts, if they're unfamiliar to you, I suggest going to <matlab-onramp> tutorial and spend the time to go through it.
There are rudiments of examples in the doc for the for...end statement and in all the examples of cell arrays and so on, as well.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Measurements and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!