⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pitch1.m

📁 非常好的数字处理教程
💻 M
字号:
%
%  Auto-Correlation Pitch Detection Algorithm
%
% Code borrowed in part from C.H. Wong
% http://www.cse.cuhk.edu.hk/~chwong1/research.html#MatLabCode
%
% Something happens around f = 2000... it starts going down.
% Use only on signals with a fundamental < 1000 Hz.
% Return freq, and error estimate!

function freq = pitch1(frame, Fs)

	num_samples = length(frame);

	frame_xcorr = xcorr(frame, frame, 'coeff' );

	length_xcorr = length(frame_xcorr);
	peak = frame_xcorr;
	peak(num_samples) = 0;

	% Find the Peaks
	for i=2:length(frame_xcorr)-1
		if frame_xcorr(i)>frame_xcorr(i-1) & frame_xcorr(i)>frame_xcorr(i+1)
			peak(i) = frame_xcorr(i);
		else
			peak(i) = 0;
		end
	end

	% Find the maximum
	[sort_peak,sort_peak_index] = sort(-peak);

	% Choose three highest peaks
	index = sort(sort_peak_index(1:3));
	p1 = index(2)-index(1);
	p2 = index(3)-index(2);
	freq = Fs/((p1+p2)/2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -