Matlab fir2() 函数中傅立叶时移的作用是什么?

发布于 2024-12-10 14:38:28 字数 1210 浏览 1 评论 0 原文

我在理解 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-12-17 14:38:28

根据本文,因果滤波器设计需要-shift。引用一下,

如果为每个 指定了零相移,则
生成的 h(n) 将以原点为中心。因此最小
需要 g = (M-1)/2 个样本的延迟才能使滤波器具有因果性。经过
DTFT 的时移特性,这对应于
|Hd(F)| 乘以 exp(-j*g*2*pi*F)


换句话说,您可以绕过频域时移并仍然获得正确的滤波器,但这根本就不是因果关系。它将具有对称性并以原点为中心。

According to this paper, the time-shift is needed for causal filter design. To quote,

If a zero phase shift was specified for each <Hd(F) then the
resulting h(n) would be centered at the origin. Hence a minimum
delay of g = (M-1)/2 samples is needed to make the filter causal. By
the time-shift property of the DTFT, this corresponds to
multiplication of |Hd(F)| by exp(-j*g*2*pi*F).

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文