我在理解 Matlab 信号处理工具箱 fir2() 函数中的一些代码片段时遇到问题:
% My comment: at this point vector H contains nn+1 (nn is an even number) points (double numbers) of amplitudes for a dense frequency grid
% Fourier time-shift.
dt = 0.5 .* (nn - 1);
rad = -dt .* sqrt(-1) .* pi .* (0:npt-1) ./ (npt-1);
H = H .* exp(rad);
%My comment: now H contains nn+1 complex numbers
%My comment: creates a horizontal mirror with 2*nn points
Hconj = [H conj(H(npt-1:-1:2))]; % Fourier transform of real series.
ht = real(ifft(Hconj)); % Symmetric real series.
%My comment: throws away the half after ht[nn]
b = ht(1:nn); % Raw numerator.
wind = hamming(nn);
b = b .* wind(:).'; % Apply window.
令我困惑的是:
- 如果我注释掉傅里叶时移,则 ifft 的结果围绕 ht[nn] 对称
- 如果我保持傅立叶时移代码不变,则 ifft 的结果不再围绕 ht[nn] 对称,但它在 ht[nn/2] 和 ht[3*nn/4] 周围有两个对称组,而两个部分都围绕 ht[nn/2] 和 ht[nn/2] 对称ht[nn] 在情节中看起来确实不同。但是 ht[nn] 之后的所有内容都被丢弃,所以如果我需要最终输出是对称的,我必须保留傅里叶时移。
为什么需要傅里叶时移?我可以在我的 C++ 应用程序中用一些更简单的算法替换它吗?该算法不使用复数,并且仍然得到围绕 ht[nn/2] 对称的 nn 点,这样我就可以扔掉 ht[nn] 之后的所有内容?
PS 我只是查看了有和没有傅立叶时移的图,并注意到通过将第二个结果 nn/2 向右移动可以得到相同的结果。因此,理论上我可以避免在 C++ 应用程序中使用傅立叶时移,而只需将 ifft 的实际结果向右移动 nn/2,然后丢弃 nn 之后的所有内容。我说得对吗?这样做安全吗?
I have a problem understanding some code fragment from Matlab Signal processing Toolbox fir2() function:
% My comment: at this point vector H contains nn+1 (nn is an even number) points (double numbers) of amplitudes for a dense frequency grid
% Fourier time-shift.
dt = 0.5 .* (nn - 1);
rad = -dt .* sqrt(-1) .* pi .* (0:npt-1) ./ (npt-1);
H = H .* exp(rad);
%My comment: now H contains nn+1 complex numbers
%My comment: creates a horizontal mirror with 2*nn points
Hconj = [H conj(H(npt-1:-1:2))]; % Fourier transform of real series.
ht = real(ifft(Hconj)); % Symmetric real series.
%My comment: throws away the half after ht[nn]
b = ht(1:nn); % Raw numerator.
wind = hamming(nn);
b = b .* wind(:).'; % Apply window.
What confuses me is:
- if I comment out that Fourier time-shift, the result of ifft is symmetrical around ht[nn]
- if I leave Fourier time shift code intact, the result of ifft is no longer symmetrical around ht[nn] but it has two symmetrical groups around ht[nn/2] and ht[3*nn/4], while both parts around ht[nn] look really different in a plot. But everything after ht[nn] is thrown away, so if I need the final output to be symmetrical, I have to leave that Fourier time shift.
Why is that Fourier time shift needed? Can I replace it with some simpler algorithm in my C++ application which is not using complex numbers and still get out nn points with symmetry around ht[nn/2] so I can throw away everything after ht[nn]?
P.S. I just looked at the plots with and without Fourier timeshift and noticed that I can get the same result by shifting the second result nn/2 to the right. So theoretically I could avoid using Fourier time shift in my C++ application but just shift the real results of ifft by nn/2 to the right and then throw away everything after nn. Am I right? Is it safe to do?
发布评论
评论(1)
根据本文,因果滤波器设计需要-shift。引用一下,
换句话说,您可以绕过频域时移并仍然获得正确的滤波器,但这根本就不是因果关系。它将具有对称性并以原点为中心。
According to this paper, the time-shift is needed for causal filter design. To quote,
In other words, you can bypass frequency-domain time-shift and still get the right filter back, but it simply will not be causal. It will sill have symmetry and be centered at the origin.