-
Notifications
You must be signed in to change notification settings - Fork 0
/
stFeatureExtraction.m
73 lines (64 loc) · 2.37 KB
/
stFeatureExtraction.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
67
68
69
70
71
72
73
function Features = stFeatureExtraction(signal, fs, win, step)
% function Features = stFeatureExtraction(signal, fs, win, step)
%
% This function computes basic audio feature sequencies for an audio
% signal, on a short-term basis.
%
% ARGUMENTS:
% - signal: the audio signal
% - fs: the sampling frequency
% - win: short-term window size (in seconds)
% - step: short-term step (in seconds)
%
% RETURNS:
% - Features: a [MxN] matrix, where M is the number of features and N is
% the total number of short-term windows. Each line of the matrix
% corresponds to a seperate feature sequence
%
% (c) 2014 T. Giannakopoulos, A. Pikrakis
% if STEREO ...
if (size(signal,2)>1)
signal = (sum(signal,2)/2); % convert to MONO
end
% convert window length and step from seconds to samples:
windowLength = round(win * fs);
step = round(step * fs);
curPos = 1;
L = length(signal);
% compute the total number of frames:
numOfFrames = floor((L-windowLength)/step) + 1;
% number of features to be computed:
numOfFeatures = 35;
Features = zeros(numOfFeatures, numOfFrames);
Ham = window(@hamming, windowLength);
mfccParams = feature_mfccs_init(windowLength, fs);
for i=1:numOfFrames % for each frame
% get current frame:
frame = signal(curPos:curPos+windowLength-1);
frame = frame .* Ham;
frameFFT = getDFT(frame, fs);
if (sum(abs(frame))>eps)
% compute time-domain features:
Features(1,i) = feature_zcr(frame);
Features(2,i) = feature_energy(frame);
Features(3,i) = feature_energy_entropy(frame, 10);
% compute freq-domain features:
if (i==1) frameFFTPrev = frameFFT; end;
[Features(4,i) Features(5,i)] = ...
feature_spectral_centroid(frameFFT, fs);
Features(6,i) = feature_spectral_entropy(frameFFT, 10);
Features(7,i) = feature_spectral_flux(frameFFT, frameFFTPrev);
Features(8,i) = feature_spectral_rolloff(frameFFT, 0.90);
MFCCs = feature_mfccs(frameFFT, mfccParams);
Features(9:21,i) = MFCCs;
[HR, F0] = feature_harmonic(frame, fs);
Features(22, i) = HR;
Features(23, i) = F0;
Features(23+1:23+12, i) = feature_chroma_vector(frame, fs);
else
Features(:,i) = zeros(numOfFeatures, 1);
end
curPos = curPos + step;
frameFFTPrev = frameFFT;
end
Features(35, :) = medfilt1(Features(35, :), 3);