Skip to content

Commit

Permalink
Rename gamma to quality #6
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Sep 3, 2023
1 parent a007633 commit 987a84b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
32 changes: 15 additions & 17 deletions cpp/src/qdft/qdft.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace qdft
QDFT(const double samplerate,
const std::pair<double, double> bandwidth,
const double resolution = 24,
const double gamma = 0,
const double quality = 0,
const double latency = 0,
const std::optional<std::pair<double, double>> window = std::make_pair(+0.5,-0.5))
{
Expand All @@ -55,21 +55,20 @@ namespace qdft
config.samplerate = samplerate;
config.bandwidth = bandwidth;
config.resolution = resolution;
config.gamma = gamma;
config.quality = quality;
config.latency = latency;
config.window = window;
config.quality = std::pow(std::pow(2.0, 1.0 / resolution) - 1.0, -1.0);
config.size = static_cast<size_t>(std::ceil(resolution * std::log2(bandwidth.second / bandwidth.first)));

data.frequencies.resize(config.size);
data.qualities.resize(config.size);
data.latencies.resize(config.size);
data.periods.resize(config.size);
data.offsets.resize(config.size);
data.weights.resize(config.size);
data.latencies.resize(config.size);

const double alpha = std::pow(2.0, 1.0 / config.resolution) - 1.0;
const double beta = (gamma < 0) ? (alpha * 24.7 / 0.108) : gamma;
const double beta = (config.quality < 0) ? (alpha * 24.7 / 0.108) : config.quality;

for (size_t i = 0; i < config.size; ++i)
{
Expand All @@ -90,13 +89,13 @@ namespace qdft

data.offsets[i] = static_cast<size_t>(offset);

const F weight = F(1) / period;

data.weights[i] = weight;

const double latency = (data.periods.front() - offset) / config.samplerate;

data.latencies[i] = latency;

const F weight = F(1) / period;

data.weights[i] = weight;
}

data.fiddles.resize(config.size * 3);
Expand Down Expand Up @@ -145,6 +144,11 @@ namespace qdft
return config.size;
}

const std::vector<double>& frequencies() const
{
return data.frequencies;
}

const std::vector<double>& qualities() const
{
return data.qualities;
Expand All @@ -155,11 +159,6 @@ namespace qdft
return data.latencies;
}

const std::vector<double>& frequencies() const
{
return data.frequencies;
}

void qdft(const T sample, std::complex<F>* const dft)
{
std::deque<T>& inputs = data.inputs;
Expand Down Expand Up @@ -260,9 +259,8 @@ namespace qdft
double samplerate;
std::pair<double, double> bandwidth;
double resolution;
double gamma;
double latency;
double quality;
double latency;
size_t size;
std::optional<std::pair<double, double>> window;
};
Expand All @@ -273,10 +271,10 @@ namespace qdft
{
std::vector<double> frequencies;
std::vector<double> qualities;
std::vector<double> latencies;
std::vector<size_t> periods;
std::vector<size_t> offsets;
std::vector<F> weights;
std::vector<double> latencies;

std::vector<std::complex<F>> fiddles;
std::vector<std::complex<F>> twiddles;
Expand Down
10 changes: 5 additions & 5 deletions python/src/qdft/qdft.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QDFT:
Constant-Q Sliding Discrete Fourier Transform (QDFT).
"""

def __init__(self, samplerate, bandwidth, resolution=24, gamma=0, latency=0, window=(+0.5,-0.5)):
def __init__(self, samplerate, bandwidth, resolution=24, quality=0, latency=0, window=(+0.5,-0.5)):
"""
Create a new QDFT plan.
Expand All @@ -44,7 +44,7 @@ def __init__(self, samplerate, bandwidth, resolution=24, gamma=0, latency=0, win
Lowest and highest frequency in hertz to be resolved.
resolution : int, optional
Octave resolution, e.g. number of DFT bins per octave.
gamma : float, optional
quality : float, optional
Bandwidth offset for determining filter lengths.
latency : float, optional
Analysis latency adjustment between -1 and +1.
Expand All @@ -58,7 +58,7 @@ def __init__(self, samplerate, bandwidth, resolution=24, gamma=0, latency=0, win
frequencies = bandwidth[0] * numpy.power(2, numpy.arange(size) / resolution)

alpha = 2 ** (1 / resolution) - 1
beta = (alpha * 24.7 / 0.108) if (gamma is None) or (gamma < 0) else gamma
beta = (alpha * 24.7 / 0.108) if (quality is None) or (quality < 0) else quality
qualities = frequencies / (alpha * frequencies + beta)

periods = numpy.ceil(qualities * samplerate / frequencies).astype(int)
Expand All @@ -83,12 +83,12 @@ def __init__(self, samplerate, bandwidth, resolution=24, gamma=0, latency=0, win
self.samplerate = samplerate
self.bandwidth = bandwidth
self.resolution = resolution
self.gamma = gamma
self.quality = quality
self.qualities = qualities
self.latency = latency
self.latencies = latencies
self.window = window
self.kernels = kernels
self.qualities = qualities
self.size = size
self.frequencies = frequencies
self.periods = periods
Expand Down

0 comments on commit 987a84b

Please sign in to comment.