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