FIR filter and design functions¶
delay
function¶
template <size_t samples = 1, typename E1,
typename T = expression_value_type<E1>>
expression_delay<samples, E1, false, samples> delay(E1 &&e1)
Returns template expression that applies delay to the input (uses ring buffer internally)
e1 an input expression
samples delay in samples (must be a compile time value)
univector<double, 10> v = counter();
auto d = delay(v, csize<4>);
Source code
template <size_t samples = 1, typename E1, typename T = expression_value_type<E1>>
KFR_INTRINSIC expression_delay<samples, E1, false, samples> delay(E1&& e1)
{
static_assert(samples >= 1 && samples < 1024, "");
return expression_delay<samples, E1, false, samples>(std::forward<E1>(e1), delay_state<T, samples>());
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/delay.hpp#L162
template <size_t samples, typename T, typename E1,
univector_tag STag>
expression_delay<samples, E1, true, STag>
delay(E1 &&e1,
std::reference_wrapper<delay_state<T, samples, STag>>
state)
Returns template expression that applies delay to the input (uses ring buffer in state)
state delay filter state (taken by reference)
e1 an input expression
univector<double, 10> v = counter();
delay_state<double, 4> state;
auto d = delay(state, v);
Source code
template <size_t samples, typename T, typename E1, univector_tag STag>
KFR_INTRINSIC expression_delay<samples, E1, true, STag> delay(
E1&& e1, std::reference_wrapper<delay_state<T, samples, STag>> state)
{
static_assert(STag == tag_dynamic_vector || (samples >= 1 && samples < 1024), "");
return expression_delay<samples, E1, true, STag>(std::forward<E1>(e1), state);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/delay.hpp#L179
template <size_t samples, typename T, typename E1,
univector_tag STag>
[[deprecated(
"delay(state, expr) is deprecated. Use delay(expr, "
"std::ref(state))")]] expression_delay<samples, E1,
true, STag>
delay(delay_state<T, samples, STag> &state, E1 &&e1)
Returns template expression that applies delay to the input (uses ring buffer in state)
state delay filter state
e1 an input expression
univector<double, 10> v = counter();
delay_state<double, 4> state;
auto d = delay(state, v);
Source code
template <size_t samples, typename T, typename E1, univector_tag STag>
[[deprecated("delay(state, expr) is deprecated. Use delay(expr, std::ref(state))")]] KFR_INTRINSIC
expression_delay<samples, E1, true, STag>
delay(delay_state<T, samples, STag>& state, E1&& e1)
{
static_assert(STag == tag_dynamic_vector || (samples >= 1 && samples < 1024), "");
return expression_delay<samples, E1, true, STag>(std::forward<E1>(e1), std::ref(state));
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/delay.hpp#L199
fir
function¶
template <typename E1, typename U = expression_value_type<E1>, typename Taps,
typename T = std::remove_cv_t<container_value_type<Taps>>>
[[deprecated("fir(expr, taps) is deprecated. Use fir(expr, fir_params
Returns template expression that applies FIR filter to the input
e1 an input expression
taps coefficients for the FIR filter (taken by value)
Source code
template <typename E1, typename U = expression_value_type<E1>, typename Taps,
typename T = std::remove_cv_t<container_value_type<Taps>>>
[[deprecated("fir(expr, taps) is deprecated. Use fir(expr, fir_params{taps})")]] KFR_INTRINSIC expression_fir<
T, U, E1, false>
fir(E1&& e1, Taps&& taps)
{
return expression_fir<T, U, E1, false>(std::forward<E1>(e1), fir_state<T, U>{ std::forward<Taps>(taps) });
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L262
template <typename T, typename E1,
typename U = expression_value_type<E1>>
expression_fir<T, U, E1, false> fir(E1 &&e1,
fir_params<T> state)
Returns template expression that applies FIR filter to the input
e1 an input expression
state coefficients for the FIR filter (taken by value)
Source code
template <typename T, typename E1, typename U = expression_value_type<E1>>
KFR_INTRINSIC expression_fir<T, U, E1, false> fir(E1&& e1, fir_params<T> state)
{
return expression_fir<T, U, E1, false>(std::forward<E1>(e1), fir_state<T, U>{ std::move(state) });
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L273
template <typename T, typename E1, typename U>
expression_fir<T, U, E1, true>
fir(E1 &&e1, std::reference_wrapper<fir_state<T, U>> state)
Returns template expression that applies FIR filter to the input
e1 an input expression
state coefficients and state of the filter (taken by reference, ensure proper lifetime)
Source code
template <typename T, typename E1, typename U>
KFR_INTRINSIC expression_fir<T, U, E1, true> fir(E1&& e1, std::reference_wrapper<fir_state<T, U>> state)
{
static_assert(std::is_same_v<U, expression_value_type<E1>>, "fir: type mismatch");
return expression_fir<T, U, E1, true>(std::forward<E1>(e1), state);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L284
template <typename T, typename U, typename E1>
[[deprecated(
"fir(state, expr) is deprecated. Use fir(expr, "
"std::ref(state))")]] expression_fir<T, U, E1, true>
fir(fir_state<T, U> &state, E1 &&e1)
Returns template expression that applies FIR filter to the input
state FIR filter state (state is referenced, ensure proper lifetime)
e1 an input expression
Source code
template <typename T, typename U, typename E1>
[[deprecated("fir(state, expr) is deprecated. Use fir(expr, std::ref(state))")]] KFR_INTRINSIC expression_fir<
T, U, E1, true>
fir(fir_state<T, U>& state, E1&& e1)
{
return fir(std::forward<E1>(e1), std::reference_wrapper<fir_state<T, U>>(state));
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L298
fir_bandpass
function¶
template <typename T, univector_tag Tag>
void fir_bandpass(univector<T, Tag> &taps,
identity<T> frequency1,
identity<T> frequency2,
const expression_handle<T> &window,
bool normalize = true)
Calculates coefficients for the band-pass FIR filter
taps array where computed coefficients are stored
frequency1 Normalized frequency (frequency_Hz / samplerate_Hz)
frequency2 Normalized frequency (frequency_Hz / samplerate_Hz)
window pointer to a window function
normalize true for normalized coefficients
Source code
template <typename T, univector_tag Tag>
KFR_INTRINSIC void fir_bandpass(univector<T, Tag>& taps, identity<T> frequency1, identity<T> frequency2,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_bandpass(taps.slice(), frequency1, frequency2, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L161
template <typename T>
void fir_bandpass(const univector_ref<T> &taps,
identity<T> frequency1,
identity<T> frequency2,
const expression_handle<T> &window,
bool normalize = true)
@copydoc kfr::fir_bandpass
Source code
template <typename T>
KFR_INTRINSIC void fir_bandpass(const univector_ref<T>& taps, identity<T> frequency1, identity<T> frequency2,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_bandpass(taps, frequency1, frequency2, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L206
fir_bandstop
function¶
template <typename T, univector_tag Tag>
void fir_bandstop(univector<T, Tag> &taps,
identity<T> frequency1,
identity<T> frequency2,
const expression_handle<T> &window,
bool normalize = true)
Calculates coefficients for the band-stop FIR filter
taps array where computed coefficients are stored
frequency1 Normalized frequency (frequency_Hz / samplerate_Hz)
frequency2 Normalized frequency (frequency_Hz / samplerate_Hz)
window pointer to a window function
normalize true for normalized coefficients
Source code
template <typename T, univector_tag Tag>
KFR_INTRINSIC void fir_bandstop(univector<T, Tag>& taps, identity<T> frequency1, identity<T> frequency2,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_bandstop(taps.slice(), frequency1, frequency2, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L176
template <typename T>
void fir_bandstop(const univector_ref<T> &taps,
identity<T> frequency1,
identity<T> frequency2,
const expression_handle<T> &window,
bool normalize = true)
@copydoc kfr::fir_bandstop
Source code
template <typename T>
KFR_INTRINSIC void fir_bandstop(const univector_ref<T>& taps, identity<T> frequency1, identity<T> frequency2,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_bandstop(taps, frequency1, frequency2, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L216
fir_highpass
function¶
template <typename T, univector_tag Tag>
void fir_highpass(univector<T, Tag> &taps,
identity<T> cutoff,
const expression_handle<T> &window,
bool normalize = true)
Calculates coefficients for the high-pass FIR filter
taps array where computed coefficients are stored
cutoff Normalized frequency (frequency_Hz / samplerate_Hz)
window pointer to a window function
normalize true for normalized coefficients
Source code
template <typename T, univector_tag Tag>
KFR_INTRINSIC void fir_highpass(univector<T, Tag>& taps, identity<T> cutoff,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_highpass(taps.slice(), cutoff, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L146
template <typename T>
void fir_highpass(const univector_ref<T> &taps,
identity<T> cutoff,
const expression_handle<T> &window,
bool normalize = true)
@copydoc kfr::fir_highpass
Source code
template <typename T>
KFR_INTRINSIC void fir_highpass(const univector_ref<T>& taps, identity<T> cutoff,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_highpass(taps, cutoff, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L196
fir_lowpass
function¶
template <typename T, univector_tag Tag>
void fir_lowpass(univector<T, Tag> &taps,
identity<T> cutoff,
const expression_handle<T> &window,
bool normalize = true)
Calculates coefficients for the low-pass FIR filter
taps array where computed coefficients are stored
cutoff Normalized frequency (frequency_Hz / samplerate_Hz)
window pointer to a window function
normalize true for normalized coefficients
Source code
template <typename T, univector_tag Tag>
KFR_INTRINSIC void fir_lowpass(univector<T, Tag>& taps, identity<T> cutoff,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_lowpass(taps.slice(), cutoff, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L132
template <typename T>
void fir_lowpass(const univector_ref<T> &taps,
identity<T> cutoff,
const expression_handle<T> &window,
bool normalize = true)
@copydoc kfr::fir_lowpass
Source code
template <typename T>
KFR_INTRINSIC void fir_lowpass(const univector_ref<T>& taps, identity<T> cutoff,
const expression_handle<T>& window, bool normalize = true)
{
return internal::fir_lowpass(taps, cutoff, window, normalize);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir_design.hpp#L186
fracdelay
function¶
template <typename T, typename E1>
expression_short_fir<2, T, expression_value_type<E1>, E1>
fracdelay(E1 &&e1, T delay)
Returns template expression that applies a fractional delay to the input
e1 an input expression
e1 a fractional delay in range 0..1
Source code
template <typename T, typename E1>
KFR_INTRINSIC expression_short_fir<2, T, expression_value_type<E1>, E1> fracdelay(E1&& e1, T delay)
{
if (CMT_UNLIKELY(delay < 0))
delay = 0;
univector<T, 2> taps({ 1 - delay, delay });
return expression_short_fir<2, T, expression_value_type<E1>, E1>(
std::forward<E1>(e1), short_fir_state<2, T, expression_value_type<E1>>{ taps });
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/delay.hpp#L211
moving_sum
function¶
template <typename E1>
expression_moving_sum<expression_value_type<E1>, E1,
tag_dynamic_vector>
moving_sum(E1 &&e1, size_t sum_length)
Returns template expression that performs moving sum on the input
e1 an input expression
Source code
template <typename E1>
KFR_INTRINSIC expression_moving_sum<expression_value_type<E1>, E1, tag_dynamic_vector> moving_sum(
E1&& e1, size_t sum_length)
{
return expression_moving_sum<expression_value_type<E1>, E1, tag_dynamic_vector>(
std::forward<E1>(e1), moving_sum_state<expression_value_type<E1>, tag_dynamic_vector>{ sum_length });
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L308
template <size_t sum_length, typename E1>
[[deprecated("moving_sum<len> is deprecated. Use "
"moving_sum(expr, len) "
"instead")]] expression_moving_sum<
expression_value_type<E1>, E1, tag_dynamic_vector>
moving_sum(E1 &&e1)
Returns template expression that performs moving sum on the input
e1 an input expression
Source code
template <size_t sum_length, typename E1>
[[deprecated("moving_sum<len> is deprecated. Use moving_sum(expr, len) instead")]] KFR_INTRINSIC
expression_moving_sum<expression_value_type<E1>, E1, tag_dynamic_vector>
moving_sum(E1&& e1)
{
return expression_moving_sum<expression_value_type<E1>, E1, tag_dynamic_vector>(
std::forward<E1>(e1), moving_sum_state<expression_value_type<E1>, tag_dynamic_vector>{ sum_length });
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L322
template <typename E1, typename U, size_t Tag>
expression_moving_sum<U, E1, Tag, true> moving_sum(
E1 &&e1,
std::reference_wrapper<moving_sum_state<U, Tag>> state)
Returns template expression that performs moving sum on the input
e1 an input expression
state State (taken by reference)
Source code
template <typename E1, typename U, size_t Tag>
KFR_INTRINSIC expression_moving_sum<U, E1, Tag, true> moving_sum(
E1&& e1, std::reference_wrapper<moving_sum_state<U, Tag>> state)
{
return expression_moving_sum<expression_value_type<E1>, E1, Tag, true>(std::forward<E1>(e1), state);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L334
template <typename U, typename E1, univector_tag STag>
[[deprecated(
"moving_sum(state, expr) is deprecated. Use "
"moving_sum(expr, std::ref(state)) "
"instead")]] expression_moving_sum<U, E1, STag, true>
moving_sum(moving_sum_state<U, STag> &state, E1 &&e1)
Returns template expression that performs moving sum on the input
state moving sum state
e1 an input expression
Source code
template <typename U, typename E1, univector_tag STag>
[[deprecated("moving_sum(state, expr) is deprecated. Use moving_sum(expr, std::ref(state)) "
"instead")]] KFR_INTRINSIC expression_moving_sum<U, E1, STag, true>
moving_sum(moving_sum_state<U, STag>& state, E1&& e1)
{
return moving_sum(std::forward<E1>(e1), std::ref(state));
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L348
reset
function¶
void reset() final
Reset internal filter state
Source code
void reset() final
{
state.delayline = scalar(0);
state.delayline_cursor = 0;
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L411
short_fir
function¶
template <typename T, size_t TapCount, typename E1,
size_t InternalTapCount =
next_poweroftwo(TapCount - 1) + 1,
typename U = expression_value_type<E1>>
expression_short_fir<InternalTapCount, T, U, E1, false>
short_fir(E1 &&e1, const univector<T, TapCount> &taps)
Returns template expression that applies FIR filter to the input (count of coefficients must be in
range 2..32)
e1 an input expression
taps coefficients for the FIR filter
Source code
template <typename T, size_t TapCount, typename E1,
size_t InternalTapCount = next_poweroftwo(TapCount - 1) + 1, typename U = expression_value_type<E1>>
KFR_INTRINSIC expression_short_fir<InternalTapCount, T, U, E1, false> short_fir(
E1&& e1, const univector<T, TapCount>& taps)
{
static_assert(TapCount >= 2 && TapCount <= 33, "Use short_fir only for small FIR filters");
return expression_short_fir<InternalTapCount, T, U, E1, false>(
std::forward<E1>(e1), short_fir_state<InternalTapCount, T, U>{ taps });
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L361
template <typename T, size_t TapCount, typename E1,
typename U>
expression_short_fir<TapCount, T, U, E1, true> short_fir(
E1 &&e1,
std::reference_wrapper<short_fir_state<TapCount, T, U>>
state)
Returns template expression that applies FIR filter to the input (count of coefficients must be in
range 2..32)
e1 an input expression
state FIR filter state (state is referenced, ensure proper lifetime)
Source code
template <typename T, size_t TapCount, typename E1, typename U>
KFR_INTRINSIC expression_short_fir<TapCount, T, U, E1, true> short_fir(
E1&& e1, std::reference_wrapper<short_fir_state<TapCount, T, U>> state)
{
static_assert(std::is_same_v<U, expression_value_type<E1>>, "short_fir: type mismatch");
static_assert(TapCount >= 2 && TapCount <= 33, "Use short_fir only for small FIR filters");
return expression_short_fir<TapCount, T, U, E1, true>(std::forward<E1>(e1), state);
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L375
template <size_t TapCount,
size_t InternalTapCount =
next_poweroftwo(TapCount - 1) + 1,
typename T, typename U, typename E1>
[[deprecated("short_fir(state, expr) is deprecated, use "
"short_fir(expr, "
"std::ref(state))")]] expression_short_fir<
InternalTapCount, T, expression_value_type<E1>, E1,
true>
short_fir(short_fir_state<InternalTapCount, T, U> &state,
E1 &&e1)
Returns template expression that applies FIR filter to the input (count of coefficients must be in
range 2..32)
state FIR filter state
e1 an input expression
Source code
template <size_t TapCount, size_t InternalTapCount = next_poweroftwo(TapCount - 1) + 1, typename T,
typename U, typename E1>
[[deprecated("short_fir(state, expr) is deprecated, use short_fir(expr, std::ref(state))")]] KFR_INTRINSIC
expression_short_fir<InternalTapCount, T, expression_value_type<E1>, E1, true>
short_fir(short_fir_state<InternalTapCount, T, U>& state, E1&& e1)
{
static_assert(InternalTapCount == next_poweroftwo(TapCount - 1) + 1, "short_fir: TapCount mismatch");
return short_fir(std::forward<E1>(e1), std::ref(state));
}
https://github.com/kfrlib/kfr/blob//include/kfr/dsp/fir.hpp#L393
Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/