mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2026-04-19 23:02:43 +00:00
even more stuff
This commit is contained in:
23
core/src/dsp/taps/band_pass.h
Normal file
23
core/src/dsp/taps/band_pass.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
#include "windowed_sinc.h"
|
||||
#include "estimate_tap_count.h"
|
||||
#include "../window/nuttall.h"
|
||||
#include "../math/phasor.h"
|
||||
#include "../math/freq_to_omega.h"
|
||||
|
||||
namespace dsp::taps {
|
||||
template<class T>
|
||||
inline tap<T> bandPass(double bandStart, double bandStop, double transWidth, double sampleRate) {
|
||||
assert(bandStop > bandStart);
|
||||
float offsetOmega = math::freqToOmega((bandStart + bandStop) / 2.0, sampleRate);
|
||||
return windowedSinc<T>(estimateTapCount(transWidth, sampleRate), (bandStop - bandStart) / 2.0, sampleRate, [=](double n, double N) {
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
return cosf(offsetOmega * (float)n) * window::nuttall(n, N);
|
||||
}
|
||||
if constexpr (std::is_same_v<T, complex_t>) {
|
||||
return math::phasor(offsetOmega * (float)n) * window::nuttall(n, N);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
7
core/src/dsp/taps/estimate_tap_count.h
Normal file
7
core/src/dsp/taps/estimate_tap_count.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace dsp::taps {
|
||||
inline int estimateTapCount(double transWidth, double samplerate) {
|
||||
return 3.8 * samplerate / transWidth;
|
||||
}
|
||||
}
|
||||
18
core/src/dsp/taps/from_array.h
Normal file
18
core/src/dsp/taps/from_array.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "tap.h"
|
||||
#include "../math/sinc.h"
|
||||
#include "../math/freq_to_omega.h"
|
||||
#include "../window/nuttall.h"
|
||||
|
||||
namespace dsp::taps {
|
||||
template<class T>
|
||||
inline tap<T> fromArray(int count, const T* taps) {
|
||||
// Allocate taps
|
||||
tap<T> _taps = taps::alloc<T>(count);
|
||||
|
||||
// Copy data
|
||||
memcpy(_taps.taps, taps, count * sizeof(T));
|
||||
|
||||
return _taps;
|
||||
}
|
||||
}
|
||||
12
core/src/dsp/taps/high_pass.h
Normal file
12
core/src/dsp/taps/high_pass.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "windowed_sinc.h"
|
||||
#include "estimate_tap_count.h"
|
||||
#include "../window/nuttall.h"
|
||||
|
||||
namespace dsp::taps {
|
||||
inline tap<float> highPass(double cutoff, double transWidth, double sampleRate) {
|
||||
return windowedSinc<float>(estimateTapCount(transWidth, sampleRate), (sampleRate / 2.0) - cutoff, sampleRate, [=](double n, double N){
|
||||
return window::nuttall(n, N) * (((int)round(n) % 2) ? -1.0f : 1.0f);
|
||||
});
|
||||
}
|
||||
}
|
||||
10
core/src/dsp/taps/low_pass.h
Normal file
10
core/src/dsp/taps/low_pass.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "windowed_sinc.h"
|
||||
#include "estimate_tap_count.h"
|
||||
#include "../window/nuttall.h"
|
||||
|
||||
namespace dsp::taps {
|
||||
inline tap<float> lowPass(double cutoff, double transWidth, double sampleRate) {
|
||||
return windowedSinc<float>(estimateTapCount(transWidth, sampleRate), cutoff, sampleRate, window::nuttall);
|
||||
}
|
||||
}
|
||||
33
core/src/dsp/taps/raised_cosine.h
Normal file
33
core/src/dsp/taps/raised_cosine.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include "tap.h"
|
||||
#include "../math/constants.h"
|
||||
#include "../math/sinc.h"
|
||||
|
||||
namespace dsp::taps {
|
||||
template<class T>
|
||||
inline tap<T> raisedCosine(int count, double beta, double Ts) {
|
||||
// Allocate taps
|
||||
tap<T> taps = taps::alloc<T>(count);
|
||||
|
||||
// Generate taps
|
||||
double half = (double)count / 2.0;
|
||||
double limit = Ts / (2.0 * beta);
|
||||
for (int i = 0; i < count; i++) {
|
||||
double t = (double)i - half + 0.5;
|
||||
if (t == limit || t == -limit) {
|
||||
taps.taps[i] = math::sinc(1.0 / (2.0*beta)) * DB_M_PI / (4.0*Ts);
|
||||
}
|
||||
else {
|
||||
taps.taps[i] = math::sinc(t / Ts) * DB_M_PI / (4.0*Ts);
|
||||
}
|
||||
}
|
||||
|
||||
return taps;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline tap<T> raisedCosine(int count, double beta, double symbolrate, double samplerate) {
|
||||
return raisedCosine<T>(count, beta, samplerate / symbolrate);
|
||||
}
|
||||
}
|
||||
35
core/src/dsp/taps/root_raised_cosine.h
Normal file
35
core/src/dsp/taps/root_raised_cosine.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include "tap.h"
|
||||
#include "../math/constants.h"
|
||||
|
||||
namespace dsp {
|
||||
template<class T>
|
||||
inline tap<T> rootRaisedCosine(int count, double beta, double Ts) {
|
||||
// Allocate taps
|
||||
tap<T> taps = taps::alloc<T>(count);
|
||||
|
||||
// Generate taps
|
||||
double half = (double)count / 2.0;
|
||||
double limit = Ts / (4.0 * beta);
|
||||
for (int i = 0; i < count; i++) {
|
||||
double t = (double)i - half + 0.5;
|
||||
if (t == 0.0) {
|
||||
taps.taps[i] = (1.0 + beta*(4.0/DB_M_PI - 1.0)) / Ts;
|
||||
}
|
||||
else if (t == limit || t == -limit) {
|
||||
taps.taps[i] = ((1.0 + 2.0/DB_M_PI)*sin(DB_M_PI/(4.0*beta)) + (1.0 - 2.0/DB_M_PI)*cos(DB_M_PI/(4.0*beta))) * beta/(Ts*DB_M_SQRT2);
|
||||
}
|
||||
else {
|
||||
taps.taps[i] = ((sin((1.0 - beta)*DB_M_PI*t/Ts) + cos((1.0 + beta)*DB_M_PI*t/Ts)*4.0*beta*t/Ts) / ((1.0 - (4.0*beta*t/Ts)*(4.0*beta*t/Ts))*DB_M_PI*t/Ts)) / Ts;
|
||||
}
|
||||
}
|
||||
|
||||
return taps;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline tap<T> rootRaisedCosine(int count, double beta, double symbolrate, double samplerate) {
|
||||
return rootRaisedCosine<T>(count, beta, samplerate / symbolrate);
|
||||
}
|
||||
}
|
||||
29
core/src/dsp/taps/tap.h
Normal file
29
core/src/dsp/taps/tap.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <volk/volk.h>
|
||||
|
||||
namespace dsp {
|
||||
template<class T>
|
||||
class tap {
|
||||
public:
|
||||
T* taps = NULL;
|
||||
unsigned int size = 0;
|
||||
};
|
||||
|
||||
namespace taps {
|
||||
template<class T>
|
||||
inline tap<T> alloc(int count) {
|
||||
tap<T> taps;
|
||||
taps.size = count;
|
||||
taps.taps = buffer::alloc<T>(count);
|
||||
return taps;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void free(tap<T>& taps) {
|
||||
if (!taps.taps) { return; }
|
||||
buffer::free(taps.taps);
|
||||
taps.taps = NULL;
|
||||
taps.size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
core/src/dsp/taps/windowed_sinc.h
Normal file
35
core/src/dsp/taps/windowed_sinc.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "tap.h"
|
||||
#include "../math/sinc.h"
|
||||
#include "../math/freq_to_omega.h"
|
||||
#include "../window/nuttall.h"
|
||||
|
||||
namespace dsp::taps {
|
||||
template<class T, typename Func>
|
||||
inline tap<T> windowedSinc(int count, double omega, Func window, double norm = 1.0) {
|
||||
// Allocate taps
|
||||
tap<T> taps = taps::alloc<T>(count);
|
||||
|
||||
// Generate using window
|
||||
double half = (double)count / 2.0;
|
||||
double corr = norm * omega / DB_M_PI;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
double t = (double)i - half + 0.5;
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
taps.taps[i] = math::sinc(t * omega) * window(t - half, count) * corr;
|
||||
}
|
||||
if constexpr (std::is_same_v<T, complex_t>) {
|
||||
complex_t cplx = { math::sinc(t * omega), 0.0f };
|
||||
taps.taps[i] = cplx * window(t - half, count) * corr;
|
||||
}
|
||||
}
|
||||
|
||||
return taps;
|
||||
}
|
||||
|
||||
template<class T, typename Func>
|
||||
inline tap<T> windowedSinc(int count, double cutoff, double samplerate, Func window, double norm = 1.0) {
|
||||
return windowedSinc<T>(count, math::freqToOmega(cutoff, samplerate), window, norm);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user