-
Notifications
You must be signed in to change notification settings - Fork 0
/
F_Frequency_Feature_STFTStatistics_Backup_v2.m
66 lines (56 loc) · 3.42 KB
/
F_Frequency_Feature_STFTStatistics_Backup_v2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function frequencyFeatures = F_Frequency_Feature_STFTStatistics(signal, fs, win, step, FFTPeakNumber )
windowLength = round(win * fs);
step = round(step * fs);
% FFTPeakNumber=10;
curPos = 1;
L = length(signal);
[featureNames,...
numberOfFeatures,...
numberofFFTPeakFeatures] = G_FeatureExtraction_Frequency_STFTStastistics_FeatureNames(FFTPeakNumber);
% compute the total number of frames:
Ham = window(@hamming, windowLength);
numOfFrames = floor((L-windowLength)/step) + 1;
frequencyFeatures = zeros(numberOfFeatures, numOfFrames);
for i=1:numOfFrames
frame = signal(curPos:curPos+windowLength-1);
frame = frame .* Ham;
frameFFT = F_Frequency_Feature_getDFT(frame , fs);
if (sum(abs(frame))>eps)
if (i==1)
frameFFTPrev = frameFFT;
end
fnum=1;
frequencyFeatures(fnum,i) = max(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = min(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = mean(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = median(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = mode(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = std(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = var(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = max(frameFFT)- min(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = skewness(frameFFT,1); fnum=fnum+1;
frequencyFeatures(fnum,i) = kurtosis(frameFFT,1); fnum=fnum+1;
frequencyFeatures(fnum,i) = moment(frameFFT,3); fnum=fnum+1;
frequencyFeatures(fnum,i) = F_Time_Feature_Energy_Entropy(frameFFT, 10); fnum=fnum+1;
frequencyFeatures(fnum,i) = peak2peak(frameFFT); fnum=fnum+1;
frequencyFeatures(fnum,i) = peak2rms(frameFFT); fnum=fnum+1;
frameFFTFlux = frameFFT / sum(frameFFT);
frameFFTPrevFlux = frameFFTPrev / sum(frameFFTPrev+eps);
frequencyFeatures(fnum,i) = sum((frameFFTFlux - frameFFTPrevFlux ).^2); fnum=fnum+1;
% [pks,locs,widths,proms] = findpeaks(frameFFT,...
% 'SortStr','descend','NPeaks',numberofPeak);
frequencyFeatures(fnum:fnum+numberofFFTPeakFeatures-1,...
i) = F_Time_Feature_PeakAnalysis(frameFFT,FFTPeakNumber);
fnum=fnum+numberofFFTPeakFeatures;
% frequencyFeatures(fnum:fnum+numberofPeak-1,i)=pks; fnum=fnum+numberofPeak;
% frequencyFeatures(fnum:fnum+numberofPeak-2,i)=diff(locs); fnum=fnum+numberofPeak-1;
% frequencyFeatures(fnum:fnum+numberofPeak-1,i)=widths; fnum=fnum+numberofPeak;
% frequencyFeatures(fnum:fnum+numberofPeak-1,i)=proms; fnum=fnum+numberofPeak;
else
frequencyFeatures(:,i) = zeros(numberOfFeatures, 1);
end
curPos = curPos + step;
frameFFTPrev = frameFFT;
end
frequencyFeatures(numberOfFeatures, :) = medfilt1(frequencyFeatures(numberOfFeatures, :), 3);
end