add missing files

This commit is contained in:
AlexandreRouma
2026-03-10 16:51:32 -04:00
parent d42f0ca0bc
commit 6649370209
4 changed files with 367 additions and 0 deletions

107
dsp/mrate/fir_decim.cpp Normal file
View File

@@ -0,0 +1,107 @@
#include "fir_decim.h"
#include "../complex.h"
#include <string.h>
#include <volk/volk.h>
namespace dsp::mrate {
template <class SAMPLE, class TAP>
FIRDecim<SAMPLE, TAP>::FIRDecim() {}
template <class SAMPLE, class TAP>
FIRDecim<SAMPLE, TAP>::FIRDecim(const Taps<TAP>& taps, int decim) {
// Save the parameters
this->taps = taps;
this->decim = decim;
// Pre-allocate the history buffer
hist.reserve(taps.size());
// Initialize the state
reset();
}
template <class SAMPLE, class TAP>
FIRDecim<SAMPLE, TAP>::FIRDecim(Taps<TAP>&& taps, int decim) {
// Save the parameters
this->taps = taps;
this->decim = decim;
// Pre-allocate the history buffer
hist.reserve(taps.size());
// Initialize the state
reset();
}
template <class SAMPLE, class TAP>
const Taps<TAP>& FIRDecim<SAMPLE, TAP>::getTaps() const {
// Return the taps
return taps;
}
template <class SAMPLE, class TAP>
void FIRDecim<SAMPLE, TAP>::setTaps(const Taps<TAP>& taps, int decim) {
// Update the taps
this->taps = taps;
// Update the decimation factor if it was given
if (decim) { this->decim = decim; }
}
template <class SAMPLE, class TAP>
void FIRDecim<SAMPLE, TAP>::setTaps(Taps<TAP>&& taps, int decim) {
// Update the taps
this->taps = taps;
// Update the decimation factor if it was given
if (decim) { this->decim = decim; }
}
template <class SAMPLE, class TAP>
void FIRDecim<SAMPLE, TAP>::reset() {
// Zero out the history buffer
memset(hist.data(), 0, (taps.size() - 1) * sizeof(SAMPLE));
// Reset the offset
offset = 0;
}
template <class SAMPLE, class TAP>
size_t FIRDecim<SAMPLE, TAP>::process(const SAMPLE* in, SAMPLE* out, size_t count) {
// Reserve enough space in the history buffer
hist.reserve(taps.size() + count - 1, REALLOC_KEEP);
// Copy over the new input samples
memcpy(&hist[taps.size() - 1], in, count * sizeof(SAMPLE));
// Filter the samples
uintptr_t i;
uintptr_t io = 0;
for (i = offset; i < count; i += decim) {
// Compute the dot product depending on type
if constexpr (std::is_same_v<SAMPLE, float>) {
volk_32f_x2_dot_prod_32f(&out[io++], &hist[i], taps.data(), taps.size());
}
else if constexpr (std::is_same_v<SAMPLE, Complex> && std::is_same_v<TAP, float>) {
volk_32fc_32f_dot_prod_32fc((lv_32fc_t*)&out[io++], (const lv_32fc_t*)&hist[i], taps.data(), taps.size());
}
else if constexpr (std::is_same_v<SAMPLE, Complex> && std::is_same_v<TAP, Complex>) {
volk_32fc_x2_dot_prod_32fc((lv_32fc_t*)&out[io++], (const lv_32fc_t*)&hist[i], (const lv_32fc_t*)taps.data(), taps.size());
}
}
// Update the offset
offset = i - count;
// Move over the unused sample to the history buffer
memmove(hist.data(), &hist[count], (taps.size() - 1) * sizeof(SAMPLE));
// Return the number of samples generated
return io;
}
// Instantiate the class
template class FIRDecim<float, float>;
template class FIRDecim<Complex, float>;
template class FIRDecim<Complex, Complex>;
}

79
dsp/mrate/fir_decim.h Normal file
View File

@@ -0,0 +1,79 @@
#pragma once
#include "../processor.h"
#include "../buffer.h"
#include "../taps.h"
namespace dsp::mrate {
template <class SAMPLE, class TAP>
class FIRDecim {
public:
// Default constructor
FIRDecim();
/**
* Create a decimating FIR filter.
* @param taps Taps to use for the filter.
* @param decim Decimation factor.
*/
FIRDecim(const Taps<TAP>& taps, int decim);
/**
* Create a decimating FIR filter.
* @param taps Taps to use for the filter.
* @param decim Decimation factor.
*/
FIRDecim(Taps<TAP>&& taps, int decim);
/**
* Get the filter taps.
* @return Filter taps.
*/
const Taps<TAP>& getTaps() const;
/**
* Set the filter taps.
* @param taps Filter taps.
* @param decim Decimation factor. Zero to keep unchanged.
*/
void setTaps(const Taps<TAP>& taps, int decim = 0);
/**
* Set the filter taps.
* @param taps Filter taps.
* @param decim Decimation factor. Zero to keep unchanged.
*/
void setTaps(Taps<TAP>&& taps, int decim = 0);
/**
* Get the decimation factor.
* @return Decimation factor.
*/
int getDecimation();
/**
* Set the decimation factor.
* @param decim Decimation factor.
*/
void setDecimation(int decim);
/**
* Reset the state of the filter.
*/
void reset();
/**
* Filter and decimate samples.
* @param in Input samples.
* @param out Output samples.
* @param count Number of samples to filter.
* @return Number of samples generates.
*/
size_t process(const SAMPLE* in, SAMPLE* out, size_t count);
private:
Buffer<SAMPLE> hist;
uintptr_t offset = 0;
Taps<TAP> taps;
int decim = 0;
};
}

