-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSVMtest.m
65 lines (53 loc) · 1.67 KB
/
SVMtest.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
function [ out1, out2 ] = SVMtest( sig, fs, th, dim )
% Input : sig - the input signal.
% fs - the sampling rate.
% th - the power ratio threshold.
% dim - the dimension of time-domain feature.
% Output: out1 - the result of frequency domain check. [ 1 - high frequency
% dominant (replay attack); 0 - low frequency dominant (normal) ]
% out2 - the result of time domain check. [ 1 - burr (modulated
% replay attack); 0 - smooth (normal) ]
% Shu Wang
%% TEST
% clear;
% close all;
% [sig, fs] = audioread('./samples/modreplay/0001.wav');
% th = 0.1;
% dim = 20;
%--------------------- Check replay attack.---------------------%
%% Calculate the frequency spectrum
addpath('signalproc');
[f, amp, ~] = fastFT(sig(:, 1), fs);
%% Calculate the corresponding points of 2K / 4K
find2k = find(f > 2000, 1);
find4k = find(f > 4000, 1);
%% Calculate the ratio of HF(2K-4K) / LF(0-2K)
P = sum(amp(find2k:find4k-1).^2) / sum(amp(1:find2k-1).^2);
if (P > th)
out1 = 1;
disp('Frequency Domain Abnormal! [ The replay attack! ]');
else
out1 = 0;
disp('Frequency Domain Normal!');
end
%---------------- Check modulated replay attack.----------------%
%% Get the modulated feature
addpath('timedomain');
feature = [];
for v = 1 : dim
[~, rt] = Peakratio(sig, v);
feature(end+1) = rt;
end
%% Constant path
model_path = './model/SVMmodel.mat';
%% Load model
load(model_path);
%% Preprocess feature
out2 = svmpredict(0, feature, SVMSTRUCT);
%% Display
if (out2)
disp('Time Domain Abnormal! [ The modulated replay attack! ]');
else
disp('Time Domain Normal!');
end
end