FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
fers_signal::FmcwTriangleSignal Class Referencefinal

FMCW symmetric triangular modulation signal implementation. More...

#include "radar_signal.h"

+ Inheritance diagram for fers_signal::FmcwTriangleSignal:
+ Collaboration diagram for fers_signal::FmcwTriangleSignal:

Public Member Functions

 FmcwTriangleSignal (RealType chirp_bandwidth, RealType chirp_duration, RealType start_frequency_offset=0.0, std::optional< std::size_t > triangle_count=std::nullopt)
 Constructs an FMCW triangular modulation signal.
 
 ~FmcwTriangleSignal () override=default
 
 FmcwTriangleSignal (const FmcwTriangleSignal &) noexcept=delete
 
FmcwTriangleSignaloperator= (const FmcwTriangleSignal &) noexcept=delete
 
 FmcwTriangleSignal (FmcwTriangleSignal &&) noexcept=delete
 
FmcwTriangleSignaloperator= (FmcwTriangleSignal &&) noexcept=delete
 
RealType getChirpBandwidth () const noexcept
 Gets the chirp bandwidth in hertz.
 
RealType getChirpDuration () const noexcept
 Gets the per-leg chirp duration in seconds.
 
RealType getStartFrequencyOffset () const noexcept
 Gets the start frequency offset relative to carrier in hertz.
 
const std::optional< std::size_t > & getTriangleCount () const noexcept
 Gets the optional finite triangle count.
 
RealType getChirpRate () const noexcept
 Gets the chirp rate magnitude in hertz per second.
 
RealType getTrianglePeriod () const noexcept
 Gets the full up/down triangle period in seconds.
 
RealType getDeltaPhiUp () const noexcept
 Gets the full, unreduced phase accumulated by one leg.
 
bool isTriangle () const noexcept
 Returns true for triangular FMCW waveforms.
 
RealType basebandPhaseForTriangleTime (RealType triangle_time) const noexcept
 Computes baseband phase at a time since the triangle train start.
 
std::optional< RealTypeinstantaneousBasebandPhase (RealType time_since_segment_start) const noexcept
 Computes instantaneous baseband phase at a time since segment start.
 
std::vector< ComplexTyperender (const std::vector< interp::InterpPoint > &points, unsigned &size, RealType fracWinDelay) const override
 Renders an FMCW waveform from interpolation points.
 
bool isFmcwFamily () const noexcept override
 Returns true when this signal belongs to the FMCW waveform family.
 
void clear () noexcept
 Clears the internal signal data.
 
void load (std::span< const ComplexType > inData, unsigned samples, RealType sampleRate)
 Loads complex radar waveform data.
 
RealType getRate () const noexcept
 Gets the sample rate of the signal.
 
unsigned getSampleCount () const noexcept
 Gets the number of native samples held by this signal.
 
virtual std::vector< ComplexTyperenderSlice (const std::vector< interp::InterpPoint > &points, RealType outputStartTime, RealType outputSampleRate, std::size_t sampleCount, RealType fracWinDelay) const
 Renders a bounded absolute-time slice on the requested output grid.
 
ComplexType sampleAt (RealType time_since_start) const noexcept
 Samples the finite stored complex envelope using the render interpolation filter.
 

Detailed Description

FMCW symmetric triangular modulation signal implementation.

Definition at line 518 of file radar_signal.h.

Constructor & Destructor Documentation

◆ FmcwTriangleSignal() [1/3]

fers_signal::FmcwTriangleSignal::FmcwTriangleSignal ( RealType  chirp_bandwidth,
RealType  chirp_duration,
RealType  start_frequency_offset = 0.0,
std::optional< std::size_t >  triangle_count = std::nullopt 
)

Constructs an FMCW triangular modulation signal.

Definition at line 205 of file radar_signal.cpp.

207 :
208 _chirp_bandwidth(chirp_bandwidth), _chirp_duration(chirp_duration),
209 _start_frequency_offset(start_frequency_offset), _triangle_count(triangle_count),
210 _chirp_rate(chirp_bandwidth / chirp_duration), _triangle_period(2.0 * chirp_duration),
211 _delta_phi_up(2.0 * PI * start_frequency_offset * chirp_duration +
212 PI * _chirp_rate * chirp_duration * chirp_duration)
213 {
214 }
constexpr RealType PI
Mathematical constant π (pi).
Definition config.h:43

