我有 2 个具有不同采样率的信号,即 1ms(A) 和 4ms(B),我尝试根据代码片段对任何一个信号进行上采样/下采样基于 FFT的重新采样,我认为这相当于如何使用 fft 或 dft 重新采样音频中描述了什么
% FFTRESAMPLE Resample a real signal by the ratio p/q
function y = fftResample(x,p,q)
% --- take FFT of signal ---
f = fft(x);
% --- resize in the FFT domain ---
% add/remove the highest frequency components such that len(f) = len2
len1 = length(f);
len2 = round(len1*p/q);
lby2 = 1+len1/2;
if len2 < len1
% remove some high frequency samples
d = len1-len2;
f = f(:);
f(floor(lby2-(d-1)/2:lby2+(d-1)/2)) = [];
elseif len2 > len1
% add some high frequency zero samples
d = len2-len1;
lby2 = floor(lby2);
f = f(:);
f = [f(1:lby2); zeros(d,1); f(lby2+1:end)];
end
% --- take the IFFT ---
% odd number of sample removal/addition may make the FFT of a real signal
% asymmetric and artificially introduce imaginary components - we take the
% real value of the IFFT to remove these, at the cost of not being able to
% reample complex signals
y = real(ifft(f));
即,使用 FFTW 库在 C++ 中重新实现了 fftResample。
问题是由于零填充,输出失真。我对 Singal 处理比较陌生,如果用户能帮助我理解,我将不胜感激:
如果我使用正确的代码片段来上采样/下采样?
突出上采样(A 到 4 毫秒)与下采样(B 到 1 毫秒)相比的优势?