2022-06-29 10:25:32 +00:00
|
|
|
#pragma once
|
|
|
|
#include "lasp_siggen.h"
|
|
|
|
#include "lasp_types.h"
|
2022-09-22 19:02:41 +00:00
|
|
|
/**
|
|
|
|
* \addtogroup dsp
|
|
|
|
* @{
|
|
|
|
*/
|
2022-06-29 10:25:32 +00:00
|
|
|
|
2022-09-22 19:02:41 +00:00
|
|
|
/**
|
2024-03-04 14:49:29 +00:00
|
|
|
* \addtogroup siggen
|
2022-09-22 19:02:41 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Generate a random signal (noise)
|
|
|
|
*/
|
2022-06-29 10:25:32 +00:00
|
|
|
class Noise : public Siggen {
|
|
|
|
d level_linear;
|
|
|
|
virtual vd genSignalUnscaled(const us nframes) override;
|
|
|
|
void resetImpl() override;
|
|
|
|
|
2024-03-04 14:49:29 +00:00
|
|
|
public:
|
2022-06-29 10:25:32 +00:00
|
|
|
/**
|
|
|
|
* @brief Constructs a noise generator. If no filter is used, the output will
|
|
|
|
* be white noise. By default, the output will be standard deviation = 1
|
|
|
|
* noise, which clips the output for standard audio devices, so make sure the
|
|
|
|
* level is set properly.
|
|
|
|
*/
|
|
|
|
Noise();
|
|
|
|
~Noise() = default;
|
|
|
|
};
|
|
|
|
|
2022-09-22 19:02:41 +00:00
|
|
|
/**
|
|
|
|
* @brief Generate a sine wave
|
|
|
|
*/
|
2022-06-29 10:25:32 +00:00
|
|
|
class Sine : public Siggen {
|
|
|
|
d phase = 0;
|
|
|
|
d omg;
|
2022-09-22 19:02:41 +00:00
|
|
|
|
2024-03-04 14:49:29 +00:00
|
|
|
protected:
|
|
|
|
void resetImpl() override final { phase = 0; }
|
2022-09-22 19:02:41 +00:00
|
|
|
virtual vd genSignalUnscaled(const us nframes) override final;
|
2022-06-29 10:25:32 +00:00
|
|
|
|
2024-03-04 14:49:29 +00:00
|
|
|
public:
|
2022-06-29 10:25:32 +00:00
|
|
|
/**
|
|
|
|
* @brief Create a sine wave generator
|
|
|
|
*
|
2022-09-03 18:59:14 +00:00
|
|
|
* @param freq_Hz The frequency in Hz
|
2022-06-29 10:25:32 +00:00
|
|
|
*/
|
|
|
|
Sine(const d freq_Hz);
|
|
|
|
~Sine() = default;
|
2024-03-04 14:49:29 +00:00
|
|
|
void setFreq(const d newFreq) { omg = 2 * arma::datum::pi * newFreq; };
|
2022-06-29 10:25:32 +00:00
|
|
|
};
|
2022-09-22 19:02:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Base class for all periodic signals (that are exactly periodic based
|
|
|
|
* on the sampling frequency). Note that the sine wave generator is not exactly
|
|
|
|
* periodic as the frequency can be any floating point value.
|
|
|
|
*/
|
2022-06-29 10:25:32 +00:00
|
|
|
class Periodic: public Siggen {
|
|
|
|
protected:
|
|
|
|
vd _signal { 1, arma::fill::zeros};
|
|
|
|
us _cur_pos = 0;
|
|
|
|
public:
|
2022-10-21 21:12:47 +00:00
|
|
|
/**
|
|
|
|
* @brief Return copy of the generated sequence.
|
|
|
|
*
|
|
|
|
* @return As stated above
|
|
|
|
*/
|
|
|
|
vd getSequence() const { return _signal; }
|
2022-06-29 10:25:32 +00:00
|
|
|
|
2022-09-22 08:18:38 +00:00
|
|
|
virtual vd genSignalUnscaled(const us nframes) override final;
|
2022-06-29 10:25:32 +00:00
|
|
|
~Periodic() = default;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-09-22 19:02:41 +00:00
|
|
|
/**
|
|
|
|
* @brief Sweep signal
|
|
|
|
*/
|
2022-06-29 10:25:32 +00:00
|
|
|
class Sweep : public Periodic {
|
|
|
|
d fl_, fu_, Ts, Tq;
|
|
|
|
us index;
|
|
|
|
us flags;
|
|
|
|
|
2022-09-22 19:02:41 +00:00
|
|
|
void resetImpl() override;
|
|
|
|
|
2024-03-04 14:49:29 +00:00
|
|
|
public:
|
2022-06-29 10:25:32 +00:00
|
|
|
static constexpr int ForwardSweep = 1 << 0;
|
|
|
|
static constexpr int BackwardSweep = 1 << 1;
|
|
|
|
static constexpr int LinearSweep = 1 << 2;
|
|
|
|
static constexpr int LogSweep = 1 << 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a sweep signal
|
|
|
|
*
|
|
|
|
* @param[in] fl: Lower frequency [Hz]
|
|
|
|
* @param[in] fu: Upper frequency [Hz]
|
|
|
|
* @param[in] Ts: Sweep time [s]
|
|
|
|
* @param[in] Tq: Quescent tail time [s]. Choose this value long enough to
|
|
|
|
* avoid temporal aliasing in case of measuring impulse responses.
|
|
|
|
* @param[in] sweep_flags: Sweep period [s]
|
|
|
|
*/
|
2024-03-04 14:49:29 +00:00
|
|
|
Sweep(const d fl, const d fu, const d Ts, const d Tq, const us sweep_flags);
|
2022-06-29 10:25:32 +00:00
|
|
|
|
|
|
|
~Sweep() = default;
|
|
|
|
|
2024-03-04 14:49:29 +00:00
|
|
|
|
2022-06-29 10:25:32 +00:00
|
|
|
};
|
2022-09-22 19:02:41 +00:00
|
|
|
/** @} */
|
|
|
|
/** @} */
|