clear;
clc;
rng=[0 1 149 1];
rng1=[150 1 299 1];
train_label=csvread('./training-a/REFERENCE.csv',0,1,rng);
for i=1:length(train_label)
if train_label(i)<0
train_label(i)=2;
end
end
test_label=csvread('./training-a/REFERENCE.csv',150,1,rng1);
for i=1:length(test_label)
if test_label(i)<0
test_label(i)=2;
end
end
figure();
subplot(211);
bar(test_label);
train_data=[];
test_data=[];
for i=1:9
ss=feature_extraction(strcat('./training-a/a000',num2str(i),'.wav'));
train_data=[train_data;ss];
end
for i=10:99
ss=feature_extraction(strcat('./training-a/a00',num2str(i),'.wav'));
train_data=[train_data;ss];
end
for i=100:150
ss=feature_extraction(strcat('./training-a/a0',num2str(i),'.wav'));
train_data=[train_data;ss];
end
for i=151:300
ss=feature_extraction(strcat('./training-a/a0',num2str(i),'.wav'));
test_data=[test_data;ss];
end
Factor = mnrfit(train_data, train_label);
Scores = mnrval(Factor, test_data);
S1=Scores(:,1);
S2=Scores(:,2);
predict_label=[];
for i=1:length(S1)
if S1(i)i)
predict_label=[predict_label;2];
else
predict_label=[predict_label;1];
end
end
subplot(212);
bar(predict_label);
accuracy = length(find(predict_label == test_label))/length(test_label)*100;
accuracy
分类结果:
accuracy =
76
由于只采用了150个信号做训练集,训练好的分类器只有76%的预测率,心音信号来源于
https://physionet.org/physiobank/database/challenge/2016/training.zip
REFERENCE.csv形式:
特征提取函数feature_extraction采用db6小波特征提取,函数代码如下:
function [ ss ] = feature_extraction(route )
[x,fs]=audioread(route);
x1=x(:,1);
level = 4;
wname ='db6';
t=wpdec(x1,level,wname,'shannon');
t0=wprcoef(t,[3,0]);
t1=wprcoef(t,[4,2]);
t2=wprcoef(t,[4,3]);
t3=wprcoef(t,[3,2]);
t4=wprcoef(t,[4,6]);
t5=wprcoef(t,[4,7]);
t6=wprcoef(t,[1,1]);
s0=norm(t0);
s1=norm(t1);
s2=norm(t2);
s3=norm(t3);
s4=norm(t4);
s5=norm(t5);
s6=norm(t6);
ss=[s0,s1,s2,s3,s4,s5,s6];
end