FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
channel_model.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 channel_model.h
10 * @brief Header for radar channel propagation and interaction models.
11 *
12 * This file contains the declarations for functions that model the radar channel,
13 * including direct and reflected signal path calculations, and
14 * power scaling according to the radar range equation. These functions form the
15 * core physics engine for determining the properties of a received signal based
16 * on the positions and velocities of transmitters, receivers, and targets.
17 */
18
19#pragma once
20
21#include <chrono>
22#include <cstdint>
23#include <exception>
24#include <memory>
25#include <span>
26#include <unordered_map>
27#include <vector>
28
29#include "core/config.h"
30#include "core/sim_id.h"
32#include "math/geometry_ops.h"
33
34namespace core
35{
36 class World;
37}
38namespace timing
39{
40 class Timing;
41}
42namespace radar
43{
44 class Receiver;
45
46 class Transmitter;
47
48 class Target;
49}
50
51namespace serial
52{
53 class Response;
54}
55
56namespace fers_signal
57{
58 class RadarSignal;
59}
60
61namespace simulation
62{
63 /// Sampled phase-noise buffer for one timing source.
65 {
66 RealType start_time{}; ///< First sample time in seconds.
67 RealType dt{}; ///< Time spacing between phase-noise samples in seconds.
68 std::vector<RealType> samples; ///< Phase-noise samples in radians.
69
70 /// Returns the interpolated phase-noise sample at the specified time.
71 [[nodiscard]] RealType sampleAt(RealType time) const noexcept;
72 };
73
74 /// Lookup table for CW phase noise across timing sources.
76 {
77 RealType start_time{}; ///< Lookup start time in seconds.
78 RealType end_time{}; ///< Lookup end time in seconds.
79 RealType dt{}; ///< Lookup sample spacing in seconds.
80 std::unordered_map<SimId, CwPhaseNoiseBuffer> buffers; ///< Per-timing-source phase-noise buffers.
81
82 /// Builds a phase-noise lookup for the requested timing sources and time range.
83 [[nodiscard]] static CwPhaseNoiseLookup build(std::span<const std::shared_ptr<timing::Timing>> timings,
85
86 /// Samples phase noise for one timing source at the specified time.
87 [[nodiscard]] RealType sample(const timing::Timing* timing, RealType time) const noexcept;
88
89 /// Computes receiver-minus-transmitter phase noise at two propagation times.
91 const timing::Timing* tx_timing, RealType tx_time) const noexcept;
92 };
93
94 /// Selects how timing phase noise is applied to streaming channel contributions.
95 enum class StreamingTimingPhaseMode : std::uint8_t
96 {
97 ReceiverRelative, ///< Existing raw streaming convention: transmitter phase minus receiver LO phase.
98 TransmitterOnly, ///< Incoming RF/baseband signal before receiver LO subtraction.
99 None ///< Ignore timing phase noise entirely.
100 };
101
102 /**
103 * @struct ReResults
104 * @brief Stores the intermediate results of a radar equation calculation for a single time point.
105 */
107 {
108 RealType power; /**< Power scaling factor (dimensionless, relative to transmitted power). */
109 RealType delay; /**< Signal propagation delay in seconds. */
110 RealType phase; /**< Phase shift in radians due to propagation delay. */
111 };
112
113 /**
114 * @class RangeError
115 * @brief Exception thrown when a range calculation fails, typically due to objects being too close.
116 */
117 class RangeError final : public std::exception
118 {
119 public:
120 /**
121 * @brief Provides the error message for the exception.
122 * @return A C-style string describing the error.
123 */
124 [[nodiscard]] const char* what() const noexcept override
125 {
126 return "Range error in radar equation calculations";
127 }
128 };
129
130 /**
131 * @brief Solves the bistatic radar equation for a reflected path (Tx -> Tgt -> Rx).
132 *
133 * This function calculates the signal properties (power, delay, phase)
134 * for a signal traveling from a transmitter, reflecting off a target, and arriving at a receiver.
135 * It accounts for antenna gains, target RCS, and propagation loss.
136 *
137 * @param trans Pointer to the transmitter.
138 * @param recv Pointer to the receiver.
139 * @param targ Pointer to the target.
140 * @param time The time at which the pulse is transmitted.
141 * @param wave Pointer to the transmitted radar signal.
142 * @param results Output struct to store the calculation results.
143 * @throws RangeError If the target is too close to the transmitter or receiver.
144 */
146 const std::chrono::duration<RealType>& time, const fers_signal::RadarSignal* wave, ReResults& results);
147
148 /**
149 * @brief Solves the radar equation for a direct path (Tx -> Rx).
150 *
151 * This function calculates the signal properties for a direct line-of-sight signal
152 * traveling from a transmitter to a receiver.
153 *
154 * @param trans Pointer to the transmitter.
155 * @param recv Pointer to the receiver.
156 * @param time The time at which the pulse is transmitted.
157 * @param wave Pointer to the transmitted radar signal.
158 * @param results Output struct to store the calculation results.
159 * @throws RangeError If the transmitter and receiver are too close.
160 */
162 const std::chrono::duration<RealType>& time, const fers_signal::RadarSignal* wave,
163 ReResults& results);
164
165 /**
166 * @brief Calculates the complex envelope contribution for a direct propagation path (Tx -> Rx) at a specific time.
167 * This function is used for Continuous Wave (CW) simulations.
168 *
169 * @param trans The transmitter.
170 * @param recv The receiver.
171 * @param timeK The current simulation time.
172 * @return The complex I/Q sample contribution for this path.
173 */
175 RealType timeK, const CwPhaseNoiseLookup* phase_noise_lookup = nullptr);
176
177 /**
178 * @brief Calculates a direct-path contribution from a cached streaming source.
179 *
180 * @param source Cached active streaming source to evaluate.
181 * @param recv Receiver observing the source.
182 * @param timeK Current receiver time in seconds.
183 * @param phase_noise_lookup Optional lookup for timing phase noise samples.
184 * @param chirp_tracker Optional caller-owned FMCW boundary tracker for this path.
185 * @param timing_phase_mode Selects how timing phase noise is applied.
186 * @return The complex I/Q sample contribution for this path.
187 */
190 const CwPhaseNoiseLookup* phase_noise_lookup = nullptr, core::FmcwChirpBoundaryTracker* chirp_tracker = nullptr,
192
193 /**
194 * @brief Evaluates a receive-time streaming waveform phase for receiver LO/dechirp references.
195 *
196 * @param source Cached active streaming source to evaluate.
197 * @param timeK Receiver time in seconds.
198 * @param chirp_tracker Optional caller-owned FMCW boundary tracker for this source.
199 * @param phase_out Receives the waveform phase in radians when evaluation succeeds.
200 * @return True when the source is active and a phase was produced.
201 */
205
206 /**
207 * @brief Calculates the complex envelope contribution for a reflected path (Tx -> Tgt -> Rx) at a specific time.
208 * This function is used for Continuous Wave (CW) simulations.
209 *
210 * @param trans The transmitter.
211 * @param recv The receiver.
212 * @param targ The target.
213 * @param timeK The current simulation time.
214 * @return The complex I/Q sample contribution for this path.
215 */
218 const CwPhaseNoiseLookup* phase_noise_lookup = nullptr);
219
220 /**
221 * @brief Calculates a reflected-path contribution from a cached streaming source.
222 *
223 * @param source Cached active streaming source to evaluate.
224 * @param recv Receiver observing the reflected signal.
225 * @param targ Reflecting target.
226 * @param timeK Current receiver time in seconds.
227 * @param phase_noise_lookup Optional lookup for timing phase noise samples.
228 * @param chirp_tracker Optional caller-owned FMCW boundary tracker for this path.
229 * @param timing_phase_mode Selects how timing phase noise is applied.
230 * @return The complex I/Q sample contribution for this reflected path.
231 */
234 RealType timeK, const CwPhaseNoiseLookup* phase_noise_lookup = nullptr,
237
238 /**
239 * @brief Creates a Response object by simulating a signal's interaction over its duration.
240 *
241 * This function iterates over the duration of a transmitted pulse, calling the
242 * appropriate channel model function (`solveRe` or `solveReDirect`) at discrete
243 * time steps to generate a series of `InterpPoint`s. These points capture the
244 * time-varying properties of the received signal and are collected into a `Response` object.
245 *
246 * @param trans Pointer to the transmitter.
247 * @param recv Pointer to the receiver.
248 * @param signal Pointer to the transmitted pulse signal.
249 * @param startTime The absolute simulation time when the pulse transmission starts.
250 * @param targ Optional pointer to a target. If null, a direct path is simulated.
251 * @return A unique pointer to the generated Response object.
252 * @throws RangeError If the channel model reports an invalid geometry.
253 * @throws std::runtime_error If the simulation parameters result in zero time steps.
254 */
255 std::unique_ptr<serial::Response> calculateResponse(const radar::Transmitter* trans, const radar::Receiver* recv,
256 const fers_signal::RadarSignal* signal, RealType startTime,
257 const radar::Target* targ = nullptr);
258
259 /**
260 * @enum LinkType
261 * @brief Categorizes the visual link for rendering.
262 */
263 enum class LinkType : std::uint8_t
264 {
265 Monostatic, ///< Combined Tx/Rx path
266 BistaticTxTgt, ///< Illuminator path
267 BistaticTgtRx, ///< Scattered path
268 DirectTxRx ///< Interference path
269 };
270
271 /**
272 * @enum LinkQuality
273 * @brief Describes the radiometric quality of the link.
274 */
275 enum class LinkQuality : std::uint8_t
276 {
277 Strong, ///< SNR > 0 dB
278 Weak ///< SNR < 0 dB (Geometric line of sight, but below noise floor)
279 };
280
281 /**
282 * @struct PreviewLink
283 * @brief A calculated link segment for 3D visualization.
284 */
286 {
287 LinkType type; ///< Visual link category.
288 LinkQuality quality; ///< Radiometric link quality.
289 std::string label; ///< Human-readable label for display.
290 double display_value{-999.0}; ///< Numeric value represented by label, in the label's unit.
291 SimId source_id; ///< SimId at the start of this specific link segment.
292 SimId dest_id; ///< SimId at the end of this specific link segment.
293 SimId origin_id; ///< Original transmitted-energy source SimId.
294 double rcs{-1.0}; ///< RCS in square meters, or -1.0 when not applicable.
295 double actual_power_dbm{-999.0}; ///< Received power in dBm with actual RCS, or sentinel when unavailable.
296 };
297
298 /**
299 * @brief Calculates all visual links for the current world state at a specific time.
300 *
301 * This function utilizes the core radar equation helpers to determine visibility,
302 * power levels, and SNR for all Tx/Rx/Target combinations. It is lightweight
303 * and does not update simulation state.
304 *
305 * @param world The simulation world containing radar components.
306 * @param time The time at which to calculate geometry.
307 * @return A vector of renderable links.
308 */
309 std::vector<PreviewLink> calculatePreviewLinks(const core::World& world, RealType time);
310}
The World class manages the simulator environment.
Definition world.h:39
Class representing a radar signal with associated properties.
Manages radar signal reception and response processing.
Definition receiver.h:47
Base class for radar targets.
Definition target.h:118
Represents a radar transmitter system.
Definition transmitter.h:34
Exception thrown when a range calculation fails, typically due to objects being too close.
const char * what() const noexcept override
Provides the error message for the exception.
Represents a timing source for simulation.
Definition timing.h:36
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
std::complex< RealType > ComplexType
Type for complex numbers.
Definition config.h:35
Classes and operations for 3D geometry.
ComplexType calculateStreamingDirectPathContribution(const core::ActiveStreamingSource &source, const Receiver *recv, const RealType timeK, const CwPhaseNoiseLookup *const phase_noise_lookup, core::FmcwChirpBoundaryTracker *const chirp_tracker, const StreamingTimingPhaseMode timing_phase_mode)
Calculates a direct-path contribution from a cached streaming source.
LinkType
Categorizes the visual link for rendering.
@ DirectTxRx
Interference path.
@ Monostatic
Combined Tx/Rx path.
@ BistaticTgtRx
Scattered path.
@ BistaticTxTgt
Illuminator path.
ComplexType calculateReflectedPathContribution(const Transmitter *trans, const Receiver *recv, const Target *targ, const RealType timeK, const CwPhaseNoiseLookup *const phase_noise_lookup)
Calculates the complex envelope contribution for a reflected path (Tx -> Tgt -> Rx) at a specific tim...
LinkQuality
Describes the radiometric quality of the link.
@ Weak
SNR < 0 dB (Geometric line of sight, but below noise floor)
void solveReDirect(const Transmitter *trans, const Receiver *recv, const std::chrono::duration< RealType > &time, const RadarSignal *wave, ReResults &results)
Solves the radar equation for a direct path (Tx -> Rx).
bool calculateStreamingReferencePhase(const core::ActiveStreamingSource &source, const RealType timeK, core::FmcwChirpBoundaryTracker *const chirp_tracker, RealType &phase_out)
Evaluates a receive-time streaming waveform phase for receiver LO/dechirp references.
StreamingTimingPhaseMode
Selects how timing phase noise is applied to streaming channel contributions.
@ TransmitterOnly
Incoming RF/baseband signal before receiver LO subtraction.
@ None
Ignore timing phase noise entirely.
@ ReceiverRelative
Existing raw streaming convention: transmitter phase minus receiver LO phase.
void solveRe(const Transmitter *trans, const Receiver *recv, const Target *targ, const std::chrono::duration< RealType > &time, const RadarSignal *wave, ReResults &results)
Solves the bistatic radar equation for a reflected path (Tx -> Tgt -> Rx).
ComplexType calculateStreamingReflectedPathContribution(const core::ActiveStreamingSource &source, const Receiver *recv, const Target *targ, const RealType timeK, const CwPhaseNoiseLookup *const phase_noise_lookup, core::FmcwChirpBoundaryTracker *const chirp_tracker, const StreamingTimingPhaseMode timing_phase_mode)
Calculates a reflected-path contribution from a cached streaming source.
ComplexType calculateDirectPathContribution(const Transmitter *trans, const Receiver *recv, const RealType timeK, const CwPhaseNoiseLookup *const phase_noise_lookup)
Calculates the complex envelope contribution for a direct propagation path (Tx -> Rx) at a specific t...
std::vector< PreviewLink > calculatePreviewLinks(const core::World &world, const RealType time)
Calculates all visual links for the current world state at a specific time.
std::unique_ptr< serial::Response > calculateResponse(const Transmitter *trans, const Receiver *recv, const RadarSignal *signal, const RealType startTime, const Target *targ)
Creates a Response object by simulating a signal's interaction over its duration.
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18
math::Vec3 max
Defines the global state for the event-driven simulation engine.
Cached description of an active streaming transmitter segment.
Tracks the current FMCW chirp boundary for a streaming path.
Sampled phase-noise buffer for one timing source.
RealType start_time
First sample time in seconds.
RealType sampleAt(RealType time) const noexcept
Returns the interpolated phase-noise sample at the specified time.
std::vector< RealType > samples
Phase-noise samples in radians.
RealType dt
Time spacing between phase-noise samples in seconds.
Lookup table for CW phase noise across timing sources.
static CwPhaseNoiseLookup build(std::span< const std::shared_ptr< timing::Timing > > timings, RealType start_time, RealType end_time)
Builds a phase-noise lookup for the requested timing sources and time range.
RealType dt
Lookup sample spacing in seconds.
RealType end_time
Lookup end time in seconds.
std::unordered_map< SimId, CwPhaseNoiseBuffer > buffers
Per-timing-source phase-noise buffers.
RealType start_time
Lookup start time in seconds.
RealType sample(const timing::Timing *timing, RealType time) const noexcept
Samples phase noise for one timing source at the specified time.
RealType phaseDifference(const timing::Timing *rx_timing, RealType rx_time, const timing::Timing *tx_timing, RealType tx_time) const noexcept
Computes receiver-minus-transmitter phase noise at two propagation times.
Stores the intermediate results of a radar equation calculation for a single time point.
RealType delay
Signal propagation delay in seconds.
RealType power
Power scaling factor (dimensionless, relative to transmitted power).
RealType phase
Phase shift in radians due to propagation delay.