◆ ~FmcwTriangleSignal()

fers_signal::FmcwTriangleSignal::~FmcwTriangleSignal ( )
overridedefault

◆ FmcwTriangleSignal() [2/3]

fers_signal::FmcwTriangleSignal::FmcwTriangleSignal ( const FmcwTriangleSignal )
deletenoexcept

◆ FmcwTriangleSignal() [3/3]

fers_signal::FmcwTriangleSignal::FmcwTriangleSignal ( FmcwTriangleSignal &&  )
deletenoexcept

Member Function Documentation

◆ basebandPhaseForTriangleTime()

RealType fers_signal::FmcwTriangleSignal::basebandPhaseForTriangleTime ( RealType  triangle_time) const
noexcept

Computes baseband phase at a time since the triangle train start.

Definition at line 216 of file radar_signal.cpp.

217 {
218 if (triangle_time <= 0.0)
219 {
220 return 0.0;
221 }
222
223 const auto triangle_index = static_cast<std::size_t>(std::floor(triangle_time / _triangle_period));
224 const RealType local_triangle_time = triangle_time - static_cast<RealType>(triangle_index) * _triangle_period;
225 const bool down_leg = local_triangle_time >= _chirp_duration;
226 const RealType u = down_leg ? local_triangle_time - _chirp_duration : local_triangle_time;
227 const RealType phi_base =
228 static_cast<RealType>(triangle_index) * 2.0 * _delta_phi_up + (down_leg ? _delta_phi_up : 0.0);
229 if (!down_leg)
230 {
231 return phi_base + 2.0 * PI * _start_frequency_offset * u + PI * _chirp_rate * u * u;
232 }
233 return phi_base + 2.0 * PI * (_start_frequency_offset + _chirp_bandwidth) * u - PI * _chirp_rate * u * u;
234 }
double RealType
Type for real numbers.
Definition config.h:27
math::Vec3 max

References max, and PI.

◆ clear()

void fers_signal::Signal::clear ( )
noexceptinherited

Clears the internal signal data.

Definition at line 347 of file radar_signal.cpp.

348 {
349 _size = 0;
350 _rate = 0;
351 }

Referenced by fers_signal::Signal::load().

+ Here is the caller graph for this function:

◆ getChirpBandwidth()

RealType fers_signal::FmcwTriangleSignal::getChirpBandwidth ( ) const
noexcept

Gets the chirp bandwidth in hertz.

Definition at line 536 of file radar_signal.h.

536{ return _chirp_bandwidth; }

◆ getChirpDuration()

RealType fers_signal::FmcwTriangleSignal::getChirpDuration ( ) const
noexcept

Gets the per-leg chirp duration in seconds.

Definition at line 539 of file radar_signal.h.

539{ return _chirp_duration; }

◆ getChirpRate()

RealType fers_signal::FmcwTriangleSignal::getChirpRate ( ) const
noexcept

Gets the chirp rate magnitude in hertz per second.

Definition at line 548 of file radar_signal.h.

548{ return _chirp_rate; }

◆ getDeltaPhiUp()

RealType fers_signal::FmcwTriangleSignal::getDeltaPhiUp ( ) const
noexcept

Gets the full, unreduced phase accumulated by one leg.

Definition at line 554 of file radar_signal.h.

554{ return _delta_phi_up; }

◆ getRate()

RealType fers_signal::Signal::getRate ( ) const
noexceptinherited

Gets the sample rate of the signal.

Returns
The sample rate of the signal.

Definition at line 94 of file radar_signal.h.

94{ return _rate; }

◆ getSampleCount()

unsigned fers_signal::Signal::getSampleCount ( ) const
noexceptinherited

Gets the number of native samples held by this signal.

Definition at line 97 of file radar_signal.h.

97{ return _size; }

◆ getStartFrequencyOffset()

RealType fers_signal::FmcwTriangleSignal::getStartFrequencyOffset ( ) const
noexcept

Gets the start frequency offset relative to carrier in hertz.

Definition at line 542 of file radar_signal.h.

