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:
parent
30992add71
commit
6eaf5db691
@ -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;
|
||||
|
||||
@ -26,7 +26,7 @@ vd Noise::genSignalUnscaled(us nframes) {
|
||||
}
|
||||
void Noise::resetImpl() {}
|
||||
|
||||
Sine::Sine(const d freq) : omg(2 * arma::datum::pi * freq) { DEBUGTRACE_ENTER;}
|
||||
Sine::Sine(const d freq) : omg(2 * arma::datum::pi * freq) { DEBUGTRACE_ENTER; }
|
||||
|
||||
vd Sine::genSignalUnscaled(const us nframes) {
|
||||
/* DEBUGTRACE_ENTER; */
|
||||
@ -43,10 +43,10 @@ vd Sine::genSignalUnscaled(const us nframes) {
|
||||
vd Periodic::genSignalUnscaled(const us nframes) {
|
||||
|
||||
vd res(nframes);
|
||||
if(_signal.size() == 0) {
|
||||
if (_signal.size() == 0) {
|
||||
throw rte("No signal defined while calling");
|
||||
}
|
||||
for(us i=0;i<nframes;i++) {
|
||||
for (us i = 0; i < nframes; i++) {
|
||||
res(i) = _signal[_cur_pos];
|
||||
_cur_pos++;
|
||||
_cur_pos %= _signal.size();
|
||||
@ -57,18 +57,21 @@ 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);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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,18 +27,23 @@ 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);
|
||||
|
||||
py::class_<Noise,std::shared_ptr<Noise>> noise(m, "Noise", siggen);
|
||||
py::class_<Noise, std::shared_ptr<Noise>> noise(m, "Noise", siggen);
|
||||
noise.def(py::init<>());
|
||||
|
||||
py::class_<Sine, std::shared_ptr<Sine>> sine(m, "Sine", siggen);
|
||||
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);
|
||||
|
||||
}
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user