29 std::vector<ComplexType>
CwSignal::render(
const std::vector<interp::InterpPoint>& points,
unsigned& size,
37 std::unique_ptr<Signal> signal) :
38 _name(std::move(name)), _power(power), _carrierfreq(carrierfreq), _length(length), _signal(std::move(signal))
42 throw std::runtime_error(
"Signal is empty");
46 std::vector<ComplexType>
RadarSignal::render(
const std::vector<interp::InterpPoint>& points,
unsigned& size,
49 auto data = _signal->render(points, size, fracWinDelay);
50 const RealType scale = std::sqrt(_power);
52 std::ranges::for_each(data, [scale](
auto& value) { value *= scale; });
67 _data.resize(samples * ratio);
68 _size = samples * ratio;
69 _rate = sampleRate * ratio;
73 std::ranges::copy(inData, _data.begin());
81 std::vector<ComplexType>
Signal::render(
const std::vector<interp::InterpPoint>& points,
unsigned& size,
82 const double fracWinDelay)
const
84 auto out = std::vector<ComplexType>(_size);
87 const RealType timestep = 1.0 / _rate;
91 auto iter = points.begin();
92 auto next = points.size() > 1 ? std::next(iter) : iter;
93 const RealType idelay = std::round(_rate * iter->delay);
96 for (
int i = 0; i < static_cast<int>(_size); ++i)
98 if (sample_time > next->time && next != iter)
101 if (std::next(next) != points.end())
107 auto [amplitude, phase, fdelay, i_sample_unwrap] =
108 calculateWeightsAndDelays(iter, next, sample_time, idelay, fracWinDelay);
109 const auto& filt =
interp.getFilter(fdelay);
110 ComplexType accum = performConvolution(i, filt.data(), filt_length, amplitude, i_sample_unwrap);
111 out[i] = std::exp(
ComplexType(0.0, 1.0) * phase) * accum;
113 sample_time += timestep;
119 constexpr std::tuple<RealType, RealType, RealType, int>
120 Signal::calculateWeightsAndDelays(
const std::vector<interp::InterpPoint>::const_iterator iter,
121 const std::vector<interp::InterpPoint>::const_iterator next,
123 const RealType fracWinDelay)
const noexcept
125 const RealType bw = iter < next ? (sampleTime - iter->time) / (next->time - iter->time) : 0.0;
127 const RealType amplitude = std::lerp(std::sqrt(iter->power), std::sqrt(next->power), bw);
128 const RealType phase = std::lerp(iter->phase, next->phase, bw);
129 RealType fdelay = -(std::lerp(iter->delay, next->delay, bw) * _rate - idelay + fracWinDelay);
131 const int i_sample_unwrap =
static_cast<int>(std::floor(fdelay));
132 fdelay -= i_sample_unwrap;
134 return {amplitude, phase, fdelay, i_sample_unwrap};
137 ComplexType Signal::performConvolution(
const int i,
const RealType* filt,
const int filtLength,
138 const RealType amplitude,
const int iSampleUnwrap)
const noexcept
140 const int start = std::max(-filtLength / 2, -i);
141 const int end = std::min(filtLength / 2,
static_cast<int>(_size) - i);
145 for (
int j = start; j < end; ++j)
147 if (
const unsigned sample_idx = i + j + iSampleUnwrap;
148 sample_idx < _size && j + filtLength / 2 < filtLength)
150 accum += amplitude * _data[sample_idx] * filt[j + filtLength / 2];
std::vector< ComplexType > render(const std::vector< interp::InterpPoint > &points, unsigned &size, RealType fracWinDelay) const override
Renders the signal data.
RadarSignal(std::string name, RealType power, RealType carrierfreq, RealType length, std::unique_ptr< Signal > signal)
Constructs a RadarSignal object.
std::vector< ComplexType > render(const std::vector< interp::InterpPoint > &points, unsigned &size, RealType fracWinDelay) const
Renders the radar signal.
void clear() noexcept
Clears the internal signal data.
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.
static InterpFilter & getInstance() noexcept
Retrieves the singleton instance of the InterpFilter class.
double RealType
Type for real numbers.
std::complex< RealType > ComplexType
Type for complex numbers.
Header file for Digital Signal Processing (DSP) filters and upsampling/downsampling functionality.
Interpolation filter implementation using Kaiser windowing.
Defines a structure to store interpolation point data for signal processing.
void upsample(const std::span< const ComplexType > in, const unsigned size, std::span< ComplexType > out)
Upsamples a signal by a given ratio.
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
unsigned renderFilterLength() noexcept
Get the render filter length.
Defines the Parameters struct and provides methods for managing simulation parameters.
Classes for handling radar waveforms and signals.