Skip to content

Commit 5331601

Browse files
Updated code for 20a release
1 parent e4d7e6f commit 5331601

File tree

178 files changed

+12442
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+12442
-127
lines changed

HelperFiles/DownloadData.m

Lines changed: 0 additions & 28 deletions
This file was deleted.

HelperFiles/OpenCodegenReport.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
% Copyright 2018-2020 The MathWorks, Inc.
2+
3+
function OpenCodegenReport
4+
5+
prj = currentProject;
6+
open(fullfile(prj.RootFolder,'arm_compute','html','report.mldatx'));
7+
8+
end

HelperFiles/OpenPart1.m

Lines changed: 0 additions & 3 deletions
This file was deleted.

HelperFiles/OpenPart2.m

Lines changed: 0 additions & 3 deletions
This file was deleted.

HelperFiles/OpenPart3.m

Lines changed: 0 additions & 3 deletions
This file was deleted.

HelperFiles/extractFeatures.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
% Copyright 2020 The MathWorks, Inc.
2+
3+
function features = extractFeatures(audioIn,fs)
4+
5+
%#codegen
6+
7+
persistent stf F winPower
8+
9+
if(isempty(stf))
10+
% Setup a short time fourier transform object
11+
FFTLength = 512;
12+
windowLength = 512;
13+
hopLength = 512;
14+
win = hamming(windowLength,'periodic');
15+
winPower = 2/(sum(win)^2);
16+
stf = dsp.STFT(win,windowLength-hopLength,FFTLength);
17+
[~,temp] = stft(zeros(windowLength,1),fs,'Window',win,'OverlapLength',windowLength-hopLength,'centered',false);
18+
F = temp(1:257);
19+
end
20+
21+
Xcomp = stf(audioIn);
22+
Xcomp= Xcomp(1:257,:);
23+
24+
% Get power spectrum
25+
X = real(Xcomp.*conj(Xcomp));
26+
27+
% Normalize by window power
28+
X = X .* winPower;
29+
30+
X(1,:) = 0.5*X(1,:);
31+
X(end,:) = 0.5*X(end,:);
32+
33+
S1 = spectralCentroid(X,F);
34+
S2 = spectralCrest(X,F);
35+
S3 = spectralDecrease(X,F);
36+
S4 = spectralEntropy(X,F);
37+
S5 = spectralFlatness(X,F);
38+
% S6 = spectralFlux(X,F);
39+
S7 = spectralKurtosis(X,F);
40+
S8 = spectralRolloffPoint(X,F);
41+
S9 = spectralSkewness(X,F);
42+
S10 = spectralSlope(X,F);
43+
S11 = spectralSpread(X,F);
44+
45+
features = [S1 S2 S3 S4 S5 S7 S8 S9 S10 S11];
46+
47+
end
48+

HelperFiles/reloadDatastore.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
% Copyright 2020 The MathWorks, Inc.
2+
3+
% Recreate the datastore again
4+
5+
dataFolder = 'AirCompressorData';
6+
ads = audioDatastore(dataFolder,'IncludeSubfolders',true,'LabelSource','foldernames');
7+
rng(3);
8+
ads = shuffle(ads);
9+
[adsTrain,adsValidation] = splitEachLabel(ads,0.9,0.1);

HelperFiles/streamingClassifier.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
% Copyright 2020 The MathWorks, Inc.
2+
3+
function [scores,features] = streamingClassifier(audioIn,M,S)
4+
% This is a streaming classifier function
5+
6+
persistent airCompNet;
7+
8+
if isempty(airCompNet)
9+
airCompNet = coder.loadDeepLearningNetwork('TrainedModel.mat');
10+
end
11+
12+
% Extract features using function
13+
features = extractFeatures(audioIn,16e3);
14+
15+
% Normalize
16+
features = single(((features - M)./S))';
17+
18+
% Classify
19+
[airCompNet, scores] = predictAndUpdateState(airCompNet,features);
20+
21+
end
22+

Images/bearingsignal.png

-20.8 KB
Binary file not shown.

Images/confusionmat.png

-18.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)