You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何我实现的离散时间傅里叶变换(DTFT)结果不正确?

Troubleshooting Your Custom DTFT Implementation in MATLAB

Hey there! Let's break down the issues in your code and fix them to get the expected DTFT results for your cosine sequence.

Key Problems in Your Current Code

  1. Confusing DTFT with DFT Scaling
    Your code uses exp((-1i.*k.*2/l.*pi.*(0:l-1))) which mixes up DTFT and DFT definitions. The DTFT is defined as:
    $$X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]e^{-j\omega n}$$
    For a finite-length sequence $x[n]$ (from $n=0$ to $L-1$), this simplifies to summing over those indices with $\omega$ as the continuous frequency variable (not scaled by $2\pi k/L$, which is for DFT frequency bins).

  2. Incorrect Discrete Time Sequence Definition
    You created x = cos(n) where n = linspace(0,2*pi,1500)—this samples a continuous cosine over a $0$ to $2\pi$ interval, not a discrete-time sequence $x[n]$ where $n$ is an integer index. DTFT operates on discrete integer-indexed signals, so your input signal doesn't match the theoretical model you're comparing against.

  3. Unnormalized Summation Leading to Spurious Amplitude Growth
    Because you're summing $L$ terms without accounting for the DTFT's relationship to the continuous Fourier transform, the overall amplitude scales with $L$ for all frequency points—including the side lobes, which shouldn't grow with sequence length.

Fixed DTFT Implementation

Here's the corrected code that aligns with DTFT theory and matches your expected behavior (with finite-length sequence caveats):

% Define discrete-time sequence parameters
L = 1500;          % Length of the sequence
n = 0:L-1;         % Integer indices (discrete time)
omega0 = 1;        % Normalized angular frequency of the cosine
x = cos(omega0 * n); % Discrete-time cosine sequence

% Compute DTFT symbolically
syms w real
Xw = sum(x .* exp(-1i * w * n));
Xw_fun = matlabFunction(Xw);

% Evaluate DTFT over a frequency range
w_range = linspace(-5, 5, 1000);
X_vals = Xw_fun(w_range);

% Plot the magnitude of the DTFT
figure;
plot(w_range, abs(X_vals));
xlabel('Frequency \omega (radians/sample)');
ylabel('|X(e^{j\omega})|');
title('DTFT of Discrete-Time Cosine Sequence');
grid on;

What to Expect from the Fixed Code

  • As $L$ increases, the peak magnitude at $\omega = \pm 1$ will grow linearly with $L$ (this is correct for finite-length DTFT, as the sum of $L$ in-phase terms at the resonant frequency adds up).
  • The side lobe magnitudes will not grow with $L$—they'll stay at a fixed relative amplitude (~1.27 times the first side lobe peak compared to the main lobe's normalized height), which matches the sinc-function envelope of a finite-length cosine's DTFT.
  • To compare directly with the continuous-time Fourier transform (which has delta functions), you can normalize the DTFT by dividing by $L$: X_vals = Xw_fun(w_range)/L. This will make the peak approach $\pi$ as $L \to \infty$, aligning with the infinite-length discrete cosine's DTFT (which consists of scaled delta functions at $\omega = \pm 1, \pm 1 \pm 2\pi$, etc.).

Why Your Original Result Had Growing Side Lobes

Your input signal was a continuous cosine sampled over $0$ to $2\pi$, not a discrete-time cosine with integer indices. This meant the sequence didn't have the periodic discrete structure needed for the DTFT to exhibit the expected sinc envelope. Combined with the incorrect frequency scaling, this caused all frequency components to grow with sequence length.

内容的提问来源于stack exchange,提问作者omersk3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:56:05