频域互相关延迟估计

麦克风声学延迟

clear;
N=1024;  %长度
Fs=500;  %采样频率
n=0:N-1;
t=n/Fs;   %时间序列
a1=1;     %信号幅度
a2=1;
d=-20;     %延迟点数
x1=a1*cos(2*pi*10*n/Fs);     %信号1
% x1=x1+randn(size(x1))/max(randn(size(x1)));      %加噪声
x2=a2*cos(2*pi*10*(n+d)/Fs); %信号2
% x2=x2+randn(size(x2));
% -------------------
% input number is below 1, and Prec_F is the (N-1)bit for N bit transform
Prec_F = 23;
% -------------------
input = x1;
for ii =1:length(input)
    if input(ii) == 1
        data_out(ii) = input(ii)*pow2(Prec_F)-1;
    else
        data_out(ii) = input(ii)*pow2(Prec_F);  
    end
end

data_out = round(data_out);

for ii = 1:length(input)
    if data_out(ii) < 0
        data_out(ii) = data_out(ii) + pow2(Prec_F+1);
    end
    data_out_Hex1(ii,:) = dec2hex(data_out(ii),(Prec_F+1)/4);
% dec2hex(data_out(ii),6)
end
data_out_Hex1

input = x2;
for ii =1:length(input)
    if input(ii) == 1
        data_out(ii) = input(ii)*pow2(Prec_F)-1;
    else
        data_out(ii) = input(ii)*pow2(Prec_F);  
    end
end

data_out = round(data_out);

for ii = 1:length(input)
    if data_out(ii) < 0
        data_out(ii) = data_out(ii) + pow2(Prec_F+1);
    end
    data_out_Hex2(ii,:) = dec2hex(data_out(ii),(Prec_F+1)/4);
% dec2hex(data_out(ii),6)
end
data_out_Hex2


Y1=fft(hex2dec(data_out_Hex1),N);
Y2=fft(hex2dec(data_out_Hex2),N);
S12=Y1.*conj(Y2);
Cxy=fftshift(real(ifft(S12)));
[max,location]=max(Cxy);%求出最大值max,及最大值所在的位置(第几行)location;
d2=location-N/2-1
Delay2=d2/Fs              %求得时间延迟


输出结果

d2 =

   -20


Delay2 =

   -0.0400

你可能感兴趣的:(语音识别)