542{ return _start_frequency_offset; }

◆ getTriangleCount()

const std::optional< std::size_t > & fers_signal::FmcwTriangleSignal::getTriangleCount ( ) const
noexcept

Gets the optional finite triangle count.

Definition at line 545 of file radar_signal.h.

545{ return _triangle_count; }

◆ getTrianglePeriod()

RealType fers_signal::FmcwTriangleSignal::getTrianglePeriod ( ) const
noexcept

Gets the full up/down triangle period in seconds.

Definition at line 551 of file radar_signal.h.

551{ return _triangle_period; }

◆ instantaneousBasebandPhase()

std::optional< RealType > fers_signal::FmcwTriangleSignal::instantaneousBasebandPhase ( RealType  time_since_segment_start) const
noexcept

Computes instantaneous baseband phase at a time since segment start.

Definition at line 237 of file radar_signal.cpp.

238 {
239 if (time_since_segment_start < 0.0)
240 {
241 return std::nullopt;
242 }
243
244 const auto triangle_index = static_cast<std::size_t>(std::floor(time_since_segment_start / _triangle_period));
245 if (_triangle_count.has_value() && triangle_index >= *_triangle_count)
246 {
247 return std::nullopt;
248 }
249
251 time_since_segment_start - static_cast<RealType>(triangle_index) * _triangle_period;
253 {
254 return std::nullopt;
255 }
257 }
RealType basebandPhaseForTriangleTime(RealType triangle_time) const noexcept
Computes baseband phase at a time since the triangle train start.

References max.

◆ isFmcwFamily()

bool fers_signal::FmcwTriangleSignal::isFmcwFamily ( ) const
overridevirtualnoexcept

Returns true when this signal belongs to the FMCW waveform family.

Reimplemented from fers_signal::Signal.

Definition at line 570 of file radar_signal.h.

570{ return true; }

◆ isTriangle()

bool fers_signal::FmcwTriangleSignal::isTriangle ( ) const
noexcept

Returns true for triangular FMCW waveforms.

Definition at line 557 of file radar_signal.h.

557{ return true; }

◆ load()

void fers_signal::Signal::load ( std::span< const ComplexType inData,
unsigned  samples,
RealType  sampleRate 
)
inherited

Loads complex radar waveform data.

Parameters
inDataThe input span of complex signal data.
samplesThe number of samples in the input data.
sampleRateThe sample rate of the input data.

Definition at line 353 of file radar_signal.cpp.

354 {
355 clear();
356 const unsigned ratio = params::oversampleRatio();
357 const auto oversampled_samples = static_cast<std::size_t>(samples) * static_cast<std::size_t>(ratio);
358 if (oversampled_samples > std::numeric_limits<unsigned>::max())
359 {
360 throw std::overflow_error("Oversampled signal sample count exceeds unsigned range");
361 }
362 _data.resize(oversampled_samples);
363 _size = static_cast<unsigned>(oversampled_samples);
364 _rate = sampleRate * static_cast<RealType>(ratio);
365
366 if (ratio == 1)
367 {
368 std::ranges::copy(inData, _data.begin());
369 }
370 else
371 {
372 upsample(inData, samples, _data);
373 }
374 }
void clear() noexcept
Clears the internal signal data.
void upsample(const std::span< const ComplexType > in, const unsigned size, std::span< ComplexType > out)
Upsamples a complex waveform with zero-stuffing followed by Blackman FIR filtering.
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
Definition parameters.h:151

References fers_signal::Signal::clear(), max, params::oversampleRatio(), and fers_signal::upsample().

+ Here is the call graph for this function:

◆ operator=() [1/2]

FmcwTriangleSignal & fers_signal::FmcwTriangleSignal::operator= ( const FmcwTriangleSignal )
deletenoexcept

◆ operator=() [2/2]

FmcwTriangleSignal & fers_signal::FmcwTriangleSignal::operator= ( FmcwTriangleSignal &&  )
deletenoexcept

◆ render()

std::vector< ComplexType > fers_signal::FmcwTriangleSignal::render ( const std::vector< interp::InterpPoint > &  points,
unsigned size,
RealType  fracWinDelay 
) const
overridevirtual

Renders an FMCW waveform from interpolation points.

