sdr.plot.dtft(x: ArrayLike, sample_rate: float | None = None, window: str | float | tuple | None = None, size: int = 1048576, centered: bool = True, ax: Axes | None = None, y_axis: 'complex' | 'mag' | 'mag^2' | 'db' = 'mag', diff: 'color' | 'line' = 'color', **kwargs)

Plots the discrete-time Fourier transform (DTFT) of the time-domain signal \(x[n]\).

Parameters:
x: ArrayLike

The time-domain signal \(x[n]\).

sample_rate: float | None = None

The sample rate \(f_s\) of the signal in samples/s. If None, the x-axis will be labeled as “Normalized frequency”.

window: str | float | tuple | None = None

The SciPy window definition. See scipy.signal.windows.get_window() for details. If None, no window is applied.

size: int = 1048576

The number of points to use for the DTFT. The actual size used will be the nearest power of 2.

centered: bool = True

Indicates whether to center the DTFT about 0.

ax: Axes | None = None

The axis to plot on. If None, the current axis is used.

y_axis: 'complex' | 'mag' | 'mag^2' | 'db' = 'mag'

The y-axis scaling.

diff: 'color' | 'line' = 'color'

Indicates how to differentiate the real and imaginary parts of a complex signal. If "color", the real and imaginary parts will have different colors based on the current Matplotlib color cycle. If "line", the real part will have a solid line and the imaginary part will have a dashed line, and both lines will share the same color.

**kwargs

Additional keyword arguments to pass to the plotting function.

See also

sdr.plot.dft

Notes

The discrete Fourier transform (DTFT) is defined as

\[X(f) = \sum_{n=-\infty}^{\infty} x[n] e^{-j 2 \pi f n / f_s},\]

where \(x[n]\) is the time-domain signal, \(X(f)\) is the DTFT, and \(f\) is the frequency.

Examples

Create a DC tone that is 10 samples long. Plot its DTFT. Notice that the width of the main lobe is \(2 / T\), with nulls at \(\pm 1 / T\).

In [1]: n = 10  # samples

In [2]: f = 0 / n  # cycles/sample

In [3]: x = np.exp(1j * 2 * np.pi * f * np.arange(n))

In [4]: plt.figure(); \
   ...: sdr.plot.dtft(x);
   ...: 
../../_images/sdr_plot_dtft_1.png

Plot a critically sampled DFT and an oversampled DFT of the signal. Notice that the DFT is a sampled version of the DTFT. The oversampled DFT has more samples and thus more closely resembles the DTFT.

In [5]: plt.figure(); \
   ...: sdr.plot.dtft(x, label="DTFT"); \
   ...: sdr.plot.dft(x, oversample=4, type="stem", label="4x oversampled DFT"); \
   ...: sdr.plot.dft(x, type="stem", label="DFT");
   ...: 
../../_images/sdr_plot_dtft_2.png