sdr.downsample(x: NDArray, rate: int) NDArray

Downsamples the time-domain signal \(x[n]\) by the factor \(r\).

Warning

This function does not perform any anti-aliasing filtering. The downsampled signal \(y[n]\) will have spectral aliasing. For efficient polyphase decimation (with anti-aliasing filtering), see sdr.Decimator.

Parameters:
x: NDArray

The time-domain signal \(x[n]\) with sample rate \(f_s\).

rate: int

The downsampling factor \(r\).

Returns:

The downsampled signal \(y[n]\) with sample rate \(f_s / r\).

Examples

Downsample a complex exponential by a factor of 4.

In [1]: sample_rate = 400; \
   ...: x1 = np.exp(1j * 2 * np.pi * 0 / sample_rate * np.arange(200)); \
   ...: x2 = np.exp(1j * 2 * np.pi * 130 / sample_rate * np.arange(200)); \
   ...: x3 = np.exp(1j * 2 * np.pi * -140 / sample_rate * np.arange(200)); \
   ...: x = x1 + x2 + x3
   ...: 

In [2]: y = sdr.downsample(x, 4)

In [3]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(x, sample_rate=sample_rate); \
   ...: plt.title("Input signal $x[n]$"); \
   ...: plt.tight_layout();
   ...: 

In [4]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(y, sample_rate=sample_rate/4); \
   ...: plt.title("Downsampled signal $y[n]$"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_downsample_1.png ../../_images/sdr_downsample_2.png

The spectrum of \(x[n]\) has aliased. Any spectral content above the Nyquist frequency of \(f_s / 2\) will fold into the spectrum of \(y[n]\). The CW at 0 Hz remains at 0 Hz (unaliased). The CW at 130 Hz folds into 30 Hz. The CW at -140 Hz folds into -40 Hz.

In [5]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.periodogram(x, fft=2048, sample_rate=sample_rate); \
   ...: plt.xlim(-sample_rate/2, sample_rate/2); \
   ...: plt.title("Input signal $x[n]$"); \
   ...: plt.tight_layout();
   ...: 

In [6]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.periodogram(y, fft=2048, sample_rate=sample_rate/4); \
   ...: plt.xlim(-sample_rate/2, sample_rate/2); \
   ...: plt.title("Downsampled signal $y[n]$"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_downsample_3.png ../../_images/sdr_downsample_4.png