feat: add 7 analog signal models (constant, normal, linear, sine, uniform, spike, drift)

This commit is contained in:
Huamonarch 2026-05-13 15:10:37 +08:00
parent 6afce89326
commit afd753f803
7 changed files with 88 additions and 0 deletions

View 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; }
};

View 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; }
};

View 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; }
};

View 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); }
};

View 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; }
};

View 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;
}
};

View 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); }
};