-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_features.m
73 lines (58 loc) · 1.94 KB
/
get_features.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
68
69
70
71
72
73
function [filters, result_mat] = get_features(sounds, fs, method, plot_figs)
M = 12;
samples = size(sounds, 1);
dataset_sz = size(sounds, 2);
sz = 1102; % changed name due to conflict with size()
freq = [0.0027, 0.0089, 0.0173, 0.0284, 0.0433, 0.0632, 0.0898, 0.1254, 0.1730, 0.2365, 0.3215, 0.4350];
sigma = [187.2109, 140.0663, 104.7939, 78.4041, 58.6599, 43.8878, 32.8357, 24.5668, 18.3803, 13.7516, 10.2886, 7.6977];
cos_filters = zeros(M, sz);
sin_filters = zeros(M, sz);
exp_filters = zeros(M, sz);
% Ex 2 -- creating the filter set
for i = 1:M
[comp, cos_i, sin_i] = gabor_filter(sz, sigma(i), freq(i));
exp_filters(i, :) = comp;
cos_filters(i, :) = cos_i;
sin_filters(i, :) = sin_i;
end
if plot_figs == true
% plotting the results of the first parameters
figure;
plot(1:sz, cos_filters(1, :));
title("Gabor filter - cos");
figure;
plot(1:sz, sin_filters(1, :));
title("Gabor filter - sin");
% Ex 3 -- plotting the spectrum of the filters
% for cos
figure;
for i = 1:M
hold on;
spectrum = fft(cos_filters(i, :));
spectrum = spectrum(1:sz/2);
plot(1:sz/2, abs(spectrum));
end
xlabel("Frequency component");
ylabel("Magnitude");
title("Gabor Filters - cos");
% for sin
figure;
for i = 1:M
hold on;
spectrum = fft(sin_filters(i, :));
spectrum = spectrum(1:sz/2);
plot(1:sz/2, abs(spectrum));
end
xlabel("Frequency component");
ylabel("Magnitude");
title("Gabor Filters - sin");
end
% applying the filters
if method == 0
result_mat = get_result_conv(sounds, cos_filters, dataset_sz, M);
elseif method == 1
result_mat = get_stride_conv(sounds, cos_filters, sin_filters, exp_filters, dataset_sz, fs, samples, M);
end
% returning all the filters
filters = [cos_filters; sin_filters; exp_filters];
end