-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadTestingData.m
More file actions
79 lines (61 loc) · 3.18 KB
/
LoadTestingData.m
File metadata and controls
79 lines (61 loc) · 3.18 KB
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
74
75
76
77
78
79
%% EECS351 load testing data
% audioNormalization_YW courtesy Yi-Wen Chen
% https://www.mathworks.com/matlabcentral/fileexchange/69958-audio-normalization-by-matlab
cd Testfiles\;
TESTfiles = dir('*.mp3'); %specify test files (I have them in the main matlab directory)
actual = {};
testindex=1;
for file = TESTfiles' %concatenate test audio
temp=audioNormalization_YW(audioread(file.name),0.5); %normalize
if(length(temp) >= 200000)
temp=temp(1:200000,:);
ftemp=pitch(temp,48000,WindowLength=window,OverlapLength=overlap);
%extract voiced segments courtesy MATLAB
%https://www.mathworks.com/help/audio/ug/speaker-identification-using-pitch-and-mfcc.html
[segments,~] = buffer(temp,window,overlap,"nodelay");
ste = sum((segments.*hamming(window,"periodic")).^2,1);
isSpeech = ste(:) > energyThreshold;
zcr = zerocrossrate(temp,WindowLength=window,OverlapLength=overlap);
isVoiced = zcr < zcrThreshold;
voicedSpeech = isSpeech & isVoiced;
ftemp(~voicedSpeech) = [];
%smoothing
inrange = (25 < ftemp) & (ftemp < 375);
removeSaturation = ftemp(inrange);
removeSaturation(1:round(length(ftemp)/10))=[];
instdrange = (removeSaturation > mean(removeSaturation)-2*std(removeSaturation)) & ...
(removeSaturation < mean(removeSaturation)+2*std(removeSaturation));
removeOutliers = removeSaturation(instdrange);
smooth=movmean(removeOutliers,5,'Endpoints','discard');
%smooth=lowpass(smooth,8000,48000);
%feature calculation
delta=diff(smooth);
p2p=peak2peak(smooth);
avgdelta = mean(abs(delta));
meddelta = median(abs(delta));
dft=abs(fft(smooth));
scalarfeatures = [p2p avgdelta meddelta];
if(contains(file.name,'CN')) %assigning ground truth labels for confusion matrix
actual(testindex,:)={'CN'};
[mfcctemp,deltatemp,deltadeltatemp]=mfcc(temp,48000); %compute mfcc
elseif(contains(file.name,'en'))
actual(testindex,:)={'EN'};
[mfcctemp,deltatemp,deltadeltatemp]=mfcc(temp,48000); %compute mfcc
elseif(contains(file.name,'hi'))
actual(testindex,:)={'HN'};
[mfcctemp,deltatemp,deltadeltatemp]=mfcc(temp,48000); %compute mfcc
end
mfcctemp(1:25,:)=[];
mfcctest1d=reshape(mfcctemp.',1,[]); %resize array to 1d for testing
mfcctest1d=[mfcctest1d scalarfeatures];
mfcctest(1:length(mfcctest1d),testindex)=mfcctest1d(:); %add to test array
testindex=testindex+1;
end
end
mfcctest=mfcctest.';
%mfcctest=gpuArray(mfcctest.'); %transpose
if(size(mfcctest,2)>size(mfccTrain,2))
mfcctest(:,size(mfccTrain,2)+1:size(mfcctest,2))=[];
elseif(size(mfcctest,2)<size(mfccTrain,2))
mfccTrain(:,size(mfcctest,2)+1:size(mfccTrain,2))=[];
end