-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion2.m
48 lines (42 loc) · 1003 Bytes
/
question2.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
function pitch = question2(frames, w_size, voiced)
figure(2);
%center-clipping
pitch_freqs = amdf_pitch(frames, w_size, voiced);
subplot(2,1,1)
hold on
for i = 1:5
scatter(0:length(pitch_freqs)-1, pitch_freqs(i,:), 20);
end
title('amdf');
ylabel('frequency (Hz)')
set(gca,'xtick',0:10:240)
legend('candidate1', 'candidate2', 'candidate3', 'candidate4', 'candidate5')
hold off
%smooth
smoothed = nan(5, length(pitch_freqs));
for i = 1:length(pitch_freqs)
for j = 1:5
if pitch_freqs(j, i) <= 160
smoothed(j, i) = pitch_freqs(j, i);
end
end
end
smoothed = smooth2a(smoothed, 5, 5);
h = nan(1, length(smoothed));
for i = 1:length(smoothed)
for j = 1:5
if ~isnan(smoothed(j, i))
h(i) = max(smoothed(j, i));
end
end
end
%
pitch = nanmedian(h);
subplot(2,1,2)
plot(0:length(pitch_freqs)-1, h, 'linewidth', 4);
title('amdf (smooth contour)')
xlabel('frame number')
set(gca,'xtick',0:10:240)
ylabel('frequency (Hz)')
ylim([0 400])
end