-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_reto.m
67 lines (62 loc) · 1.6 KB
/
audio_reto.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
% Initialization
clear
close all
clc
badSamples = 0;
fs2 = 44100;
while true
%record audio
audio = audiorecorder;
disp('Start sampling.')
recordblocking(audio, 10);
disp('End of Sample.');
%analyze it
aFE3 = audioFeatureExtractor( ...
SampleRate=fs2, ...
Window=hamming(round(0.03*fs2),"periodic"), ...
OverlapLength=round(0.02*fs2), ...
linearSpectrum=true,...
melSpectrum=true,...
barkSpectrum=true,...
mfcc=true, ...
mfccDelta=true, ...
mfccDeltaDelta=true, ...
pitch=true, ...
spectralCentroid=true, ...
zerocrossrate=true, ...
shortTimeEnergy=true,...
spectralCentroid=true, ...
spectralCrest=true, ...
spectralDecrease=true, ...
spectralEntropy=true, ...
spectralFlatness=true, ...
spectralFlux=false, ...
spectralKurtosis=true, ...
spectralRolloffPoint=true, ...
spectralSkewness=true, ...
spectralSlope=true, ...
spectralSpread=true,...
harmonicRatio=true);
features3 = extract(aFE3,audio.getaudiodata);
idx3 = info(aFE3);
q1=features3(:,idx3.spectralEntropy);
q2=features3(:,idx3.zerocrossrate);
n = length(q2);
thresholdN = n * .30;
badSamples = 0;
% plot(q1,q2,'r*')
% xlabel('entropy');
% ylabel('pitch')
% check if error
for i = 1 : n
if q1(i) < 0.7 && q2(i) > 0.02
badSamples = badSamples + 1;
end
end
if badSamples > thresholdN
disp('State: Critical');
else
disp('State: Normal');
end
% disp(badSamples);
end