Reimplemented from fers_signal::Signal.

Definition at line 259 of file radar_signal.cpp.

261 {
262 size = 0;
263 return {};
264 }

References max.

◆ renderSlice()

std::vector< ComplexType > fers_signal::Signal::renderSlice ( const std::vector< interp::InterpPoint > &  points,
RealType  outputStartTime,
RealType  outputSampleRate,
std::size_t  sampleCount,
RealType  fracWinDelay 
) const
virtualinherited

Renders a bounded absolute-time slice on the requested output grid.

Definition at line 413 of file radar_signal.cpp.

416 {
417 auto out = std::vector<ComplexType>(sampleCount);
418 if (_size == 0 || _rate <= 0.0 || outputSampleRate <= 0.0 || points.empty())
419 {
420 return out;
421 }
422
423 const RealType timestep = 1.0 / outputSampleRate;
424 const int filt_length = static_cast<int>(params::renderFilterLength());
426
427 auto iter = points.begin();
428 auto next = points.size() > 1 ? std::next(iter) : iter;
429 const RealType idelay = std::round(_rate * iter->delay);
431
432 for (std::size_t i = 0; i < sampleCount; ++i)
433 {
434 while (sample_time > next->time && next != iter)
435 {
436 iter = next;
437 if (std::next(next) != points.end())
438 {
439 ++next;
440 }
441 else
442 {
443 break;
444 }
445 }
446
447 auto [amplitude, phase, fdelay, i_sample_unwrap] =
448 calculateWeightsAndDelays(iter, next, sample_time, idelay, fracWinDelay);
449 const RealType native_position = (sample_time - points.front().time) * _rate;
450 const auto source_index = static_cast<int>(std::floor(native_position));
453 {
454 source_fraction = 0.0;
455 }
456
458 const auto delay_unwrap = static_cast<int>(std::floor(combined_delay));
459 fdelay = combined_delay - static_cast<RealType>(delay_unwrap);
461
462 const auto& filt = interp.getFilter(fdelay);
463 const ComplexType accum =
464 performConvolution(source_index, filt.data(), filt_length, amplitude, i_sample_unwrap);
465 out[i] = std::exp(ComplexType(0.0, 1.0) * phase) * accum;
466
468 }
469
470 return out;
471 }
static InterpFilter & getInstance() noexcept
Retrieves the singleton instance of the InterpFilter class.
std::complex< RealType > ComplexType
Type for complex numbers.
Definition config.h:35
unsigned renderFilterLength() noexcept
Get the render filter length.
Definition parameters.h:139

References interp::InterpFilter::getInstance(), max, and params::renderFilterLength().

Referenced by fers_signal::Signal::render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sampleAt()

ComplexType fers_signal::Signal::sampleAt ( RealType  time_since_start) const
noexceptinherited

Samples the finite stored complex envelope using the render interpolation filter.

Times outside [0, duration) return zero; file-backed signals never wrap implicitly.

Definition at line 376 of file radar_signal.cpp.

377 {
378 if (_data.empty() || _rate <= 0.0 || !std::isfinite(time_since_start) || time_since_start < 0.0 ||
379 time_since_start >= static_cast<RealType>(_size) / _rate)
380 {
381 return {0.0, 0.0};
382 }
383
384 const RealType position = time_since_start * _rate;
385 const auto center = static_cast<long long>(std::floor(position));
386 const RealType fraction = position - std::floor(position);
388 const auto filter_length = static_cast<long long>(filter.size());
389 const auto sample_count = static_cast<long long>(_data.size());
390 ComplexType value{0.0, 0.0};
391 for (long long tap = 0; tap < filter_length; ++tap)
392 {
393 const long long sample_index = center + tap - filter_length / 2;
394 if (sample_index >= 0 && sample_index < sample_count)
395 {
396 value += _data[static_cast<std::size_t>(sample_index)] * filter[static_cast<std::size_t>(tap)];
397 }
398 }
399 return value;
400 }
Vec3 position
std::span< const RealType > getFilter(RealType delay) const
Retrieves a span of precomputed filter values for a given delay.

References interp::InterpFilter::getFilter(), interp::InterpFilter::getInstance(), max, and position.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: