查看吉姆·克莱在评论中提到的参考文献后找到答案,谢谢吉姆。
我犯了一个错误,即仅考虑会导致零相位信号并且无法明智地用于发射的幅度,至少在此设置中不这样做。
我最终使用的代码可以在下面看到。
该脚本遵循命名约定,即时域信号应小写,频域信号应大写。
% Align and sum all files called Mandag*
files = dir('Mandag*');
% Where in the recordings the signal is
rng = [1.5e6, 1.52e6];
% Initialize the xh vector
[xh, fs] = wavread(files(1).name, rng);
xh = xh(:,1);
for i=2:length(files)
y = wavread(files(i).name, rng);
y = y(:,1);
% Determine offset between xh and y
[~, off] = max(xcorr(xh', y'));
off = length(xh) - off;
% Shift signal appropriately
if(off < 0)
y = [zeros(1, -off), y(1:end+off)'];
elseif (off > 0)
y = [y(off:end)', zeros(1, off-1)];
end
xh = xh + y';
end
% Average
xh = xh/length(files);
% Location of the 20ms signal
xh = xh(2306:12306-1);
% Normalize
xh = xh / max(xh);
% Apply a moving average filter on xh to reduce noise. Window size of 4 was
% experimentally determined to give the best results
n = 4;
B = zeros(n, 1);
for i=1:n
B(i) = 1/n;
end
xh = filter(B, 1, xh);
xh = xh / max(xh);
x = wavread('sweep.wav');
x = x(1:2:end); % Sweep generated @ 1MHz, decimate
% to have same length as xh
% Transform x into frequency domain and determine H
X = fft(x);
H = fft(xh) ./ X;
% Vector indices to choose only frequencies of interest
starti = 20e3 / 50;
endi = 100e3 / 50;
rng = starti:endi;
irng = (length(x) - endi) : (length(x) - starti);
% Zero out unwanted frequencies
X = [zeros(1, starti - 1 ), X( rng)', zeros(1, length(X)/2 - endi) ...
zeros(1, length(X)/2 - endi), X(irng)', zeros(1, starti - 1 )]';
% Deconvolve x with h
X_deconv_H = X ./ H;
% Transform X/H to time domain and normalise
x_deconv_h = real(ifft(X_deconv_H));
x_deconv_h = x_deconv_h / max(x_deconv_h);
% Save the deconvolved sweep
wavwrite(x_deconv_h, fs, 'deconvolved_sweep.wav');
% Generate spectrograms of xh and x_deconv_h
winsize = 512;
overlap = round(.99 * winsize);
figure(1)
specgram(xh, winsize, fs, hann(winsize), overlap)
colorbar
figure(2)
specgram(x_deconv_h, winsize, fs, hann(winsize), overlap)
colorbar
的谱图x conv h
和x deconv h
可以看到如下:
尽管去卷积信号中有些噪声,但这些对我来说似乎是合理的。
下一个测试将是查看发射是否x_deconv_y
给人类似x
的声音,除非扬声器无法发射那些频率。
更新测试结果
我们使用对数向下扫描重做上述测量。这些结果似乎表明该方法有效。
验证测试包括发射X / H
并期望X
返回,即所有频率下的能量相等。由于最差的输出频率比最差的输出频率弱约20dB,因此预计最高的输出电平会低得多。
发出的信号:
所记录信号的时间序列和频谱图如下所示: