FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
signal_processor.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file signal_processor.h
10 * @brief Header for receiver-side signal processing and rendering.
11 *
12 * This file contains declarations for functions that perform digital signal
13 * processing on received radar signals. This includes rendering raw responses
14 * into time-domain I/Q samples, adding thermal noise, and simulating ADC quantization.
15 */
16
17#pragma once
18
19#include <cstdint>
20#include <memory>
21#include <random>
22#include <span>
23#include <vector>
24
25#include "core/config.h"
26
27namespace serial
28{
29 class Response;
30}
31
32namespace pool
33{
34 class ThreadPool;
35}
36
37namespace processing
38{
39 /// One complex Cartesian IQ sample scaled for VITA-style signed 16-bit transport.
41 {
42 std::int16_t i = 0;
43 std::int16_t q = 0;
44 };
45
46 /// Result of fixed-fullscale IQ scaling.
48 {
49 std::vector<FixedFullscaleIqSample> samples;
50 std::uint64_t clipped_sample_count = 0;
51 };
52
53 /**
54 * @brief Renders a time-window of I/Q data from a collection of raw radar responses.
55 *
56 * This function orchestrates the process of converting abstract `Response` objects
57 * into a concrete vector of complex I/Q samples for a specific time window.
58 * It handles the superposition of multiple signals arriving at the receiver
59 * during the window and can use a thread pool for parallel processing.
60 *
61 * @param window The output vector where the rendered I/Q samples will be added.
62 * @param length The duration of the time window in seconds.
63 * @param start The start time of the window in seconds.
64 * @param fracDelay A fractional sample delay to apply for fine-grained timing.
65 * @param responses A span of unique pointers to the `Response` objects to be rendered.
66 */
67 void renderWindow(std::vector<ComplexType>& window, RealType length, RealType start, RealType fracDelay,
68 std::span<const std::unique_ptr<serial::Response>> responses);
69
70 /**
71 * @brief Applies thermal (Johnson-Nyquist) noise to a window of I/Q samples.
72 *
73 * Simulates the addition of white Gaussian noise based on the receiver's noise
74 * temperature and the simulation bandwidth.
75 *
76 * @param window A span of I/Q data to which noise will be added.
77 * @param noiseTemperature The effective noise temperature in Kelvin.
78 * @param rngEngine A random number generator engine to use for noise generation.
79 */
80 void applyThermalNoise(std::span<ComplexType> window, RealType noiseTemperature, std::mt19937& rngEngine);
81
82 /// Applies circular complex thermal noise using a caller-specified complex-baseband sample rate.
84 std::mt19937& rngEngine, RealType sampleRateHz);
85
86 /**
87 * @brief Simulates ADC quantization and scales a window of complex I/Q samples.
88 *
89 * This function first finds the maximum absolute value in the I/Q data to determine
90 * the full-scale range. It then simulates the quantization process based on the
91 * configured number of ADC bits. If no quantization is specified (adc_bits=0), it
92 * normalizes the data to a maximum amplitude of 1.0.
93 *
94 * @param window The window of complex I/Q samples to quantize and scale.
95 * @return The full-scale value used for quantization/normalization.
96 */
97 RealType quantizeAndScaleWindow(std::span<ComplexType> window);
98
99 /**
100 * @brief Scales complex samples against a fixed full-scale to signed int16 IQ.
101 *
102 * This helper is intended for real-time receiver-output sinks, where scanning a
103 * complete future window to derive full-scale would change hardware-like behavior.
104 *
105 * @param samples Input complex samples in physical units.
106 * @param fullscale Positive fixed full-scale magnitude for both I and Q channels.
107 * @return Scaled int16 IQ samples and a count of complex samples that clipped on either channel.
108 * @throws std::invalid_argument when fullscale is not positive.
109 */
110 [[nodiscard]] FixedFullscaleScalingResult scaleToInt16FixedFullscale(std::span<const ComplexType> samples,
111 RealType fullscale);
112}
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
FixedFullscaleScalingResult scaleToInt16FixedFullscale(const std::span< const ComplexType > samples, const RealType fullscale)
Scales complex samples against a fixed full-scale to signed int16 IQ.
void applyThermalNoise(std::span< ComplexType > window, const RealType noiseTemperature, std::mt19937 &rngEngine)
Applies thermal (Johnson-Nyquist) noise to a window of I/Q samples.
void applyThermalNoiseAtSampleRate(std::span< ComplexType > window, const RealType noiseTemperature, std::mt19937 &rngEngine, const RealType sampleRateHz)
Applies circular complex thermal noise using a caller-specified complex-baseband sample rate.
RealType quantizeAndScaleWindow(std::span< ComplexType > window)
Simulates ADC quantization and scales a window of complex I/Q samples.
void renderWindow(std::vector< ComplexType > &window, const RealType length, const RealType start, const RealType fracDelay, const std::span< const std::unique_ptr< serial::Response > > responses)
Renders a time-window of I/Q data from a collection of raw radar responses.
math::Vec3 max
One complex Cartesian IQ sample scaled for VITA-style signed 16-bit transport.
Result of fixed-fullscale IQ scaling.
std::vector< FixedFullscaleIqSample > samples