Do delay bin to km conversion in JSON

This commit is contained in:
30hours 2023-11-17 10:32:32 +10:30
parent b77ac6b015
commit 56e92c09e9
5 changed files with 32 additions and 8 deletions

View file

@ -15,8 +15,8 @@ process:
ambiguity: ambiguity:
delayMin: -10 delayMin: -10
delayMax: 300 delayMax: 300
dopplerMin: -300 dopplerMin: -250
dopplerMax: 300 dopplerMax: 250
clutter: clutter:
delayMin: -10 delayMin: -10
delayMax: 300 delayMax: 300

View file

@ -206,6 +206,7 @@ int main(int argc, char **argv)
// output map data // output map data
map->set_metrics(); map->set_metrics();
mapJson = map->to_json(); mapJson = map->to_json();
mapJson = map->delay_bin_to_km(mapJson, fs);
if (saveMap) if (saveMap)
{ {
map->save(mapJson, saveMapPath); map->save(mapJson, saveMapPath);

View file

@ -121,7 +121,7 @@ std::string Map<T>::to_json()
rapidjson::Value arrayDelay(rapidjson::kArrayType); rapidjson::Value arrayDelay(rapidjson::kArrayType);
for (int i = 0; i < delay.size(); i++) for (int i = 0; i < delay.size(); i++)
{ {
arrayDelay.PushBack(delay_km[i], allocator); arrayDelay.PushBack(delay[i], allocator);
} }
// store Doppler array // store Doppler array
@ -141,7 +141,6 @@ std::string Map<T>::to_json()
document.AddMember("maxPower", maxPower, allocator); document.AddMember("maxPower", maxPower, allocator);
document.AddMember("delay", arrayDelay, allocator); document.AddMember("delay", arrayDelay, allocator);
document.AddMember("doppler", arrayDoppler, allocator); document.AddMember("doppler", arrayDoppler, allocator);
document.AddMember("timestamp", timestamp, allocator);
document.AddMember(rapidjson::Value("data", document.GetAllocator()).Move(), array, document.GetAllocator()); document.AddMember(rapidjson::Value("data", document.GetAllocator()).Move(), array, document.GetAllocator());
rapidjson::StringBuffer strbuf; rapidjson::StringBuffer strbuf;
@ -152,6 +151,28 @@ std::string Map<T>::to_json()
return strbuf.GetString(); return strbuf.GetString();
} }
template <class T>
std::string Map<T>::delay_bin_to_km(std::string json, uint32_t fs)
{
rapidjson::Document document;
document.SetObject();
rapidjson::Document::AllocatorType &allocator = document.GetAllocator();
document.Parse(json.c_str());
document["delay"].Clear();
for (int i = 0; i < delay.size(); i++)
{
document["delay"].PushBack(1.0*delay[i]*(299792458/(double)fs)/1000, allocator);
}
rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
writer.SetMaxDecimalPlaces(2);
document.Accept(writer);
return strbuf.GetString();
}
template <class T> template <class T>
void Map<T>::set_metrics() void Map<T>::set_metrics()
{ {

View file

@ -32,9 +32,6 @@ public:
/// @brief Delay units of map data (bins). /// @brief Delay units of map data (bins).
std::deque<int> delay; std::deque<int> delay;
/// @brief Delay units of map data (km).
std::deque<double> delay_km;
/// @brief Doppler units of map data (Hz). /// @brief Doppler units of map data (Hz).
std::deque<double> doppler; std::deque<double> doppler;
@ -97,6 +94,12 @@ public:
/// @return JSON string. /// @return JSON string.
std::string to_json(); std::string to_json();
/// @brief Update JSON to convert delay bins to km.
/// @param json Input JSON string with delay field.
/// @param fs Sampling frequency (Hz).
/// @return JSON string.
std::string delay_bin_to_km(std::string json, uint32_t fs);
/// @brief Append the map to a save file. /// @brief Append the map to a save file.
/// @param json JSON string of map and metadata. /// @param json JSON string of map and metadata.
/// @param path Path of file to save. /// @param path Path of file to save.

View file

@ -79,7 +79,6 @@ Ambiguity::Ambiguity(int32_t _delayMin, int32_t _delayMax, int32_t _dopplerMin,
for (int i = 0; i < nDelayBins; i++) for (int i = 0; i < nDelayBins; i++)
{ {
map->delay.push_back(delay[i]); map->delay.push_back(delay[i]);
map->delay_km.push_back(((double)delay[i] * (299792458/(double)fs)) / 1000);
} }
for (int i = 0; i < nDopplerBins; i++) for (int i = 0; i < nDopplerBins; i++)
{ {