forked from perivar/FindSimilar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.m
173 lines (159 loc) · 4.17 KB
/
demo.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
% Demo script that generates all graphics in the report
% and demonstrates our results.
%
%
%%%%%%%%%%%%%%%%%%
% Mini-Project: An automatic speaker recognition system
%
% Responsible: Vladan Velisavljevic
% Authors: Christian Cornaz
% Urs Hunkeler
disp('Mini-Projet: Automatic Speaker Recognition');
disp('By Christian Cornaz & Urs Hunkeler (SC)');
disp('Responsible Assistant: Vladan Velisavljevic');
disp(' ');
disp(' ');
[s1 fs1] = wavread('train\s1.wav');
[s2 fs2] = wavread('train\s2.wav');
%Question 2
disp('> Question 2');
t = 0:1/fs1:(length(s1) - 1)/fs1;
plot(t, s1), axis([0, (length(s1) - 1)/fs1 -0.4 0.5]);
title('Plot of signal s1.wav');
xlabel('Time [s]');
ylabel('Amplitude (normalized)')
pause
close all
%Question 3 (linear)
disp('> Question 3: linear spectrum plot');
M = 100;
N = 256;
frames = blockFrames(s1, fs1, M, N);
t = N / 2;
tm = length(s1) / fs1;
subplot(121);
imagesc([0 tm], [0 fs1/2], abs(frames(1:t, :)).^2), axis xy;
title('Power Spectrum (M = 100, N = 256)');
xlabel('Time [s]');
ylabel('Frequency [Hz]');
colorbar;
%Question 3 (logarithmic)
disp('> Question 3: logarithmic spectrum plot');
subplot(122);
imagesc([0 tm], [0 fs1/2], 20 * log10(abs(frames(1:t, :)).^2)), axis xy;
title('Logarithmic Power Spectrum (M = 100, N = 256)');
xlabel('Time [s]');
ylabel('Frequency [Hz]');
colorbar;
D=get(gcf,'Position');
set(gcf,'Position',round([D(1)*.5 D(2)*.5 D(3)*2 D(4)*1.3]))
pause
close all
%Question 4
disp('> Question 4: Plots for different values for N');
lN = [128 256 512];
u=220;
for i = 1:length(lN)
N = lN(i);
M = round(N / 3);
frames = blockFrames(s1, fs1, M, N);
t = N / 2;
temp = size(frames);
nbframes = temp(2);
u=u+1;
subplot(u)
imagesc([0 tm], [0 fs1/2], 20 * log10(abs(frames(1:t, :)).^2)), axis xy;
title(sprintf('Power Spectrum (M = %i, N = %i, frames = %i)', M, N, nbframes));
xlabel('Time [s]');
ylabel('Frequency [Hz]');
colorbar
end
D=get(gcf,'Position');
set(gcf,'Position',round([D(1)*.5 D(2)*.5 D(3)*1.5 D(4)*1.5]))
pause
close all
%Question 5
disp('> Question 5: Mel Space');
plot(linspace(0, (fs1/2), 129), (melfb(20, 256, fs1))');
title('Mel-Spaced Filterbank');
xlabel('Frequency [Hz]');
pause
close all
%Question 6
disp('> Question 6: Modified spectrum');
M = 100;
N = 256;
frames = blockFrames(s1, fs1, M, N);
n2 = 1 + floor(N / 2);
m = melfb(20, N, fs1);
z = m * abs(frames(1:n2, :)).^2;
t = N / 2;
tm = length(s1) / fs1;
subplot(121)
imagesc([0 tm], [0 fs1/2], abs(frames(1:n2, :)).^2), axis xy;
title('Power Spectrum unmodified');
xlabel('Time [s]');
ylabel('Frequency [Hz]');
colorbar;
subplot(122)
imagesc([0 tm], [0 20], z), axis xy;
title('Power Spectrum modified through Mel Cepstrum filter');
xlabel('Time [s]');
ylabel('Number of Filter in Filter Bank');
colorbar;
D=get(gcf,'Position');
set(gcf,'Position',[0 D(2) D(3)*2 D(4)])
pause
close all
%Question 7
disp('> Question 7: 2D plot of accustic vectors');
c1 = mfcc(s1, fs1);
c2 = mfcc(s2, fs2);
plot(c1(5, :), c1(6, :), 'or');
hold on;
plot(c2(5, :), c2(6, :), 'xb');
xlabel('5th Dimension');
ylabel('6th Dimension');
legend('Signal 1', 'Signal 2');
title('2D plot of accoustic vectors');
pause
close all
%Question 8
disp('> Question 8: Plot of the 2D trained VQ codewords')
d1 = vqlbg(c1,16);
d2 = vqlbg(c2,16);
plot(c1(5, :), c1(6, :), 'xr')
hold on
plot(d1(5, :), d1(6, :), 'vk')
plot(c2(5, :), c2(6, :), 'xb')
plot(d2(5, :), d2(6, :), '+k')
xlabel('5th Dimension');
ylabel('6th Dimension');
legend('Speaker 1', 'Codebook 1', 'Speaker 2', 'Codebook 2');
title('2D plot of accoustic vectors');
pause
close all
% %Question 8
% disp('> Question 8: Plot of the 2D trained VQ codewords')
% d1 = vqlbg(c1,16);
% d2 = vqlbg(c2,16);
% subplot(121)
% plot(c1(5, :), c1(6, :), 'or')
% hold on
% plot(d1(5,:),d1(6,:),'+')
% xlabel('5th Dimension');
% ylabel('6th Dimension');
% legend('Speaker 1', 'Codebook of s1');
% title('2D plot of accoustic vectors');
% subplot(122)
% plot(c2(5, :), c2(6, :), 'or')
% hold on
% plot(d2(5,:),d2(6,:),'+')
% xlabel('5th Dimension');
% ylabel('6th Dimension');
% legend('Speaker 2', 'Codebook of s2');
% title('2D plot of accoustic vectors');
% D=get(gcf,'Position');
% set(gcf,'Position',[0 D(2) D(3)*2 D(4)])
% pause
% close all