98
dsp/mrate/fir_interp.cpp Normal file
View File

@@ -0,0 +1,98 @@
#include "fir_interp.h"
#include "../complex.h"
#include <string.h>
#include <volk/volk.h>
namespace dsp::mrate {
template <class SAMPLE, class TAP>
FIRInterp<SAMPLE, TAP>::FIRInterp() {}
template <class SAMPLE, class TAP>
FIRInterp<SAMPLE, TAP>::FIRInterp(const Taps<TAP>& taps, int interp) {
// Save the parameters
this->taps = taps;
this->interp = interp;
// Pre-allocate the history buffer
hist.reserve(taps.size());
// Initialize the state
reset();
// Generate the tap phases
generatePhases();
}
template <class SAMPLE, class TAP>
FIRInterp<SAMPLE, TAP>::FIRInterp(Taps<TAP>&& taps, int interp) {
// Save the parameters
this->taps = taps;
this->interp = interp;
// Pre-allocate the history buffer
hist.reserve(taps.size());
// Initialize the state
reset();
// Generate the tap phases
generatePhases();
}
template <class SAMPLE, class TAP>
const Taps<TAP>& FIRInterp<SAMPLE, TAP>::getTaps() const {
// Return the taps
return taps;
}
template <class SAMPLE, class TAP>
void FIRInterp<SAMPLE, TAP>::setTaps(const Taps<TAP>& taps, int interp) {
// Update the taps
this->taps = taps;
// Update the interpolation factor if it was given
if (interp) { this->interp = interp; }
// Regenerate the tap phases
generatePhases();
}
template <class SAMPLE, class TAP>
void FIRInterp<SAMPLE, TAP>::setTaps(Taps<TAP>&& taps, int interp) {
// Update the taps
this->taps = taps;
// Update the interpolation factor if it was given
if (interp) { this->interp = interp; }
// Regenerate the tap phases
generatePhases();
}
template <class SAMPLE, class TAP>
void FIRInterp<SAMPLE, TAP>::reset() {
// Zero out the history buffer
memset(hist.data(), 0, (taps.size() - 1) * sizeof(SAMPLE));
// Reset the offset
offset = 0;
}
template <class SAMPLE, class TAP>
size_t FIRInterp<SAMPLE, TAP>::process(const SAMPLE* in, SAMPLE* out, size_t count) {
// TODO
// Return the number of samples generated
return 0;
}
template <class SAMPLE, class TAP>
void FIRInterp<SAMPLE, TAP>::generatePhases() {
// TODO
}
// Instantiate the class
template class FIRInterp<float, float>;
template class FIRInterp<Complex, float>;
template class FIRInterp<Complex, Complex>;
}

83
dsp/mrate/fir_interp.h Normal file
View File

@@ -0,0 +1,83 @@
#pragma once
#include "../processor.h"
#include "../buffer.h"
#include "../taps.h"
#include <vector>
namespace dsp::mrate {
template <class SAMPLE, class TAP>
class FIRInterp {
public:
// Default constructor
FIRInterp();
/**
* Create a decimating FIR filter.
* @param taps Taps to use for the filter.
* @param interp Interpolation factor.
*/
FIRInterp(const Taps<TAP>& taps, int interp);
/**
* Create a decimating FIR filter.
* @param taps Taps to use for the filter.
* @param interp Interpolation factor.
*/
FIRInterp(Taps<TAP>&& taps, int interp);
/**
* Get the filter taps.
* @return Filter taps.
*/
const Taps<TAP>& getTaps() const;
/**
* Set the filter taps.
* @param taps Filter taps.
* @param interp Interpolation factor. Zero to keep unchanged.
*/
void setTaps(const Taps<TAP>& taps, int interp = 0);
/**
* Set the filter taps.
* @param taps Filter taps.
* @param interp Interpolation factor. Zero to keep unchanged.
*/
void setTaps(Taps<TAP>&& taps, int interp = 0);
/**
* Get the interpolation factor.
* @return Interpolation factor.
*/
int getInterpolation();
/**
* Set the interpolation factor.
* @param interp Interpolation factor.
*/
void setInterpolation(int interp);
/**
* Reset the state of the filter.
*/
void reset();
/**
* Filter and decimate samples.
* @param in Input samples.
* @param out Output samples.
* @param count Number of samples to filter.
* @return Number of samples generates.
*/
size_t process(const SAMPLE* in, SAMPLE* out, size_t count);
private:
void generatePhases();
Buffer<SAMPLE> hist;
uintptr_t offset = 0;
Taps<TAP> taps;
std::vector<Buffer<TAP>> phases;
int interp = 0;
};
}