added class to generate simulated iq data. Currently just generates random data.

This commit is contained in:
bennysomers 2024-02-02 22:40:39 +11:00
parent f3c71a79f2
commit 440d74bcbc
5 changed files with 156 additions and 35 deletions

View file

@ -43,6 +43,7 @@ add_executable(blah2
src/capture/Source.cpp
src/capture/rspduo/RspDuo.cpp
src/capture/usrp/Usrp.cpp
src/capture/iqsimulator/IqSimulator.cpp
src/process/ambiguity/Ambiguity.cpp
src/process/clutter/WienerHopf.cpp
src/process/detection/CfarDetector1D.cpp

View file

@ -4,9 +4,10 @@
#include <iostream>
#include <thread>
#include <httplib.h>
#include "iqsimulator/IqSimulator.h"
// constants
const std::string Capture::VALID_TYPE[2] = {"RspDuo", "Usrp"};
const std::string Capture::VALID_TYPE[3] = {"RspDuo", "Usrp", "IqSimulator"};
// constructor
Capture::Capture(std::string _type, uint32_t _fs, uint32_t _fc, std::string _path)
@ -26,7 +27,8 @@ void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config)
std::unique_ptr<Source> device = factory_source(type, config);
// capture status thread
std::thread t1([&]{
std::thread t1([&]
{
while (true)
{
httplib::Client cli("http://127.0.0.1:3000");
@ -46,8 +48,7 @@ void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config)
}
}
sleep(1);
}
});
} });
if (!replay)
{
@ -58,10 +59,9 @@ void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config)
{
device->replay(buffer1, buffer2, file, loop);
}
}
std::unique_ptr<Source> Capture::factory_source(const std::string& type, c4::yml::NodeRef config)
std::unique_ptr<Source> Capture::factory_source(const std::string &type, c4::yml::NodeRef config)
{
if (type == VALID_TYPE[0])
{
@ -88,6 +88,12 @@ std::unique_ptr<Source> Capture::factory_source(const std::string& type, c4::yml
return std::make_unique<Usrp>(type, fc, fs, path, &saveIq,
address, subdev, antenna, gain);
}
else if (type == VALID_TYPE[2])
{
uint32_t n, n_min;
n_min = 2000000;
return std::make_unique<IqSimulator>(type, fc, fs, path, &saveIq, n_min);
}
// Handle unknown type
std::cerr << "Error: Source type does not exist." << std::endl;
return nullptr;

View file

@ -19,7 +19,7 @@ class Capture
{
private:
/// @brief The valid capture devices.
static const std::string VALID_TYPE[2];
static const std::string VALID_TYPE[3];
/// @brief The capture device type.
std::string type;

View file

@ -0,0 +1,51 @@
#include "IqSimulator.h"
#include <string.h>
#include <iostream>
#include <vector>
#include <complex>
#include <random>
// constructor
IqSimulator::IqSimulator(std::string _type, uint32_t _fc, uint32_t _fs,
std::string _path, bool *_saveIq, uint32_t _n_min = 1000)
: Source(_type, _fc, _fs, _path, _saveIq)
{
n_min = _n_min;
}
void IqSimulator::start()
{
}
void IqSimulator::stop()
{
}
void IqSimulator::process(IqData *buffer1, IqData *buffer2)
{
while (true)
{
if (buffer1->get_length() < n_min)
{
// create a random number generator
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(-(2 ^ 14), 2 ^ 14);
buffer1->lock();
buffer2->lock();
for (int i = 0; i < 1000; i++)
{
buffer1->push_back({(double)dis(gen), (double)dis(gen)});
buffer2->push_back({(double)dis(gen), (double)dis(gen)});
}
buffer1->unlock();
buffer2->unlock();
}
}
}
void IqSimulator::replay(IqData *buffer1, IqData *buffer2, std::string file, bool loop)
{
}

View file

@ -0,0 +1,63 @@
/// @file IQSimulator.h
/// @class IQSimulator
/// @brief A class to generate simulated IQ data with false targets
/// @details
///
/// @author bennysomers
/// @todo Simulate a single false target
/// @todo Simulate false targets
/// @todo Simulate realistic target motion
/// @todo Simulate N channels, instead of just 2
#ifndef IQSIMULATOR_H
#define IQSIMULATOR_H
#include "capture/Source.h"
#include "data/IqData.h"
#include <stdint.h>
#include <string>
class IqSimulator : public Source
{
private:
/// @brief Number of samples to generate each loop.
/// @details This is the number of samples to generate each time the process method is called. It is also the threshold for the minimum number of samples left in the buffer before new samples will be generated.
uint32_t n_min;
public:
/// @brief Constructor.
/// @param type Type of source. = "IQSimulator"
/// @param fc Center frequency (Hz).
/// @param fs Sample rate (Hz).
/// @param path Path to save IQ data.
/// @param saveIq Pointer to boolean to save IQ data.
/// @param n Number of samples.
/// @return The object.
IqSimulator(std::string type, uint32_t fc, uint32_t fs, std::string path,
bool *saveIq, uint32_t n_min);
/// @brief Implement capture function on IQSimulator.
/// @param buffer1 Pointer to reference buffer.
/// @param buffer2 Pointer to surveillance buffer.
/// @return Void.
void process(IqData *buffer1, IqData *buffer2);
/// @brief Call methods to start capture.
/// @return Void.
void start();
/// @brief Call methods to gracefully stop capture.
/// @return Void.
void stop();
/// @brief Implement replay function on IQSimulator.
/// @param buffer1 Pointer to reference buffer.
/// @param buffer2 Pointer to surveillance buffer.
/// @param file Path to file to replay data from.
/// @param loop True if samples should loop at EOF.
/// @return Void.
void replay(IqData *buffer1, IqData *buffer2, std::string file, bool loop);
};
#endif