sdr.sinusoid(duration: float, freq: float = 0.0, freq_rate: float = 0.0, phase: float = 0.0, sample_rate: float = 1.0, complex: bool = True) NDArray

Generates a complex exponential or real sinusoid.

Parameters:
duration: float

The duration of the signal in seconds (or samples if sample_rate=1).

freq: float = 0.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\).

freq_rate: float = 0.0

The frequency rate \(\frac{df}{dt}\) of the sinusoid in Hz/s (or 1/samples\(^2\) if sample_rate=1).

phase: float = 0.0

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

sample_rate: float = 1.0

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

complex: bool = True

Indicates whether to generate a complex exponential or real sinusoid.

  • True: \(\exp \left[ j \left( 2 \pi f t + \phi \right) \right]\)

  • False: \(\cos \left( 2 \pi f t + \phi \right)\)

Returns:

The sinusoid \(x[n]\).

Examples

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

In [1]: sample_rate = 1e3; \
   ...: N = 100; \
   ...: lo = sdr.sinusoid(N / sample_rate, freq=10, phase=45, sample_rate=sample_rate)
   ...: 

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

Create a real sinusoid with a frequency of 10 Hz and phase of 45 degrees.

In [3]: lo = sdr.sinusoid(N / sample_rate, freq=10, phase=45, sample_rate=sample_rate, complex=False)

In [4]: plt.figure(); \
   ...: sdr.plot.time_domain(lo, sample_rate=sample_rate); \
   ...: plt.title(r"Real sinusoid with $f=10$ Hz and $\phi=45$ degrees");
   ...: 
../../_images/sdr_sinusoid_2.png