Exercise 1b in slide 14 of http://www.cse.cuhk.edu.hk/~khwong

advertisement
Exercise 1b in slide 14 of http://www.cse.cuhk.edu.hk/~khwong/www2/cmsc5707/5707_3_pitch.ppt
Question: x=[1 3 7 2 1 9 3 1 8 ], sampling at 1Hz.Find pitch of this signal x using MACF (Modified
Autocorrelation function) .
%%%%%%%%%%%%%%Answer: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
orginal_x =
1
3
7
2
1
9
3
1
8
x =centered_wave =orginal_x-mean_x =
-2.8889 -0.8889 3.1111 -1.8889 -2.8889 5.1111 -0.8889 -2.8889 4.1111
cl=center clipped range=
2
y =center clipped signal=
-2.8889
0 3.1111
0 -2.8889 5.1111
0 -2.8889 4.1111
>> Answer: from the autocorrelation result of y in the figure, we can see that the distance between 2
peaks is 3, so pitch is 1/3 Hz, since the sampling is 1 Hz..
%dec 2012, MACF (Modified Autocorrelation function)using center clipping
clear
%select one of the followings
%real_data=1 %1 or 0
real_data=0
if real_data==1
%use real sound
%[x,fs]=wavread ('d:\0music\sounds\violin3.wav');
[orginal_x,fs]=wavread ('violin3.wav');
x=x(10000:11000);
else
%use test data
%x=[1 2 5 6 7 6 1 0 4 3 4 8 6 7 3 2 4 9 3 ]
orginal_x=[1 3 7 2 1 9 3 1 8 ]
fs=1 %assume frquecy is 1Hz
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% test
x=orginal_x-mean(orginal_x)
n=length(x)
maxx=max(x)
minx=min(x)
dd=maxx-minx
figure(1)
clf
plot(x)
%pause
%center clippin algo for pitch extccation
if real_data==1
cl=dd/4000
else
cl=dd/4 %center clippped "cl" length is 1/4 of total peak-to_peak span
pause
end
%assume the signal x is voltage against time
%center clip means set those signals with levels within the clipped regions
%center = mean voltage level of the whole signal
%positive peak = maxim,um of the signal voltage
%negative peak = minimum of the signal voltage
%center clip regions are:(i) from center to 1/2 of center_to_positive peak
%
(ii) from center to -1/2 from center_to_negative peak
for t=1:n
if x(t)<cl & x(t) > -1*cl %those within center clipped region set to 0
y(t)=0;
else
y(t)=x(t);
end;
end ;
auto_corr_y=xcorr(y) %auto correlation
figure(2)
clf
subplot(3,1,1),plot(x)
ylabel('x=centered wave')
subplot(3,1,2),plot(y)
ylabel('y=center clipped wave')
hold on
subplot(3,1,3),plot(auto_corr_y)
ylabel('auto correlation of y')
xlabel('time ')
max_list=max(y)
fs
'orginal_x ' , orginal_x
'x =centered_wave =orginal_x-mean_x ' ,
'cl=center clipped range', cl
'y =center clipped signal' , y
x
Download