Removed some memory pool stuff. Decreased some tracer values. Removed debug warning on overflow. Bugfix on macro's ASCEE_USE_BLAS to LASP_USE_BLAS. Added SFSG macro. Added denominator in z-transform for frequency response of IIR filters. Added arbitrary fir design code. Put window types in a class in wrapper.

This commit is contained in:
Anne de Jong 2018-04-01 10:27:27 +02:00 committed by Anne de Jong
parent afd2b7d38a
commit 60cf046fa6
11 changed files with 36 additions and 43 deletions

View File

@ -84,13 +84,14 @@ set(CMAKE_C_FLAGS_RELEASE "-O2 -mfpmath=sse -march=x86-64 -mtune=native \
# set(CMAKE_C_FLAGS_RELEASE "-O2 -march=native -mtune=native -fomit-frame-pointer") # set(CMAKE_C_FLAGS_RELEASE "-O2 -march=native -mtune=native -fomit-frame-pointer")
if(LASP_USE_BLAS) if(LASP_USE_BLAS)
add_definitions(-DLASP_USE_BLAS=1) add_definitions(-DLASP_USE_BLAS=1)
else() else()
add_definitions(-DLASP_USE_BLAS=0) add_definitions(-DLASP_USE_BLAS=0)
endif(LASP_USE_BLAS) endif(LASP_USE_BLAS)
# ############################# End compilation flags
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(win32 true) set(win32 true)
else() else()
@ -103,10 +104,6 @@ if(DEFINED NUMPY_INCLUDE)
endif(DEFINED NUMPY_INCLUDE) endif(DEFINED NUMPY_INCLUDE)
# ############################# End compilation flags
add_subdirectory(fftpack) add_subdirectory(fftpack)
include_directories( include_directories(
fftpack fftpack

View File

@ -1,8 +1,6 @@
set(fftpack_src numpy/fftpack.c)
add_library(fftpack add_library(fftpack
fftpack.c fftpack.c
) )
target_link_libraries(fftpack m) target_link_libraries(fftpack m)

View File

@ -7,16 +7,13 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "lasp_alg.h" #include "lasp_alg.h"
void cmv_dot(const cmat* A,const vc* restrict x,vc* restrict b){ void cmv_dot(const cmat* A,const vc* restrict x,vc* restrict b){
dbgassert(A->n_rows == b->size,SIZEINEQUAL); dbgassert(A->n_rows == b->size,SIZEINEQUAL);
dbgassert(A->n_cols == x->size,SIZEINEQUAL); dbgassert(A->n_cols == x->size,SIZEINEQUAL);
#if LASP_USE_BLAS == 1 #if LASP_USE_BLAS == 1
dbgassert(false,"Untested function"); dbgassert(false,"Untested function. Is not functional for strides");
/* typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER; */ /* typedef enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER; */
/* typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE; */ /* typedef enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, CblasConjNoTrans=114} CBLAS_TRANSPOSE; */
/* /*
@ -121,7 +118,6 @@ lapack_int LAPACKE_zgels( int matrix_layout, char trans, lapack_int m,
/* int lsq_solve(const cmat* A,const vc* b,vc* x){ */ /* int lsq_solve(const cmat* A,const vc* b,vc* x){ */
/* POOL_INIT(lsq_solve_pool); */
/* int rv; */ /* int rv; */
/* /\* M: number of rows of matrix *\/ */ /* /\* M: number of rows of matrix *\/ */
/* /\* N: Number of columns *\/ */ /* /\* N: Number of columns *\/ */
@ -180,9 +176,6 @@ lapack_int LAPACKE_zgels( int matrix_layout, char trans, lapack_int m,
/* rv = FAILURE; */ /* rv = FAILURE; */
/* } */ /* } */
/* Pool_free(&lsq_solve_pool,A_data); */
/* Pool_free(&lsq_solve_pool,work_data); */
/* POOL_EXIT(lsq_solve_pool,15); */
/* return rv; */ /* return rv; */
/* } */ /* } */

View File

@ -5,7 +5,7 @@
// Description: // Description:
// Implementation of the dFifo queue // Implementation of the dFifo queue
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#define TRACERPLUS (-5) #define TRACERPLUS (-10)
#include "lasp_dfifo.h" #include "lasp_dfifo.h"
typedef struct dFifo_s { typedef struct dFifo_s {
@ -29,7 +29,7 @@ us dFifo_size(dFifo* fifo) {
* @param new_size * @param new_size
*/ */
static void dFifo_change_maxsize(dFifo* fifo,const us new_max_size) { static void dFifo_change_maxsize(dFifo* fifo,const us new_max_size) {
fsTRACE(30); fsTRACE(15);
dmat old_queue = fifo->queue; dmat old_queue = fifo->queue;
dbgassert(new_max_size >= dFifo_size(fifo),"BUG"); dbgassert(new_max_size >= dFifo_size(fifo),"BUG");
@ -49,7 +49,7 @@ static void dFifo_change_maxsize(dFifo* fifo,const us new_max_size) {
fifo->end_row -= fifo->start_row; fifo->end_row -= fifo->start_row;
fifo->start_row = 0; fifo->start_row = 0;
feTRACE(30); feTRACE(15);
} }
dFifo* dFifo_create(const us nchannels, dFifo* dFifo_create(const us nchannels,

View File

@ -5,6 +5,7 @@
// Description: // Description:
// FilterBank implementation. // FilterBank implementation.
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#define TRACERPLUS (-5)
#include "lasp_filterbank.h" #include "lasp_filterbank.h"
#include "lasp_fft.h" #include "lasp_fft.h"
#include "lasp_dfifo.h" #include "lasp_dfifo.h"
@ -154,7 +155,7 @@ dmat FilterBank_filter(FilterBank* fb,
dmat_free(&output_block); dmat_free(&output_block);
us samples_done = dFifo_size(output_fifo); us samples_done = dFifo_size(output_fifo);
uVARTRACE(20,samples_done); uVARTRACE(15,samples_done);
dmat filtered_result = dmat_alloc(samples_done,nfilters); dmat filtered_result = dmat_alloc(samples_done,nfilters);
if(samples_done) { if(samples_done) {
us samples_done2 = dFifo_pop(output_fifo,&filtered_result,0); us samples_done2 = dFifo_pop(output_fifo,&filtered_result,0);

View File

@ -115,9 +115,7 @@ static inline c* getcmatval(const cmat* mat,const us row,const us col){
dbgassert((vx)._data[(vx).size] == OVERFLOW_MAGIC_NUMBER, \ dbgassert((vx)._data[(vx).size] == OVERFLOW_MAGIC_NUMBER, \
"Buffer overflow detected on" #vx ); \ "Buffer overflow detected on" #vx ); \
} \ } \
else { \
DBGWARN("Cannot check overflow on foreign buffer"); \
}
#define check_overflow_xmat(xmat) \ #define check_overflow_xmat(xmat) \
TRACE(15,"Checking overflow " #xmat); \ TRACE(15,"Checking overflow " #xmat); \
@ -126,9 +124,6 @@ static inline c* getcmatval(const cmat* mat,const us row,const us col){
== OVERFLOW_MAGIC_NUMBER, \ == OVERFLOW_MAGIC_NUMBER, \
"Buffer overflow detected on" #xmat ); \ "Buffer overflow detected on" #xmat ); \
} \ } \
else { \
DBGWARN("Cannot check overflow on foreign buffer"); \
}
#else #else
#define check_overflow_vx(vx) #define check_overflow_vx(vx)

View File

@ -7,7 +7,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#define TRACERPLUS (-5) #define TRACERPLUS (-5)
#include "lasp_math_raw.h" #include "lasp_math_raw.h"
#if ASCEE_USE_BLAS #if LASP_USE_BLAS
#include <cblas.h> #include <cblas.h>
#endif #endif
@ -16,9 +16,9 @@ void d_elem_prod_d(d res[],
const d arr2[], const d arr2[],
const us size) { const us size) {
#if ASCEE_USE_BLAS == 1 #if LASP_USE_BLAS == 1
#if ASCEE_DEBUG #if LASP_DEBUG
if(arr1 == arr2) { if(arr1 == arr2) {
DBGWARN("d_elem_prod_d: Array 1 and array 2 point to the same" DBGWARN("d_elem_prod_d: Array 1 and array 2 point to the same"
@ -30,7 +30,7 @@ void d_elem_prod_d(d res[],
#endif #endif
#if ASCEE_DOUBLE_PRECISION #if LASP_DOUBLE_PRECISION
#define elem_prod_fun cblas_dsbmv #define elem_prod_fun cblas_dsbmv
#else #else
#define elem_prod_fun cblas_ssbmv #define elem_prod_fun cblas_ssbmv
@ -87,9 +87,9 @@ void c_hadamard(c res[],
uVARTRACE(15,size); uVARTRACE(15,size);
dbgassert(arr1 && arr2 && res,NULLPTRDEREF); dbgassert(arr1 && arr2 && res,NULLPTRDEREF);
#if ASCEE_USE_BLAS == 1 #if LASP_USE_BLAS == 1
#if ASCEE_DEBUG #if LASP_DEBUG
if(arr1 == arr2) { if(arr1 == arr2) {
DBGWARN("c_elem_prod_c: Array 1 and array 2 point to the same" DBGWARN("c_elem_prod_c: Array 1 and array 2 point to the same"
@ -98,10 +98,10 @@ void c_hadamard(c res[],
" unrealiable."); " unrealiable.");
} }
#endif /* ASCEE_DEBUG */ #endif /* LASP_DEBUG */
#if ASCEE_DOUBLE_PRECISION #if LASP_DOUBLE_PRECISION
#define elem_prod_fun cblas_zgbmv #define elem_prod_fun cblas_zgbmv
#else #else
#define elem_prod_fun cblas_cgbmv #define elem_prod_fun cblas_cgbmv

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#ifndef LASP_PYTHON_H #ifndef LASP_PYTHON_H
#define LASP_PYTHON_H #define LASP_PYTHON_H
#define TRACERPLUS (-5)
#include <numpy/ndarrayobject.h> #include <numpy/ndarrayobject.h>
#ifdef LASP_DOUBLE_PRECISION #ifdef LASP_DOUBLE_PRECISION
#define LASP_NUMPY_FLOAT_TYPE NPY_FLOAT64 #define LASP_NUMPY_FLOAT_TYPE NPY_FLOAT64

View File

@ -153,6 +153,8 @@ void uvartrace_impl(const char* pos,int line,const char* varname,size_t var);
trace_impl(FILEWITHOUTPATH,__LINE__,trace_string ); \ trace_impl(FILEWITHOUTPATH,__LINE__,trace_string ); \
} }
#define SFSG TRACE(100,"SFSG")
/** /**
* Print start of function string * Print start of function string
*/ */

View File

@ -9,16 +9,16 @@ frequency of 48 kHz.
#from asceefigs.plot import Bode, close, Figure #from asceefigs.plot import Bode, close, Figure
import numpy as np import numpy as np
from scipy.signal import freqz, hann from scipy.signal import freqz, hann, firwin2
from matplotlib.pyplot import figure, close from matplotlib.pyplot import figure, close
def freqResponse(fir_coefs, freq, fs): def freqResponse(fs, freq, fir_coefs_b, fir_coefs_a=1.):
"""! """!
Computes the frequency response of the filter defined with filter_coefs Computes the frequency response of the filter defined with filter_coefs
""" """
Omg = 2*np.pi*freq/fs Omg = 2*np.pi*freq/fs
w, H = freqz(fir_coefs,worN = Omg) w, H = freqz(fir_coefs_b,fir_coefs_a,worN = Omg)
return H return H
def bandpass_fir_design(L,fs,fl,fu, window = hann): def bandpass_fir_design(L,fs,fl,fu, window = hann):
@ -63,3 +63,8 @@ def lowpass_fir_design(L,fs,fc,window = hann):
return fir_win return fir_win
def arbitrary_fir_design(fs,L,freq,amps,window='hann'):
"""
Last frequency of freq should be fs/2
"""
return firwin2(L,freq,amps,fs=fs,window=window)

View File

@ -105,11 +105,12 @@ cdef extern from "lasp_window.h":
Blackman Blackman
# Export these constants to Python # Export these constants to Python
hann = Hann class Window:
hamming = Hamming hann = Hann
rectangular = Rectangular hamming = Hamming
bartlett = Bartlett rectangular = Rectangular
blackman = Blackman bartlett = Bartlett
blackman = Blackman
cdef extern from "lasp_ps.h": cdef extern from "lasp_ps.h":
ctypedef struct c_PowerSpectra "PowerSpectra" ctypedef struct c_PowerSpectra "PowerSpectra"
@ -127,7 +128,7 @@ cdef class PowerSpectra:
cdef: cdef:
c_PowerSpectra* _ps c_PowerSpectra* _ps
def __cinit__(self, us nfft,us window=rectangular): def __cinit__(self, us nfft,us window=Window.rectangular):
self._ps = PowerSpectra_alloc(nfft,<WindowType> window) self._ps = PowerSpectra_alloc(nfft,<WindowType> window)
if self._ps == NULL: if self._ps == NULL:
raise RuntimeError('PowerSpectra allocation failed') raise RuntimeError('PowerSpectra allocation failed')