From 60cf046fa61829661170f919ddddbba1f8b2499c Mon Sep 17 00:00:00 2001 From: "J.A. de Jong" Date: Sun, 1 Apr 2018 10:27:27 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 7 ++----- fftpack/CMakeLists.txt | 2 -- lasp/c/lasp_alg.c | 9 +-------- lasp/c/lasp_dfifo.c | 6 +++--- lasp/c/lasp_filterbank.c | 3 ++- lasp/c/lasp_math.h | 7 +------ lasp/c/lasp_math_raw.c | 16 ++++++++-------- lasp/c/lasp_python.h | 1 + lasp/c/lasp_tracer.h | 2 ++ lasp/fir_design/fir_design.py | 13 +++++++++---- lasp/wrappers.pyx | 13 +++++++------ 11 files changed, 36 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 834f2ee..8805377 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") - if(LASP_USE_BLAS) add_definitions(-DLASP_USE_BLAS=1) else() add_definitions(-DLASP_USE_BLAS=0) endif(LASP_USE_BLAS) +# ############################# End compilation flags + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(win32 true) else() @@ -103,10 +104,6 @@ if(DEFINED NUMPY_INCLUDE) endif(DEFINED NUMPY_INCLUDE) - - -# ############################# End compilation flags - add_subdirectory(fftpack) include_directories( fftpack diff --git a/fftpack/CMakeLists.txt b/fftpack/CMakeLists.txt index 5c4f22b..ea8dec1 100644 --- a/fftpack/CMakeLists.txt +++ b/fftpack/CMakeLists.txt @@ -1,8 +1,6 @@ -set(fftpack_src numpy/fftpack.c) add_library(fftpack fftpack.c ) - target_link_libraries(fftpack m) diff --git a/lasp/c/lasp_alg.c b/lasp/c/lasp_alg.c index 1bd70a9..a51e300 100644 --- a/lasp/c/lasp_alg.c +++ b/lasp/c/lasp_alg.c @@ -7,16 +7,13 @@ ////////////////////////////////////////////////////////////////////// #include "lasp_alg.h" - - - void cmv_dot(const cmat* A,const vc* restrict x,vc* restrict b){ dbgassert(A->n_rows == b->size,SIZEINEQUAL); dbgassert(A->n_cols == x->size,SIZEINEQUAL); #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_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){ */ -/* POOL_INIT(lsq_solve_pool); */ /* int rv; */ /* /\* M: number of rows of matrix *\/ */ /* /\* N: Number of columns *\/ */ @@ -180,9 +176,6 @@ lapack_int LAPACKE_zgels( int matrix_layout, char trans, lapack_int m, /* rv = FAILURE; */ /* } */ -/* Pool_free(&lsq_solve_pool,A_data); */ -/* Pool_free(&lsq_solve_pool,work_data); */ -/* POOL_EXIT(lsq_solve_pool,15); */ /* return rv; */ /* } */ diff --git a/lasp/c/lasp_dfifo.c b/lasp/c/lasp_dfifo.c index 0965922..d5e2e0e 100644 --- a/lasp/c/lasp_dfifo.c +++ b/lasp/c/lasp_dfifo.c @@ -5,7 +5,7 @@ // Description: // Implementation of the dFifo queue ////////////////////////////////////////////////////////////////////// -#define TRACERPLUS (-5) +#define TRACERPLUS (-10) #include "lasp_dfifo.h" typedef struct dFifo_s { @@ -29,7 +29,7 @@ us dFifo_size(dFifo* fifo) { * @param new_size */ static void dFifo_change_maxsize(dFifo* fifo,const us new_max_size) { - fsTRACE(30); + fsTRACE(15); dmat old_queue = fifo->queue; 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->start_row = 0; - feTRACE(30); + feTRACE(15); } dFifo* dFifo_create(const us nchannels, diff --git a/lasp/c/lasp_filterbank.c b/lasp/c/lasp_filterbank.c index 65b7b6c..10a1a89 100644 --- a/lasp/c/lasp_filterbank.c +++ b/lasp/c/lasp_filterbank.c @@ -5,6 +5,7 @@ // Description: // FilterBank implementation. ////////////////////////////////////////////////////////////////////// +#define TRACERPLUS (-5) #include "lasp_filterbank.h" #include "lasp_fft.h" #include "lasp_dfifo.h" @@ -154,7 +155,7 @@ dmat FilterBank_filter(FilterBank* fb, dmat_free(&output_block); us samples_done = dFifo_size(output_fifo); - uVARTRACE(20,samples_done); + uVARTRACE(15,samples_done); dmat filtered_result = dmat_alloc(samples_done,nfilters); if(samples_done) { us samples_done2 = dFifo_pop(output_fifo,&filtered_result,0); diff --git a/lasp/c/lasp_math.h b/lasp/c/lasp_math.h index dc03761..bf83baf 100644 --- a/lasp/c/lasp_math.h +++ b/lasp/c/lasp_math.h @@ -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, \ "Buffer overflow detected on" #vx ); \ } \ - else { \ - DBGWARN("Cannot check overflow on foreign buffer"); \ - } + #define check_overflow_xmat(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, \ "Buffer overflow detected on" #xmat ); \ } \ - else { \ - DBGWARN("Cannot check overflow on foreign buffer"); \ - } #else #define check_overflow_vx(vx) diff --git a/lasp/c/lasp_math_raw.c b/lasp/c/lasp_math_raw.c index a01978b..196895a 100644 --- a/lasp/c/lasp_math_raw.c +++ b/lasp/c/lasp_math_raw.c @@ -7,7 +7,7 @@ ////////////////////////////////////////////////////////////////////// #define TRACERPLUS (-5) #include "lasp_math_raw.h" -#if ASCEE_USE_BLAS +#if LASP_USE_BLAS #include #endif @@ -16,9 +16,9 @@ void d_elem_prod_d(d res[], const d arr2[], const us size) { - #if ASCEE_USE_BLAS == 1 + #if LASP_USE_BLAS == 1 - #if ASCEE_DEBUG + #if LASP_DEBUG if(arr1 == arr2) { 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 - #if ASCEE_DOUBLE_PRECISION + #if LASP_DOUBLE_PRECISION #define elem_prod_fun cblas_dsbmv #else #define elem_prod_fun cblas_ssbmv @@ -87,9 +87,9 @@ void c_hadamard(c res[], uVARTRACE(15,size); dbgassert(arr1 && arr2 && res,NULLPTRDEREF); - #if ASCEE_USE_BLAS == 1 + #if LASP_USE_BLAS == 1 - #if ASCEE_DEBUG + #if LASP_DEBUG if(arr1 == arr2) { DBGWARN("c_elem_prod_c: Array 1 and array 2 point to the same" @@ -98,10 +98,10 @@ void c_hadamard(c res[], " unrealiable."); } - #endif /* ASCEE_DEBUG */ + #endif /* LASP_DEBUG */ - #if ASCEE_DOUBLE_PRECISION + #if LASP_DOUBLE_PRECISION #define elem_prod_fun cblas_zgbmv #else #define elem_prod_fun cblas_cgbmv diff --git a/lasp/c/lasp_python.h b/lasp/c/lasp_python.h index 286a286..8eb64e0 100644 --- a/lasp/c/lasp_python.h +++ b/lasp/c/lasp_python.h @@ -8,6 +8,7 @@ #pragma once #ifndef LASP_PYTHON_H #define LASP_PYTHON_H +#define TRACERPLUS (-5) #include #ifdef LASP_DOUBLE_PRECISION #define LASP_NUMPY_FLOAT_TYPE NPY_FLOAT64 diff --git a/lasp/c/lasp_tracer.h b/lasp/c/lasp_tracer.h index d89ade5..b6d5889 100644 --- a/lasp/c/lasp_tracer.h +++ b/lasp/c/lasp_tracer.h @@ -153,6 +153,8 @@ void uvartrace_impl(const char* pos,int line,const char* varname,size_t var); trace_impl(FILEWITHOUTPATH,__LINE__,trace_string ); \ } +#define SFSG TRACE(100,"SFSG") + /** * Print start of function string */ diff --git a/lasp/fir_design/fir_design.py b/lasp/fir_design/fir_design.py index dcb449a..6470b09 100644 --- a/lasp/fir_design/fir_design.py +++ b/lasp/fir_design/fir_design.py @@ -9,16 +9,16 @@ frequency of 48 kHz. #from asceefigs.plot import Bode, close, Figure import numpy as np -from scipy.signal import freqz, hann +from scipy.signal import freqz, hann, firwin2 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 """ 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 def bandpass_fir_design(L,fs,fl,fu, window = hann): @@ -62,4 +62,9 @@ def lowpass_fir_design(L,fs,fc,window = hann): fir_win = fir*win return fir_win - \ No newline at end of file + +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) \ No newline at end of file diff --git a/lasp/wrappers.pyx b/lasp/wrappers.pyx index 9e90049..6035acb 100644 --- a/lasp/wrappers.pyx +++ b/lasp/wrappers.pyx @@ -105,11 +105,12 @@ cdef extern from "lasp_window.h": Blackman # Export these constants to Python -hann = Hann -hamming = Hamming -rectangular = Rectangular -bartlett = Bartlett -blackman = Blackman +class Window: + hann = Hann + hamming = Hamming + rectangular = Rectangular + bartlett = Bartlett + blackman = Blackman cdef extern from "lasp_ps.h": ctypedef struct c_PowerSpectra "PowerSpectra" @@ -127,7 +128,7 @@ cdef class PowerSpectra: cdef: 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, window) if self._ps == NULL: raise RuntimeError('PowerSpectra allocation failed')