Renamed filterbank to firfilterbank in C-code
This commit is contained in:
parent
195319ab29
commit
9afed2c9a9
|
@ -17,7 +17,8 @@ add_library(lasp_lib
|
||||||
lasp_siggen.c
|
lasp_siggen.c
|
||||||
lasp_worker.c
|
lasp_worker.c
|
||||||
lasp_dfifo.c
|
lasp_dfifo.c
|
||||||
lasp_filterbank.c
|
lasp_firfilterbank.c
|
||||||
|
lasp_sosfilterbank.c
|
||||||
# lasp_octave_fir.c
|
# lasp_octave_fir.c
|
||||||
lasp_decimation.c
|
lasp_decimation.c
|
||||||
lasp_sp_lowpass.c
|
lasp_sp_lowpass.c
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// Implementation of the decimator
|
// Implementation of the decimator
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
#include "lasp_decimation.h"
|
#include "lasp_decimation.h"
|
||||||
#include "lasp_filterbank.h"
|
#include "lasp_firfilterbank.h"
|
||||||
#include "lasp_tracer.h"
|
#include "lasp_tracer.h"
|
||||||
#include "lasp_alloc.h"
|
#include "lasp_alloc.h"
|
||||||
#include "lasp_dfifo.h"
|
#include "lasp_dfifo.h"
|
||||||
|
@ -34,7 +34,7 @@ static __thread DecFilter DecFilters[] = {
|
||||||
typedef struct Decimator_s {
|
typedef struct Decimator_s {
|
||||||
us nchannels;
|
us nchannels;
|
||||||
us dec_fac;
|
us dec_fac;
|
||||||
FilterBank** fbs;
|
Firfilterbank** fbs;
|
||||||
dFifo* output_fifo;
|
dFifo* output_fifo;
|
||||||
} Decimator;
|
} Decimator;
|
||||||
|
|
||||||
|
@ -61,14 +61,14 @@ Decimator* Decimator_create(us nchannels,DEC_FAC df) {
|
||||||
|
|
||||||
/* Create the filterbanks */
|
/* Create the filterbanks */
|
||||||
Decimator* dec = a_malloc(sizeof(Decimator));
|
Decimator* dec = a_malloc(sizeof(Decimator));
|
||||||
dec->fbs = a_malloc(sizeof(FilterBank*)*nchannels);
|
dec->fbs = a_malloc(sizeof(Firfilterbank*)*nchannels);
|
||||||
dec->nchannels = nchannels;
|
dec->nchannels = nchannels;
|
||||||
dec->dec_fac = filter->dec_fac;
|
dec->dec_fac = filter->dec_fac;
|
||||||
|
|
||||||
dmat h = dmat_foreign_data(filter->ntaps,1,filter->h,false);
|
dmat h = dmat_foreign_data(filter->ntaps,1,filter->h,false);
|
||||||
|
|
||||||
for(us channelno=0;channelno<nchannels;channelno++) {
|
for(us channelno=0;channelno<nchannels;channelno++) {
|
||||||
dec->fbs[channelno] = FilterBank_create(&h,DEC_FFT_LEN);
|
dec->fbs[channelno] = Firfilterbank_create(&h,DEC_FFT_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
dmat_free(&h);
|
dmat_free(&h);
|
||||||
|
@ -128,10 +128,10 @@ dmat Decimator_decimate(Decimator* dec,const dmat* samples) {
|
||||||
chan);
|
chan);
|
||||||
|
|
||||||
/* Low-pass filter stuff */
|
/* Low-pass filter stuff */
|
||||||
dmat filtered_res = FilterBank_filter(dec->fbs[chan],
|
dmat filtered_res = Firfilterbank_filter(dec->fbs[chan],
|
||||||
&samples_channel);
|
&samples_channel);
|
||||||
|
|
||||||
dbgassert(filtered_res.n_cols == 1,"Bug in FilterBank");
|
dbgassert(filtered_res.n_cols == 1,"Bug in Firfilterbank");
|
||||||
|
|
||||||
vd_free(&samples_channel);
|
vd_free(&samples_channel);
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ dmat Decimator_decimate(Decimator* dec,const dmat* samples) {
|
||||||
1);
|
1);
|
||||||
|
|
||||||
dbgassert(filtered_res.n_rows == filtered_col.n_rows,
|
dbgassert(filtered_res.n_rows == filtered_col.n_rows,
|
||||||
"Not all FilterBank's have same output number"
|
"Not all Firfilterbank's have same output number"
|
||||||
" of rows!");
|
" of rows!");
|
||||||
|
|
||||||
dmat_copy_rows(&filtered_col,
|
dmat_copy_rows(&filtered_col,
|
||||||
|
@ -209,7 +209,7 @@ void Decimator_free(Decimator* dec) {
|
||||||
dFifo_free(dec->output_fifo);
|
dFifo_free(dec->output_fifo);
|
||||||
|
|
||||||
for(us chan=0;chan<dec->nchannels;chan++) {
|
for(us chan=0;chan<dec->nchannels;chan++) {
|
||||||
FilterBank_free(dec->fbs[chan]);
|
Firfilterbank_free(dec->fbs[chan]);
|
||||||
}
|
}
|
||||||
|
|
||||||
a_free(dec->fbs);
|
a_free(dec->fbs);
|
||||||
|
|
|
@ -3,17 +3,17 @@
|
||||||
// Author: J.A. de Jong -ASCEE
|
// Author: J.A. de Jong -ASCEE
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// FilterBank implementation.
|
// Firfilterbank implementation.
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
#define TRACERPLUS (-5)
|
#define TRACERPLUS (-5)
|
||||||
#include "lasp_filterbank.h"
|
#include "lasp_firfilterbank.h"
|
||||||
#include "lasp_fft.h"
|
#include "lasp_fft.h"
|
||||||
#include "lasp_dfifo.h"
|
#include "lasp_dfifo.h"
|
||||||
#include "lasp_tracer.h"
|
#include "lasp_tracer.h"
|
||||||
#include "lasp_alg.h"
|
#include "lasp_alg.h"
|
||||||
#define FIFO_SIZE_MULT 2
|
#define FIFO_SIZE_MULT 2
|
||||||
|
|
||||||
typedef struct FilterBank_s {
|
typedef struct Firfilterbank_s {
|
||||||
us nfft;
|
us nfft;
|
||||||
|
|
||||||
us P_m_1; /**< Filter length minus one */
|
us P_m_1; /**< Filter length minus one */
|
||||||
|
@ -25,9 +25,9 @@ typedef struct FilterBank_s {
|
||||||
|
|
||||||
Fft* fft; /* Handle to internal FFT-function */
|
Fft* fft; /* Handle to internal FFT-function */
|
||||||
|
|
||||||
} FilterBank;
|
} Firfilterbank;
|
||||||
|
|
||||||
FilterBank* FilterBank_create(const dmat* h,
|
Firfilterbank* Firfilterbank_create(const dmat* h,
|
||||||
const us nfft) {
|
const us nfft) {
|
||||||
|
|
||||||
fsTRACE(15);
|
fsTRACE(15);
|
||||||
|
@ -46,7 +46,7 @@ FilterBank* FilterBank_create(const dmat* h,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterBank* fb = a_malloc(sizeof(FilterBank));
|
Firfilterbank* fb = a_malloc(sizeof(Firfilterbank));
|
||||||
|
|
||||||
fb->nfft = nfft;
|
fb->nfft = nfft;
|
||||||
fb->P_m_1 = P-1;
|
fb->P_m_1 = P-1;
|
||||||
|
@ -77,7 +77,7 @@ FilterBank* FilterBank_create(const dmat* h,
|
||||||
feTRACE(15);
|
feTRACE(15);
|
||||||
return fb;
|
return fb;
|
||||||
}
|
}
|
||||||
void FilterBank_free(FilterBank* fb) {
|
void Firfilterbank_free(Firfilterbank* fb) {
|
||||||
fsTRACE(15);
|
fsTRACE(15);
|
||||||
dbgassert(fb,NULLPTRDEREF);
|
dbgassert(fb,NULLPTRDEREF);
|
||||||
cmat_free(&fb->filters);
|
cmat_free(&fb->filters);
|
||||||
|
@ -87,7 +87,7 @@ void FilterBank_free(FilterBank* fb) {
|
||||||
a_free(fb);
|
a_free(fb);
|
||||||
feTRACE(15);
|
feTRACE(15);
|
||||||
}
|
}
|
||||||
dmat FilterBank_filter(FilterBank* fb,
|
dmat Firfilterbank_filter(Firfilterbank* fb,
|
||||||
const vd* x) {
|
const vd* x) {
|
||||||
|
|
||||||
fsTRACE(15);
|
fsTRACE(15);
|
|
@ -1,8 +1,8 @@
|
||||||
// lasp_filterbank.h
|
// lasp_firfilterbank.h
|
||||||
//
|
//
|
||||||
// Author: J.A. de Jong - ASCEE
|
// Author: J.A. de Jong - ASCEE
|
||||||
//
|
//
|
||||||
// Description: Implemententation of a discrete filterbank using fast
|
// Description: Implemententation of a discrete FIR filterbank using fast
|
||||||
// convolution and the overlap-save (overlap-scrap method). Multiple
|
// convolution and the overlap-save (overlap-scrap method). Multiple
|
||||||
// filters can be applied to the same input data (*filterbank*).
|
// filters can be applied to the same input data (*filterbank*).
|
||||||
// Implementation is computationally efficient, as the forward FFT is
|
// Implementation is computationally efficient, as the forward FFT is
|
||||||
|
@ -10,14 +10,14 @@
|
||||||
// each filter in the filterbank.
|
// each filter in the filterbank.
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef LASP_FILTERBANK_H
|
#ifndef LASP_FIRFILTERBANK_H
|
||||||
#define LASP_FILTERBANK_H
|
#define LASP_FIRFILTERBANK_H
|
||||||
#include "lasp_types.h"
|
#include "lasp_types.h"
|
||||||
#include "lasp_mat.h"
|
#include "lasp_mat.h"
|
||||||
typedef struct FilterBank_s FilterBank;
|
typedef struct Firfilterbank_s Firfilterbank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a fast convolution filter bank and returns a FilterBank
|
* Initializes a fast convolution filter bank and returns a Firfilterbank
|
||||||
* handle. The nfft will be chosen to be at least four times the
|
* handle. The nfft will be chosen to be at least four times the
|
||||||
* length of the FIR filters.
|
* length of the FIR filters.
|
||||||
*
|
*
|
||||||
|
@ -30,9 +30,9 @@ typedef struct FilterBank_s FilterBank;
|
||||||
* times the filter lengths. For the lowest possible latency, it is
|
* times the filter lengths. For the lowest possible latency, it is
|
||||||
* better to set nfft at twice the filter length.
|
* better to set nfft at twice the filter length.
|
||||||
*
|
*
|
||||||
* @return FilterBank handle, NULL on error.
|
* @return Firfilterbank handle, NULL on error.
|
||||||
*/
|
*/
|
||||||
FilterBank* FilterBank_create(const dmat* h,const us nfft);
|
Firfilterbank* Firfilterbank_create(const dmat* h,const us nfft);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters x using h, returns y
|
* Filters x using h, returns y
|
||||||
|
@ -44,7 +44,7 @@ FilterBank* FilterBank_create(const dmat* h,const us nfft);
|
||||||
* filterbank. The number of output samples is equal to the number of
|
* filterbank. The number of output samples is equal to the number of
|
||||||
* input samples in x.
|
* input samples in x.
|
||||||
*/
|
*/
|
||||||
dmat FilterBank_filter(FilterBank* fb,
|
dmat Firfilterbank_filter(Firfilterbank* fb,
|
||||||
const vd* x);
|
const vd* x);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,8 +52,8 @@ dmat FilterBank_filter(FilterBank* fb,
|
||||||
*
|
*
|
||||||
* @param f Filter handle
|
* @param f Filter handle
|
||||||
*/
|
*/
|
||||||
void FilterBank_free(FilterBank* f);
|
void Firfilterbank_free(Firfilterbank* f);
|
||||||
|
|
||||||
|
|
||||||
#endif // LASP_FILTERBANK_H
|
#endif // LASP_FIRFILTERBANK_H
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
|
@ -6,6 +6,7 @@
|
||||||
// Signal generator implementation
|
// Signal generator implementation
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
#define TRACERPLUS (-5)
|
#define TRACERPLUS (-5)
|
||||||
|
#include "lasp_siggen.h"
|
||||||
#include "lasp_alloc.h"
|
#include "lasp_alloc.h"
|
||||||
#include "lasp_assert.h"
|
#include "lasp_assert.h"
|
||||||
#include "lasp_mat.h"
|
#include "lasp_mat.h"
|
||||||
|
@ -19,7 +20,7 @@ typedef enum {
|
||||||
|
|
||||||
} SignalType;
|
} SignalType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Siggen {
|
||||||
SignalType signaltype;
|
SignalType signaltype;
|
||||||
d fs; // Sampling frequency [Hz]
|
d fs; // Sampling frequency [Hz]
|
||||||
d level_amp;
|
d level_amp;
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#define LASP_SIGGEN_H
|
#define LASP_SIGGEN_H
|
||||||
#include "lasp_mat.h"
|
#include "lasp_mat.h"
|
||||||
|
|
||||||
typedef struct {} Siggen;
|
typedef struct Siggen Siggen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a sine wave signal generator
|
* Create a sine wave signal generator
|
||||||
|
@ -54,5 +54,5 @@ void Siggen_genSignal(Siggen*,vd* samples);
|
||||||
*/
|
*/
|
||||||
void Siggen_free(Siggen*);
|
void Siggen_free(Siggen*);
|
||||||
|
|
||||||
#endif LASP_SIGGEN_H
|
#endif //LASP_SIGGEN_H
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
from .freqweighting_fir import A, C
|
from .freqweighting_fir import A, C
|
||||||
|
from .bandpass_fir import OctaveBankDesigner, ThirdOctaveBankDesigner
|
||||||
|
from .bandpass_limits import octave_band_limits, third_octave_band_limits
|
||||||
|
|
||||||
__all__ = ['A', 'Z']
|
__all__ = ['A', 'Z']
|
||||||
|
|
|
@ -349,30 +349,30 @@ cdef class AvPowerSpectra:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
cdef extern from "lasp_filterbank.h":
|
cdef extern from "lasp_firfilterbank.h":
|
||||||
ctypedef struct c_FilterBank "FilterBank"
|
ctypedef struct c_Firfilterbank "Firfilterbank"
|
||||||
c_FilterBank* FilterBank_create(const dmat* h,const us nfft) nogil
|
c_Firfilterbank* Firfilterbank_create(const dmat* h,const us nfft) nogil
|
||||||
dmat FilterBank_filter(c_FilterBank* fb,const vd* x) nogil
|
dmat Firfilterbank_filter(c_Firfilterbank* fb,const vd* x) nogil
|
||||||
void FilterBank_free(c_FilterBank* fb) nogil
|
void Firfilterbank_free(c_Firfilterbank* fb) nogil
|
||||||
|
|
||||||
|
|
||||||
cdef class FilterBank:
|
cdef class FilterBank:
|
||||||
cdef:
|
cdef:
|
||||||
c_FilterBank* fb
|
c_Firfilterbank* fb
|
||||||
def __cinit__(self,d[::1,:] h, us nfft):
|
def __cinit__(self,d[::1,:] h, us nfft):
|
||||||
cdef dmat hmat = dmat_foreign_data(h.shape[0],
|
cdef dmat hmat = dmat_foreign_data(h.shape[0],
|
||||||
h.shape[1],
|
h.shape[1],
|
||||||
&h[0,0],
|
&h[0,0],
|
||||||
False)
|
False)
|
||||||
|
|
||||||
self.fb = FilterBank_create(&hmat,nfft)
|
self.fb = Firfilterbank_create(&hmat,nfft)
|
||||||
dmat_free(&hmat)
|
dmat_free(&hmat)
|
||||||
if not self.fb:
|
if not self.fb:
|
||||||
raise RuntimeError('Error creating FilberBank')
|
raise RuntimeError('Error creating FilberBank')
|
||||||
|
|
||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
if self.fb:
|
if self.fb:
|
||||||
FilterBank_free(self.fb)
|
Firfilterbank_free(self.fb)
|
||||||
|
|
||||||
def filter_(self,d[::1, :] input_):
|
def filter_(self,d[::1, :] input_):
|
||||||
assert input_.shape[1] == 1
|
assert input_.shape[1] == 1
|
||||||
|
@ -382,7 +382,7 @@ cdef class FilterBank:
|
||||||
|
|
||||||
cdef dmat output
|
cdef dmat output
|
||||||
with nogil:
|
with nogil:
|
||||||
output = FilterBank_filter(self.fb,&input_vd)
|
output = Firfilterbank_filter(self.fb,&input_vd)
|
||||||
|
|
||||||
# Steal the pointer from output
|
# Steal the pointer from output
|
||||||
result = dmat_to_ndarray(&output,True)
|
result = dmat_to_ndarray(&output,True)
|
||||||
|
|
Loading…
Reference in New Issue