mirror of
https://github.com/30hours/blah2.git
synced 2024-11-18 12:33:58 +00:00
added class to generate simulated iq data. Currently just generates random data.
This commit is contained in:
parent
f3c71a79f2
commit
440d74bcbc
5 changed files with 156 additions and 35 deletions
|
@ -43,6 +43,7 @@ add_executable(blah2
|
||||||
src/capture/Source.cpp
|
src/capture/Source.cpp
|
||||||
src/capture/rspduo/RspDuo.cpp
|
src/capture/rspduo/RspDuo.cpp
|
||||||
src/capture/usrp/Usrp.cpp
|
src/capture/usrp/Usrp.cpp
|
||||||
|
src/capture/iqsimulator/IqSimulator.cpp
|
||||||
src/process/ambiguity/Ambiguity.cpp
|
src/process/ambiguity/Ambiguity.cpp
|
||||||
src/process/clutter/WienerHopf.cpp
|
src/process/clutter/WienerHopf.cpp
|
||||||
src/process/detection/CfarDetector1D.cpp
|
src/process/detection/CfarDetector1D.cpp
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
|
#include "iqsimulator/IqSimulator.h"
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
const std::string Capture::VALID_TYPE[2] = {"RspDuo", "Usrp"};
|
const std::string Capture::VALID_TYPE[3] = {"RspDuo", "Usrp", "IqSimulator"};
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
Capture::Capture(std::string _type, uint32_t _fs, uint32_t _fc, std::string _path)
|
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);
|
std::unique_ptr<Source> device = factory_source(type, config);
|
||||||
|
|
||||||
// capture status thread
|
// capture status thread
|
||||||
std::thread t1([&]{
|
std::thread t1([&]
|
||||||
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
httplib::Client cli("http://127.0.0.1:3000");
|
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);
|
sleep(1);
|
||||||
}
|
} });
|
||||||
});
|
|
||||||
|
|
||||||
if (!replay)
|
if (!replay)
|
||||||
{
|
{
|
||||||
|
@ -58,39 +59,44 @@ void Capture::process(IqData *buffer1, IqData *buffer2, c4::yml::NodeRef config)
|
||||||
{
|
{
|
||||||
device->replay(buffer1, buffer2, file, loop);
|
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])
|
if (type == VALID_TYPE[0])
|
||||||
{
|
{
|
||||||
return std::make_unique<RspDuo>(type, fc, fs, path, &saveIq);
|
return std::make_unique<RspDuo>(type, fc, fs, path, &saveIq);
|
||||||
}
|
}
|
||||||
else if (type == VALID_TYPE[1])
|
else if (type == VALID_TYPE[1])
|
||||||
{
|
{
|
||||||
std::string address, subdev;
|
std::string address, subdev;
|
||||||
std::vector<std::string> antenna;
|
std::vector<std::string> antenna;
|
||||||
std::vector<double> gain;
|
std::vector<double> gain;
|
||||||
std::string _antenna;
|
std::string _antenna;
|
||||||
double _gain;
|
double _gain;
|
||||||
config["address"] >> address;
|
config["address"] >> address;
|
||||||
config["subdev"] >> subdev;
|
config["subdev"] >> subdev;
|
||||||
config["antenna"][0] >> _antenna;
|
config["antenna"][0] >> _antenna;
|
||||||
antenna.push_back(_antenna);
|
antenna.push_back(_antenna);
|
||||||
config["antenna"][1] >> _antenna;
|
config["antenna"][1] >> _antenna;
|
||||||
antenna.push_back(_antenna);
|
antenna.push_back(_antenna);
|
||||||
config["gain"][0] >> _gain;
|
config["gain"][0] >> _gain;
|
||||||
gain.push_back(_gain);
|
gain.push_back(_gain);
|
||||||
config["gain"][1] >> _gain;
|
config["gain"][1] >> _gain;
|
||||||
gain.push_back(_gain);
|
gain.push_back(_gain);
|
||||||
|
|
||||||
return std::make_unique<Usrp>(type, fc, fs, path, &saveIq,
|
return std::make_unique<Usrp>(type, fc, fs, path, &saveIq,
|
||||||
address, subdev, antenna, gain);
|
address, subdev, antenna, gain);
|
||||||
}
|
}
|
||||||
// Handle unknown type
|
else if (type == VALID_TYPE[2])
|
||||||
std::cerr << "Error: Source type does not exist." << std::endl;
|
{
|
||||||
return nullptr;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Capture::set_replay(bool _loop, std::string _file)
|
void Capture::set_replay(bool _loop, std::string _file)
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Capture
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/// @brief The valid capture devices.
|
/// @brief The valid capture devices.
|
||||||
static const std::string VALID_TYPE[2];
|
static const std::string VALID_TYPE[3];
|
||||||
|
|
||||||
/// @brief The capture device type.
|
/// @brief The capture device type.
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
51
src/capture/iqsimulator/IqSimulator.cpp
Normal file
51
src/capture/iqsimulator/IqSimulator.cpp
Normal 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)
|
||||||
|
{
|
||||||
|
}
|
63
src/capture/iqsimulator/IqSimulator.h
Normal file
63
src/capture/iqsimulator/IqSimulator.h
Normal 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
|
Loading…
Reference in a new issue