FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
radar_signal.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 radar_signal.h
10 * @brief Classes for handling radar waveforms and signals.
11 */
12
13#pragma once
14
15#include <memory>
16#include <optional>
17#include <span>
18#include <string>
19#include <tuple>
20#include <vector>
21
22#include "core/config.h"
23#include "core/sim_id.h"
24
25namespace interp
26{
27 struct InterpPoint;
28}
29
30namespace fers_signal
31{
32 /**
33 * @class Signal
34 * @brief Class for handling radar waveform signal data.
35 */
36 class Signal
37 {
38 public:
39 virtual ~Signal() = default;
40
41 Signal() = default;
42
43 Signal(const Signal&) = delete;
44
45 Signal& operator=(const Signal&) = delete;
46
47 Signal(Signal&&) = default;
48
49 Signal& operator=(Signal&&) = default;
50
51 /**
52 * @brief Clears the internal signal data.
53 */
54 void clear() noexcept;
55
56 /**
57 * @brief Loads complex radar waveform data.
58 *
59 * @param inData The input span of complex signal data.
60 * @param samples The number of samples in the input data.
61 * @param sampleRate The sample rate of the input data.
62 */
63 void load(std::span<const ComplexType> inData, unsigned samples, RealType sampleRate);
64
65 /**
66 * @brief Gets the sample rate of the signal.
67 *
68 * @return The sample rate of the signal.
69 */
70 [[nodiscard]] RealType getRate() const noexcept { return _rate; }
71
72 /**
73 * @brief Renders the signal data based on interpolation points.
74 *
75 * @param points A vector of interpolation points used to render the signal.
76 * @param size Reference to store the size of the rendered data.
77 * @param fracWinDelay Fractional window delay to apply during rendering.
78 * @return A vector of rendered complex signal data.
79 */
80 virtual std::vector<ComplexType> render(const std::vector<interp::InterpPoint>& points, unsigned& size,
81 double fracWinDelay) const;
82
83 private:
84 std::vector<ComplexType> _data; ///< The complex signal data.
85 unsigned _size{0}; ///< The size of the signal data.
86 RealType _rate{0}; ///< The sample rate of the signal.
87
88 /**
89 * @brief Calculates weights and delays for rendering.
90 *
91 * @param iter Iterator pointing to the current interpolation point.
92 * @param next Iterator pointing to the next interpolation point.
93 * @param sampleTime Current sample time.
94 * @param idelay Integer delay value.
95 * @param fracWinDelay Fractional window delay to apply.
96 * @return A tuple containing amplitude, phase, fractional delay, and sample unwrap index.
97 */
98 [[nodiscard]] std::tuple<double, double, double, int>
99 calculateWeightsAndDelays(std::vector<interp::InterpPoint>::const_iterator iter,
100 std::vector<interp::InterpPoint>::const_iterator next, double sampleTime,
101 double idelay, double fracWinDelay) const noexcept;
102
103 /**
104 * @brief Performs convolution with a filter.
105 *
106 * @param i Index of the current sample.
107 * @param filt Pointer to the filter coefficients.
108 * @param filtLength Length of the filter.
109 * @param amplitude Amplitude scaling factor.
110 * @param iSampleUnwrap Unwrapped sample index for the convolution.
111 * @return The result of the convolution for the given sample.
112 */
113 ComplexType performConvolution(int i, const double* filt, int filtLength, double amplitude,
114 int iSampleUnwrap) const noexcept;
115 };
116
117 /**
118 * @class RadarSignal
119 * @brief Class representing a radar signal with associated properties.
120 */
122 {
123 public:
124 /**
125 * @brief Constructs a RadarSignal object.
126 *
127 * @param name The name of the radar signal.
128 * @param power The power of the radar signal.
129 * @param carrierfreq The carrier frequency of the radar signal.
130 * @param length The length of the radar signal.
131 * @param signal A unique pointer to the `Signal` object containing the waveform data.
132 * @throws std::runtime_error if the signal is null.
133 */
134 RadarSignal(std::string name, RealType power, RealType carrierfreq, RealType length,
135 std::unique_ptr<Signal> signal, const SimId id = 0);
136
137 ~RadarSignal() = default;
138
139 RadarSignal(const RadarSignal&) noexcept = delete;
140
141 RadarSignal& operator=(const RadarSignal&) noexcept = delete;
142
143 RadarSignal(RadarSignal&&) noexcept = delete;
144
145 RadarSignal& operator=(RadarSignal&&) noexcept = delete;
146
147 /**
148 * @brief Sets the filename associated with this signal.
149 * @param filename The source filename.
150 */
151 void setFilename(const std::string& filename) noexcept { _filename = filename; }
152
153 /**
154 * @brief Gets the filename associated with this signal.
155 * @return The source filename, if one was set.
156 */
157 [[nodiscard]] const std::optional<std::string>& getFilename() const noexcept { return _filename; }
158
159 /**
160 * @brief Gets the power of the radar signal.
161 *
162 * @return The power of the radar signal.
163 */
164 [[nodiscard]] RealType getPower() const noexcept { return _power; }
165
166 /**
167 * @brief Gets the carrier frequency of the radar signal.
168 *
169 * @return The carrier frequency of the radar signal.
170 */
171 [[nodiscard]] RealType getCarrier() const noexcept { return _carrierfreq; }
172
173 /**
174 * @brief Gets the name of the radar signal.
175 *
176 * @return The name of the radar signal.
177 */
178 [[nodiscard]] const std::string& getName() const noexcept { return _name; }
179
180 /**
181 * @brief Gets the unique ID of the radar signal.
182 *
183 * @return The radar signal SimId.
184 */
185 [[nodiscard]] SimId getId() const noexcept { return _id; }
186
187 /**
188 * @brief Gets the sample rate of the radar signal.
189 *
190 * @return The sample rate of the radar signal.
191 */
192 [[nodiscard]] RealType getRate() const noexcept { return _signal->getRate(); }
193
194 /**
195 * @brief Gets the length of the radar signal.
196 *
197 * @return The length of the radar signal.
198 */
199 [[nodiscard]] RealType getLength() const noexcept { return _length; }
200
201 /**
202 * @brief Gets the underlying signal object.
203 * @return A const pointer to the Signal object.
204 */
205 [[nodiscard]] const Signal* getSignal() const noexcept { return _signal.get(); }
206
207 /**
208 * @brief Renders the radar signal.
209 *
210 * @param points A vector of interpolation points.
211 * @param size Reference to store the size of the rendered data.
212 * @param fracWinDelay Fractional window delay to apply during rendering.
213 * @return A vector of rendered complex radar signal data.
214 */
215 std::vector<ComplexType> render(const std::vector<interp::InterpPoint>& points, unsigned& size,
216 RealType fracWinDelay) const;
217
218 private:
219 std::string _name; ///< The name of the radar signal.
220 SimId _id; ///< Unique ID for this radar signal.
221 RealType _power; ///< The power of the radar signal.
222 RealType _carrierfreq; ///< The carrier frequency of the radar signal.
223 RealType _length; ///< The length of the radar signal.
224 std::unique_ptr<Signal> _signal; ///< The `Signal` object containing the radar signal data.
225 std::optional<std::string> _filename; ///< The original filename for file-based signals.
226 };
227
228 class CwSignal final : public Signal
229 {
230 public:
231 CwSignal() = default;
232
233 ~CwSignal() override = default;
234
235 CwSignal(const CwSignal&) noexcept = delete;
236
237 CwSignal& operator=(const CwSignal&) noexcept = delete;
238
239 CwSignal(CwSignal&&) noexcept = delete;
240
241 CwSignal& operator=(CwSignal&&) noexcept = delete;
242
243 /**
244 * @brief Renders the signal data. For CW signals, this is a no-op.
245 * @return An empty vector of complex signal data.
246 */
247 std::vector<ComplexType> render(const std::vector<interp::InterpPoint>& points, unsigned& size,
248 RealType fracWinDelay) const override;
249 };
250}
~CwSignal() override=default
CwSignal(CwSignal &&) noexcept=delete
std::vector< ComplexType > render(const std::vector< interp::InterpPoint > &points, unsigned &size, RealType fracWinDelay) const override
Renders the signal data.
CwSignal(const CwSignal &) noexcept=delete
CwSignal & operator=(const CwSignal &) noexcept=delete
Class representing a radar signal with associated properties.
SimId getId() const noexcept
Gets the unique ID of the radar signal.
void setFilename(const std::string &filename) noexcept
Sets the filename associated with this signal.
RadarSignal(const RadarSignal &) noexcept=delete
RadarSignal & operator=(const RadarSignal &) noexcept=delete
const std::optional< std::string > & getFilename() const noexcept
Gets the filename associated with this signal.
RealType getRate() const noexcept
Gets the sample rate of the radar signal.
std::vector< ComplexType > render(const std::vector< interp::InterpPoint > &points, unsigned &size, RealType fracWinDelay) const
Renders the radar signal.
RadarSignal(RadarSignal &&) noexcept=delete
const std::string & getName() const noexcept
Gets the name of the radar signal.
RealType getCarrier() const noexcept
Gets the carrier frequency of the radar signal.
RealType getLength() const noexcept
Gets the length of the radar signal.
const Signal * getSignal() const noexcept
Gets the underlying signal object.
RealType getPower() const noexcept
Gets the power of the radar signal.
Class for handling radar waveform signal data.
RealType getRate() const noexcept
Gets the sample rate of the signal.
virtual ~Signal()=default
Signal(Signal &&)=default
void clear() noexcept
Clears the internal signal data.
Signal & operator=(const Signal &)=delete
Signal(const Signal &)=delete
void load(std::span< const ComplexType > inData, unsigned samples, RealType sampleRate)
Loads complex radar waveform data.
virtual std::vector< ComplexType > render(const std::vector< interp::InterpPoint > &points, unsigned &size, double fracWinDelay) const
Renders the signal data based on interpolation points.
Signal & operator=(Signal &&)=default
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
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18