sdr.mix(x: NDArray, freq: float = 0, phase: float = 0, sample_rate: float = 1, complex: bool = True) NDArray

Mixes the time-domain signal \(x[n]\) with a complex exponential or real sinusoid.

Parameters:
x: NDArray

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

freq: float = 0

The frequency \(f\) of the sinusoid in Hz (or 1/samples if sample_rate=1). The frequency must satisfy \(-f_s/2 \le f \le f_s/2\).

phase: float = 0

The phase \(\phi\) of the sinusoid in degrees.

sample_rate: float = 1

The sample rate \(f_s\) of the signal.

complex: bool = True

Indicates whether to mix by a complex exponential or real sinusoid.

  • True: \(y[n] = x[n] \cdot \exp \left[ j \left( \frac{2 \pi f}{f_s} n + \phi \right) \right]\)

  • False: \(y[n] = x[n] \cdot \cos \left( \frac{2 \pi f}{f_s} n + \phi \right)\)

Returns:

The mixed signal \(y[n]\).

Examples

Create a complex exponential with a frequency of 10 Hz and phase of 45 degrees.

In [1]: sample_rate = 1e3; \
   ...: N = 100; \
   ...: x = np.exp(1j * (2 * np.pi * 10 * np.arange(N) / sample_rate + np.pi/4))
   ...: 

In [2]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(x, sample_rate=sample_rate); \
   ...: plt.title(r"Complex exponential with $f=10$ Hz and $\phi=45$ degrees"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_mix_1.png

Mix the signal to baseband by removing the frequency rotation and the phase offset.

In [3]: y = sdr.mix(x, freq=-10, phase=-45, sample_rate=sample_rate)

In [4]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(y, sample_rate=sample_rate); \
   ...: plt.title(r"Baseband signal with $f=0$ Hz and $\phi=0$ degrees"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_mix_2.png