feat: add 7 analog signal models (constant, normal, linear, sine, uniform, spike, drift)
This commit is contained in:
parent
6afce89326
commit
afd753f803
10
TestProject/RNG/model/ConstantModel.h
Normal file
10
TestProject/RNG/model/ConstantModel.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct ConstantModel : IModel {
|
||||
float c;
|
||||
ConstantModel(const json& params, float defaultVal) : c(defaultVal) {}
|
||||
float evaluate(size_t) override { return c; }
|
||||
};
|
||||
11
TestProject/RNG/model/DriftModel.h
Normal file
11
TestProject/RNG/model/DriftModel.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct DriftModel : IModel {
|
||||
float base, drift_rate;
|
||||
DriftModel(const json& params, float defaultVal)
|
||||
: base(defaultVal), drift_rate(params.value("drift_rate", 0.0f)) {}
|
||||
float evaluate(size_t t) override { return base + drift_rate * t; }
|
||||
};
|
||||
11
TestProject/RNG/model/LinearModel.h
Normal file
11
TestProject/RNG/model/LinearModel.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct LinearModel : IModel {
|
||||
float k, b;
|
||||
LinearModel(const json& params, float defaultVal)
|
||||
: k(params.value("k", 0.0f)), b(defaultVal) {}
|
||||
float evaluate(size_t t) override { return k * t + b; }
|
||||
};
|
||||
12
TestProject/RNG/model/NormalModel.h
Normal file
12
TestProject/RNG/model/NormalModel.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <TestProject/RNG/RandT.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct NormalModel : IModel {
|
||||
float mean, sigma;
|
||||
NormalModel(const json& params, float defaultVal)
|
||||
: mean(defaultVal), sigma(params.value("sigma", 0.01f)) {}
|
||||
float evaluate(size_t) override { return RandT::GuassRand(mean, sigma); }
|
||||
};
|
||||
13
TestProject/RNG/model/SineModel.h
Normal file
13
TestProject/RNG/model/SineModel.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <cmath>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct SineModel : IModel {
|
||||
float A, omega, phi, offset;
|
||||
SineModel(const json& params, float defaultVal)
|
||||
: A(params.value("A", 1.0f)), omega(params.value("omega", 1.0f)),
|
||||
phi(params.value("phi", 0.0f)), offset(defaultVal) {}
|
||||
float evaluate(size_t t) override { return A * sinf(omega * t + phi) + offset; }
|
||||
};
|
||||
19
TestProject/RNG/model/SpikeModel.h
Normal file
19
TestProject/RNG/model/SpikeModel.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <cstdlib>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct SpikeModel : IModel {
|
||||
float base, amplitude, probability;
|
||||
SpikeModel(const json& params, float defaultVal)
|
||||
: base(defaultVal)
|
||||
, amplitude(params.value("amplitude", 1.0f))
|
||||
, probability(params.value("probability", 0.01f)) {}
|
||||
float evaluate(size_t) override {
|
||||
if ((double)rand() / RAND_MAX < probability) {
|
||||
return base + ((rand() % 2) ? amplitude : -amplitude);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
};
|
||||
12
TestProject/RNG/model/UniformModel.h
Normal file
12
TestProject/RNG/model/UniformModel.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/model/IModel.h>
|
||||
#include <TestProject/RNG/RandT.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct UniformModel : IModel {
|
||||
float center, delta;
|
||||
UniformModel(const json& params, float defaultVal)
|
||||
: center(defaultVal), delta(params.value("delta", 0.01f)) {}
|
||||
float evaluate(size_t) override { return RandT::RandT(center - delta, center + delta); }
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user