Added possibility to get the periodic sequence to Python using the getSequence() method on class Periodic. Added a check that at least one of LogSweep or LinSweep should be activated.

This commit is contained in:
Anne de Jong 2022-10-21 23:12:47 +02:00
parent 30992add71
commit 6eaf5db691
3 changed files with 48 additions and 35 deletions

View File

@ -6,10 +6,10 @@
// Signal generators implementation
//////////////////////////////////////////////////////////////////////
/* #define DEBUGTRACE_ENABLED */
#include "debugtrace.hpp"
#include "lasp_siggen_impl.h"
#include "debugtrace.hpp"
#include "lasp_mathtypes.h"
#include <cassert>
using rte = std::runtime_error;
@ -57,17 +57,20 @@ vd Periodic::genSignalUnscaled(const us nframes) {
Sweep::Sweep(const d fl, const d fu, const d Ts, const d Tq, const us flags)
: fl_(fl), fu_(fu), Ts(Ts), Tq(Tq), flags(flags) {
if (fl <= 0 || fu < fl || Ts <= 0) {
throw std::runtime_error("Invalid sweep parameters");
throw rte("Invalid sweep parameters");
}
if ((flags & ForwardSweep) && (flags & BackwardSweep)) {
throw std::runtime_error(
throw rte(
"Both forward and backward sweep flag set. Please only set either one "
"or none for a continuous sweep");
}
if ((flags & LinearSweep) && (flags & LogSweep)) {
throw std::runtime_error(
throw rte(
"Both logsweep and linear sweep flag set. Please only set either one.");
}
if (!((flags & LinearSweep) || (flags & LogSweep))) {
throw rte("Either LinearSweep or LogSweep should be given as flag");
}
}
void Sweep::resetImpl() {
@ -224,7 +227,6 @@ void Sweep::resetImpl() {
/* Iterate! */
k -= E / dEdk;
}
DEBUGTRACE_PRINT(K);
@ -254,5 +256,10 @@ void Sweep::resetImpl() {
/* This should be a very small number!! */
DEBUGTRACE_PRINT(phase);
}
} // End of log sweep
else {
// Either log or linear sweep had to be given as flags.
assert(false);
}
}

View File

@ -64,6 +64,12 @@ class Periodic: public Siggen {
vd _signal { 1, arma::fill::zeros};
us _cur_pos = 0;
public:
/**
* @brief Return copy of the generated sequence.
*
* @return As stated above
*/
vd getSequence() const { return _signal; }
virtual vd genSignalUnscaled(const us nframes) override final;
~Periodic() = default;

View File

@ -1,10 +1,6 @@
#include "lasp_avpowerspectra.h"
#include "lasp_biquadbank.h"
#include "lasp_fft.h"
#include "lasp_siggen.h"
#include "arma_npy.h"
#include "lasp_siggen_impl.h"
#include "lasp_slm.h"
#include "lasp_window.h"
#include <iostream>
#include <pybind11/pybind11.h>
@ -31,7 +27,9 @@ void init_siggen(py::module &m) {
siggen.def("setDCOffset", &Siggen::setDCOffset);
siggen.def("setMute", &Siggen::setMute);
siggen.def("setLevel", &Siggen::setLevel);
siggen.def("setLevel", &Siggen::setLevel, py::arg("newLevel"), py::arg("dB") = true);
siggen.def("setLevel", &Siggen::setLevel, py::arg("newLevel"),
py::arg("dB") = true);
siggen.def("reset", &Siggen::reset);
siggen.def("setFilter", &Siggen::setFilter);
@ -42,7 +40,10 @@ void init_siggen(py::module &m) {
sine.def(py::init<const d>());
sine.def("setFreq", &Sine::setFreq);
py::class_<Periodic, std::shared_ptr<Periodic>> periodic(m, "Periodic", siggen);
py::class_<Periodic, std::shared_ptr<Periodic>> periodic(m, "Periodic",
siggen);
periodic.def("getSequence",
[](const Sweep &s) { return ColToNpy<d>(s.getSequence()); });
py::class_<Sweep, std::shared_ptr<Sweep>> sweep(m, "Sweep", periodic);
sweep.def(py::init<const d, const d, const d, const d, const us>());
@ -50,6 +51,5 @@ void init_siggen(py::module &m) {
sweep.def_readonly_static("BackwardSweep", &Sweep::BackwardSweep);
sweep.def_readonly_static("LinearSweep", &Sweep::LinearSweep);
sweep.def_readonly_static("LogSweep", &Sweep::LogSweep);
}
/** @} */