1\subsection{Digital Signal Processing Routines} 2\label{group__dsp}\index{Digital Signal Processing Routines@{Digital Signal Processing Routines}} 3 4 5\subsubsection{Detailed Description} 6\label{group__dsp_dsp} 7 8 9This module contains the definitions for the digital signal processing routines for libbpm.\subsubsection{The digital filtering routines}\label{group__dsp_dsp_filtering} 10\paragraph{General usage}\label{group__dsp_dsp_filtering_usage} 11Setup a filter using the \doxyref{create\_\-filter()}{p.}{group__dsp_g9a69282273c256d3fd7481652b360b93} routine. 12 13\begin{Code}\begin{verbatim} filter_t *filter = create_filter( "the_filter", RESONATOR | , 0, 14 nsamples, 40.*kHz, 8.*kHz, 0., 200. ); 15\end{verbatim} 16\end{Code} 17 18 19 20The arguments the filter expects is a name for the filter (just for esthetic purposes when printing the filter), the filter options, which are explained below, the order of the filter, where it is meaning full (e.g. Butterworth, Bessel, Chebyshev). Then it needs the number of samples in the waveforms which will be filtered by this filter, the sampling frequency and one (optionally two) frequency parameter. For lowpass/highpass filters and the resonater, only the first frequency defines respectively the -3dB frequency level for the low/high pass and the resonance frequency for the resonator (the witdh is defined by the Q value in this case). For bandpass/stop filters the two frequencies are required and define the -3dB level which defines the bandwidth of the filter, with f1 being the lower end frequency and f2 the higher end. 21 22The implemented filters are :\begin{itemize} 23\item BESSEL : Bessel IIR filter\item BUTTERWORTH : Butterwordth IIR filter\item CHEBYSHEV : Chebyshev IIR filter\item RESONATOR : Resonators\item GAUSSIAN : Non-causal Gaussian FIR filter\end{itemize} 24 25 26The IIR Bessel, Butterworth and Chebyshev filters can be normalised as lowpass (option LOWPASS) which is the default, highpass (option HIGHPASS), bandstop (option BANDSTOP) or bandpass (option BANDPASS) filters. They are designed with poles and zeros in the s plane that are transformed to the z plane either by bilinear z transform (option BILINEAR\_\-Z\_\-TRANSFORM) or matched z transform (option MATCHED\_\-Z\_\-TRANSFORM). Just \char`\"{}OR\char`\"{} the options together to setup the filter, e.g. : 27 28 29 30\begin{Code}\begin{verbatim} filter_t *filter = create_filter( "lp", BESSEL | HIGHPASS | MATCHED_Z_TRANSFORM, 0, 31 ns, 40.*kHz, 8.*kHz, 0., 200. ); 32\end{verbatim} 33\end{Code} 34 35 36 37The resonators are designed directly with their 2 poles and 2 zeros in the z plane and can be normalised either as BANDPASS (default), BANDSTOP (or NOTCH) or ALLPASS resonators. 38 39The last argument to the \doxyref{create\_\-filter()}{p.}{group__dsp_g9a69282273c256d3fd7481652b360b93} routine is a parameter which can optionally be given to the filter. It depends on the filter chosen, currently the parameter has meaning for the following filters : 40 41\begin{itemize} 42\item BESSEL : the parameter defines the ripple in dB, has to be negative !\item RESONATOR : the parameter gives the Q value of the resonator, if you want to have a pure oscillator (so infinite Q), then set the parameter to a negative number or zero.\item GAUSSIAN : the filter cut-off parameter, or the fraction of the gaussian convolution function below which it is set to 0. (default is 0.001)\end{itemize} 43 44 45The filter coefficients for the difference equation are calculated and checked for consistency, upon which they are stored in the filter structure. Once this is done and the filter is setup, application to various waveforms is fairly straightforward. Note that you only have to define your filter once during initialisation. Once setup, it can be used to filter any number of waveforms of the same type. 46 47 48 49\begin{Code}\begin{verbatim} apply_filter( filter, wave ); 50\end{verbatim} 51\end{Code} 52 53 54 55To get an impulse response from the filter into the secified waveform, where the impulse is given at sample 1000, the following routine is implemented. 56 57 58 59\begin{Code}\begin{verbatim} filter_impulse_response( filter, wave, 1000 ); 60\end{verbatim} 61\end{Code} 62 63 64 65This routine creates an impulse function (zero everywhere, except at the sample you enter, where it's value is 1) and puts it through the filter. The FFT of this impulse response gives you the filter characteristic in frequency domain. Also you can check the filter's response to a step function, it's so-called step response : 66 67 68 69\begin{Code}\begin{verbatim} filter_step_response( filter, wave, 1000 ) 70\end{verbatim} 71\end{Code} 72 73 74 75The step response is defined as the response of the filter to an input function which is zero at the beginning and 1 for samples $>$= the sample you specify.\paragraph{The Bessel, Butterworth and Chebyshev filters}\label{group__dsp_dsp_filtering_bbc} 76\paragraph{The Resonator filter}\label{group__dsp_dsp_filtering_resonator} 77\paragraph{The gaussian filter}\label{group__dsp_dsp_filtering_gaus} 78The gaussian filter is implemented as a FIR convolution with both causal and anti-causal coefficients. Note that the frequency given is treated as the -3dB level for the gaussian. There is an option to restore the definition for bandwith which was used in early ESA processing, being the gaussian sigma, use GAUSSIAN\_\-SIGMA\_\-BW.\subsubsection{The Digital Downconversion Algorithm (DDC)}\label{group__dsp_dsp_ddc} 79The digital downconversion routine was developped to process digitised BPM waveforms and to retreive their position and amplitude. It basically implements an RF mixer in software. You need to supply it with the \doxyref{doublewf\_\-t}{p.}{structdoublewf__t} holding the waveform to mix down and the frequency for the software LO. Also you need to give a pointer to a low-pass filter in order to filter out the resulting double frequency component from the downmixing. The routine 80 81 82 83\begin{Code}\begin{verbatim} int ddc( doublewf_t *w, double f, filter_t *filter, complexwf_t *dcw ); 84\end{verbatim} 85\end{Code} 86 87 88 89returns then the complex DC waveform (dcw), where it's amplitude and phase can then be used in further calculations for beam position and slope in the BPM. We recommend the usage of a GAUSSIAN low-pass filter for the double frequency filtering as this shows the best phase behaviour combined with linearity (see \doxyref{create\_\-filter()}{p.}{group__dsp_g9a69282273c256d3fd7481652b360b93}). 90 91For fast execution, the DDC routine comes with a buffer which it only allocates once by doing 92 93 94 95\begin{Code}\begin{verbatim} ddc_initialise(); 96\end{verbatim} 97\end{Code} 98 99 100 101This buffer is used in the filtering routine, you can clean up after the execution of the buffer by having 102 103 104 105\begin{Code}\begin{verbatim} ddc_cleanup(); 106\end{verbatim} 107\end{Code} 108 109\subsubsection{Discrete (Fast) Fourier Transforms}\label{group__dsp_dsp_fft} 110The FFT routines in the dsp section of libbpm are based upon the General Purpose FFT Package by Takuya OOURA, 1996-2001, see {\tt http://www.kurims.kyoto-u.ac.jp/$\sim$ooura/fft.html} More specifically on it's split-radix fast version (fftsg). These set of routines needs a buffer for bitswapping an a buffer to store a table with sin and cos values so they needn't be calculated for every FFT. The routine 111 112 113 114\begin{Code}\begin{verbatim} fft_initialise( int ns ) 115\end{verbatim} 116\end{Code} 117 118 119 120intialises the buffers for waveforms of a certain sample length ns. Note that ns has to be a power of 2. You can clear the FFT buffers by issuing 121 122 123 124\begin{Code}\begin{verbatim} fft_cleanup( ); 125\end{verbatim} 126\end{Code} 127 128 129 130Then two wrapper routines are implemented which take \doxyref{doublewf\_\-t}{p.}{structdoublewf__t} and \doxyref{complexwf\_\-t}{p.}{structcomplexwf__t} data.\paragraph{Complex Discrete Fourier Transform}\label{group__dsp_dsp_fft_complex} 131The first one is 132 133 134 135\begin{Code}\begin{verbatim} int complexfft( complexwf_t *z, int fft_mode ); 136\end{verbatim} 137\end{Code} 138 139 140 141which takes a complex waveform and performs an FFT in place. The fft\_\-mode argument can be either\begin{itemize} 142\item FFT\_\-FORWARD : forward discrete Fourier transform (plus-sign)\end{itemize} 143 144 145\[ X[k] = \sum_{j=0}^{n-1} x[j]*\exp(2*\pi*i*j*k/n), 0<=k<n \] 146 147\begin{itemize} 148\item FFT\_\-BACKWARD : backward discrete Fourier transform (minus-sign)\end{itemize} 149 150 151\[ X[k] = \sum_{j=0}^{n-1} x[j]*\exp(-2*\pi*i*j*k/n), 0<=k<n \] 152 153Note the backward and forward FFT's have a factor of n inbetween them, so to get the orginal wf back after applying both the backward and the forward FFT, you need to divdide by the number of samples z-$>$n.\paragraph{Real Discrete Fourier Transform}\label{group__dsp_dsp_fft_real} 154The second routine implements the real discrete Fourier transform when having FFT\_\-FORWARD and the other way around when having FFT\_\-BACKWARD. 155 156 157 158\begin{Code}\begin{verbatim} int realfft( doublewf_t *y, int fft_mode, complexwf_t *z ); 159\end{verbatim} 160\end{Code} 161 162 163 164So for FFT\_\-FORWARD 165 166\[ Re( X[k] ) = \sum_{j=0}^{n-1} a[j]*\cos(2*\pi*j*k/n), 0<=k<=n/2 \] \[ Im( X[k] ) = \sum_{j=0}^{n-1} a[j]*\sin(2*\pi*j*k/n), 0<k<n/2 \] 167 168and FFT\_\-BACKWARD takes the input frmo the first half (n/2) of the \doxyref{complexwf\_\-t}{p.}{structcomplexwf__t} and FFTs it, expanding to a \doxyref{doublewf\_\-t}{p.}{structdoublewf__t} of length n. 169 170\[ X[k] = \frac{(Re(x[0]) + Re(x[n/2])*\cos(\pi*k) )}{2} + \sum_{j=1}^{n/2-1} Re(x[j])*\cos(2*\pi*j*k/n) + \sum_{j=1}^{n/2-1} Im(x[j])*\sin(2*\pi*j*k/n), 0<=k<n \]\paragraph{Reference for FFT routines}\label{group__dsp_dsp_fft_ref} 171\begin{itemize} 172\item Masatake MORI, Makoto NATORI, Tatuo TORII: Suchikeisan, Iwanamikouzajyouhoukagaku18, Iwanami, 1982 (Japanese)\item Henri J. Nussbaumer: Fast Fourier Transform and Convolution Algorithms, Springer Verlag, 1982\item C. S. Burrus, Notes on the FFT (with large FFT paper list) {\tt http://www-dsp.rice.edu/research/fft/fftnote.asc}\end{itemize} 173\paragraph{Copyright statement for FFT routines}\label{group__dsp_dsp_fft_copy} 174Copyright(C) 1996-2001 Takuya OOURA email: {\tt ooura@mmm.t.u-tokyo.ac.jp} download: {\tt http://momonga.t.u-tokyo.ac.jp/$\sim$ooura/fft.html} You may use, copy, modify this code for any purpose and without fee. You may distribute this ORIGINAL package.\subsubsection{DSP example program}\label{group__dsp_dsp_examples} 175There is an example program, which can be found in the examples directory under dsp. It shows how to work with the filtering and the DDC routines... 176 177 178 179\begin{Code}\begin{verbatim} #include <stdio.h> 180 #include <stdlib.h> 181 #include <string.h> 182 #include <math.h> 183 184 #include <iostream> 185 186 #include <TROOT.h> 187 #include <TFile.h> 188 #include <TTree.h> 189 190 #include <bpm/bpm_process.h> 191 #include <bpm/bpm_units.h> 192 #include <bpm/bpm_simulation.h> 193 #include <bpm/bpm_nr.h> 194 #include <bpm/bpm_rf.h> 195 #include <bpm/bpm_dsp.h> 196 #include <bpm/bpm_wf.h> 197 198 using namespace std; 199 200 int main( int argc, char **argv ) { 201 202 cout << "Welcome to the libbpm DSP sandbox" << endl; 203 204 int ns = 256; 205 double fs = 119.*MHz; 206 207 doublewf_t *w = doublewf( ns, fs ); 208 doublewf_t *s = doublewf_sample_series( ns, fs ); 209 210 doublewf_t *ddc_amp = doublewf( ns, fs ); 211 doublewf_t *ddc_phase = doublewf( ns, fs ); 212 213 // setup the root trees... 214 TFile *rootfile = new TFile( "dsp.root", "recreate" ); 215 TTree *roottree = new TTree( "dsp", "libbpm dsp tests" ); 216 217 int evt; 218 double amp, phase; 219 double gen_amp, gen_phase; 220 221 // setup the branches in the tree 222 roottree->Branch( "evt", &evt, "evt/I" ); 223 roottree->Branch( "wf", w->wf, "wf[256]/D" ); 224 roottree->Branch( "s", s->wf, "s[256]/D" ); 225 roottree->Branch( "gen_amp", &gen_amp, "gen_amp/D" ); 226 roottree->Branch( "gen_phase", &gen_phase, "gen_phase/D" ); 227 roottree->Branch( "ddc_amp", ddc_amp->wf, "ddc_amp[256]/D" ); 228 roottree->Branch( "ddc_phase", ddc_phase->wf, "ddc_phase[256]/D" ); 229 230 complexwf_t *ddcwf = complexwf( ns, fs ); 231 232 filter_t *gauss = create_filter( "gauss", GAUSSIAN,0,ns,fs,6.*MHz,0.,0.001); 233 filter_t *butter = create_filter( "butter", BUTTERWORTH | LOWPASS,4,ns,fs,6.*MHz,0.,0.); 234 filter_t *bessel = create_filter( "bessel", BESSEL | LOWPASS,4,ns, fs,6.*MHz,0., 0.); 235 filter_t *cheby = create_filter( "cheby", CHEBYSHEV | LOWPASS,4,ns,fs,6.*MHz,0.,-10.); 236 237 // init the DDC 238 ddc_initialise( ns, fs ); 239 240 for ( evt = 1; evt<=1000; evt++ ) { 241 242 // Make the waveform 243 gen_amp = (double) evt * 10.; 244 gen_phase = PI / (double) evt; 245 246 // reset the w to 0... quite important :D 247 doublewf_reset( w ); 248 249 doublewf_add_dcywave( w, gen_amp, gen_phase, 21.4*MHz, 0.15*usec, 0.2*usec, 0. ); 250 251 // do the DDC :) 252 if ( ddc( w, 21.4*MHz, gauss, ddcwf ) ) return 1; 253 254 // want to try differen filters ? 255 //if ( ddc( w, 21.4*MHz, butter, ddcwf ) ) return 1; 256 //if ( ddc( w, 21.4*MHz, bessel, ddcwf ) ) return 1; 257 //if ( ddc( w, 21.4*MHz, cheby, ddcwf ) ) return 1; 258 259 260 // get amplitude and phase from complex wf 261 complexwf_getamp( ddc_amp, ddcwf ); 262 complexwf_getphase( ddc_phase, ddcwf ); 263 264 // fill the tree... 265 roottree->Fill(); 266 267 if ( evt % 100 == 0 ) cout << "Simulated " << evt << " events." << endl; 268 } 269 270 // clear the DDC memory buffers 271 ddc_cleanup(); 272 273 rootfile->Write(); 274 rootfile->Close(); 275 276 delete_filter( gauss ); 277 delete_filter( butter ); 278 delete_filter( bessel); 279 delete_filter( cheby ); 280 281 complexwf_delete( ddcwf ); 282 283 doublewf_delete( w ); 284 doublewf_delete( s ); 285 doublewf_delete( ddc_amp ); 286 doublewf_delete( ddc_phase ); 287 288 return 0; 289 } 290\end{verbatim} 291\end{Code} 292 293 294 295\subsubsection*{Files} 296\begin{CompactItemize} 297\item 298file {\bf bpm\_\-dsp.h} 299\begin{CompactList}\small\item\em libbpm digital signal processing routines \item\end{CompactList} 300 301\item 302file {\bf calculate\_\-filter\_\-coefficients.c} 303\item 304file {\bf create\_\-filter.c} 305\item 306file {\bf create\_\-resonator\_\-representation.c} 307\item 308file {\bf create\_\-splane\_\-representation.c} 309\item 310file {\bf ddc.c} 311\item 312file {\bf delete\_\-filter.c} 313\item 314file {\bf discrete\_\-fourier\_\-transforms.c} 315\item 316file {\bf filter\_\-impulse\_\-response.c} 317\item 318file {\bf filter\_\-step\_\-response.c} 319\item 320file {\bf gaussian\_\-filter\_\-coeffs.c} 321\item 322file {\bf norm\_\-phase.c} 323\item 324file {\bf normalise\_\-filter.c} 325\item 326file {\bf print\_\-filter.c} 327\item 328file {\bf print\_\-filter\_\-representation.c} 329\item 330file {\bf zplane\_\-transform.c} 331\end{CompactItemize} 332\subsubsection*{Data Structures} 333\begin{CompactItemize} 334\item 335struct {\bf filterrep\_\-t} 336\item 337struct {\bf filter\_\-t} 338\end{CompactItemize} 339\subsubsection*{Defines} 340\begin{CompactItemize} 341\item 342\#define {\bf BESSEL} 343\item 344\#define {\bf BUTTERWORTH} 345\item 346\#define {\bf CHEBYSHEV} 347\item 348\#define {\bf RAISEDCOSINE} 349\item 350\#define {\bf RESONATOR} 351\item 352\#define {\bf GAUSSIAN} 353\item 354\#define {\bf BILINEAR\_\-Z\_\-TRANSFORM} 355\item 356\#define {\bf MATCHED\_\-Z\_\-TRANSFORM} 357\item 358\#define {\bf NO\_\-PREWARP} 359\item 360\#define {\bf CAUSAL} 361\item 362\#define {\bf ANTICAUSAL} 363\item 364\#define {\bf NONCAUSAL} 365\item 366\#define {\bf GAUSSIAN\_\-SIGMA\_\-BW} 367\item 368\#define {\bf LOWPASS} 369\item 370\#define {\bf HIGHPASS} 371\item 372\#define {\bf BANDPASS} 373\item 374\#define {\bf BANDSTOP} 375\item 376\#define {\bf NOTCH} 377\item 378\#define {\bf ALLPASS} 379\item 380\#define {\bf FIR} 381\item 382\#define {\bf IIR} 383\item 384\#define {\bf MAXORDER} 385\item 386\#define {\bf MAXPZ} 387\item 388\#define {\bf FILT\_\-EPS} 389\item 390\#define {\bf MAX\_\-RESONATOR\_\-ITER} 391\item 392\#define {\bf FFT\_\-FORWARD} 393\item 394\#define {\bf FFT\_\-BACKWARD} 395\end{CompactItemize} 396\subsubsection*{Functions} 397\begin{CompactItemize} 398\item 399EXTERN {\bf filter\_\-t} $\ast$ {\bf create\_\-filter} (char name[$\,$], unsigned int options, int order, int ns, double fs, double f1, double f2, double par) 400\item 401EXTERN int {\bf apply\_\-filter} ({\bf filter\_\-t} $\ast$f, {\bf doublewf\_\-t} $\ast$w) 402\item 403EXTERN void {\bf print\_\-filter} (FILE $\ast$of, {\bf filter\_\-t} $\ast$f) 404\item 405EXTERN void {\bf delete\_\-filter} ({\bf filter\_\-t} $\ast$f) 406\item 407EXTERN int {\bf filter\_\-step\_\-response} ({\bf filter\_\-t} $\ast$f, {\bf doublewf\_\-t} $\ast$w, int itrig) 408\item 409EXTERN int {\bf filter\_\-impulse\_\-response} ({\bf filter\_\-t} $\ast$f, {\bf doublewf\_\-t} $\ast$w, int itrig) 410\item 411EXTERN {\bf filterrep\_\-t} $\ast$ {\bf create\_\-splane\_\-representation} ({\bf filter\_\-t} $\ast$f) 412\item 413EXTERN {\bf filterrep\_\-t} $\ast$ {\bf create\_\-resonator\_\-representation} ({\bf filter\_\-t} $\ast$f) 414\item 415EXTERN {\bf filterrep\_\-t} $\ast$ {\bf zplane\_\-transform} ({\bf filter\_\-t} $\ast$f, {\bf filterrep\_\-t} $\ast$s) 416\item 417EXTERN void {\bf print\_\-filter\_\-representation} (FILE $\ast$of, {\bf filterrep\_\-t} $\ast$r) 418\item 419EXTERN int {\bf normalise\_\-filter} ({\bf filter\_\-t} $\ast$f, {\bf filterrep\_\-t} $\ast$s) 420\item 421EXTERN int {\bf calculate\_\-filter\_\-coefficients} ({\bf filter\_\-t} $\ast$f) 422\item 423EXTERN int {\bf gaussian\_\-filter\_\-coeffs} ({\bf filter\_\-t} $\ast$f) 424\item 425EXTERN int {\bf \_\-expand\_\-complex\_\-polynomial} ({\bf complex\_\-t} $\ast$w, int n, {\bf complex\_\-t} $\ast$a) 426\item 427EXTERN {\bf complex\_\-t} {\bf \_\-eval\_\-complex\_\-polynomial} ({\bf complex\_\-t} $\ast$a, int n, {\bf complex\_\-t} z) 428\item 429EXTERN int {\bf ddc\_\-initialise} (int ns, double fs) 430\item 431EXTERN void {\bf ddc\_\-cleanup} (void) 432\item 433int {\bf ddc} ({\bf doublewf\_\-t} $\ast$w, double f, {\bf filter\_\-t} $\ast$filter, {\bf complexwf\_\-t} $\ast$dcw, {\bf doublewf\_\-t} $\ast$bufre, {\bf doublewf\_\-t} $\ast$bufim) 434\item 435EXTERN int {\bf fft\_\-gen\_\-tables} (void) 436\item 437EXTERN int {\bf fft\_\-initialise} (int ns) 438\item 439EXTERN void {\bf fft\_\-cleanup} (void) 440\item 441EXTERN int {\bf complexfft} ({\bf complexwf\_\-t} $\ast$z, int fft\_\-mode) 442\item 443EXTERN int {\bf realfft} ({\bf doublewf\_\-t} $\ast$y, int fft\_\-mode, {\bf complexwf\_\-t} $\ast$z) 444\item 445EXTERN void {\bf norm\_\-phase} (double $\ast$phase) 446\end{CompactItemize} 447 448 449\subsubsection{Define Documentation} 450\index{dsp@{dsp}!BESSEL@{BESSEL}} 451\index{BESSEL@{BESSEL}!dsp@{dsp}} 452\paragraph[BESSEL]{\setlength{\rightskip}{0pt plus 5cm}\#define BESSEL}\hfill\label{group__dsp_ga1703a42f41a941e1b8542e2aa7725b8} 453 454 455Bitmask for Bessel filter 456 457Definition at line 384 of file bpm\_\-dsp.h. 458 459Referenced by create\_\-filter(), and create\_\-splane\_\-representation().\index{dsp@{dsp}!BUTTERWORTH@{BUTTERWORTH}} 460\index{BUTTERWORTH@{BUTTERWORTH}!dsp@{dsp}} 461\paragraph[BUTTERWORTH]{\setlength{\rightskip}{0pt plus 5cm}\#define BUTTERWORTH}\hfill\label{group__dsp_g5d0a54629b87a77272d7979fa69eb0f4} 462 463 464Bitmask for Butterworth filter 465 466Definition at line 385 of file bpm\_\-dsp.h. 467 468Referenced by create\_\-filter(), and create\_\-splane\_\-representation().\index{dsp@{dsp}!CHEBYSHEV@{CHEBYSHEV}} 469\index{CHEBYSHEV@{CHEBYSHEV}!dsp@{dsp}} 470\paragraph[CHEBYSHEV]{\setlength{\rightskip}{0pt plus 5cm}\#define CHEBYSHEV}\hfill\label{group__dsp_g8d2af0f448fbf14aae730419d05e9aae} 471 472 473Bitmask for Chebyshev filter 474 475Definition at line 386 of file bpm\_\-dsp.h. 476 477Referenced by create\_\-filter(), and create\_\-splane\_\-representation().\index{dsp@{dsp}!RAISEDCOSINE@{RAISEDCOSINE}} 478\index{RAISEDCOSINE@{RAISEDCOSINE}!dsp@{dsp}} 479\paragraph[RAISEDCOSINE]{\setlength{\rightskip}{0pt plus 5cm}\#define RAISEDCOSINE}\hfill\label{group__dsp_gad132a516e77ed236f2fc783d4a0a76a} 480 481 482Bitmask for Raised Cosine filter 483 484Definition at line 387 of file bpm\_\-dsp.h.\index{dsp@{dsp}!RESONATOR@{RESONATOR}} 485\index{RESONATOR@{RESONATOR}!dsp@{dsp}} 486\paragraph[RESONATOR]{\setlength{\rightskip}{0pt plus 5cm}\#define RESONATOR}\hfill\label{group__dsp_gfe7637a70564a23668795435de22932c} 487 488 489Bitmask for Resonator filter 490 491Definition at line 388 of file bpm\_\-dsp.h. 492 493Referenced by create\_\-filter(), and get\_\-mode\_\-response().\index{dsp@{dsp}!GAUSSIAN@{GAUSSIAN}} 494\index{GAUSSIAN@{GAUSSIAN}!dsp@{dsp}} 495\paragraph[GAUSSIAN]{\setlength{\rightskip}{0pt plus 5cm}\#define GAUSSIAN}\hfill\label{group__dsp_gd751f1b6909c0124a4ca151036b28a0e} 496 497 498Bitmask for Gaussian filter 499 500Definition at line 389 of file bpm\_\-dsp.h. 501 502Referenced by create\_\-filter().\index{dsp@{dsp}!BILINEAR\_\-Z\_\-TRANSFORM@{BILINEAR\_\-Z\_\-TRANSFORM}} 503\index{BILINEAR\_\-Z\_\-TRANSFORM@{BILINEAR\_\-Z\_\-TRANSFORM}!dsp@{dsp}} 504\paragraph[BILINEAR\_\-Z\_\-TRANSFORM]{\setlength{\rightskip}{0pt plus 5cm}\#define BILINEAR\_\-Z\_\-TRANSFORM}\hfill\label{group__dsp_g2b8825fbaecce70ee62e88c392c3a5cc} 505 506 507Get z poles via bilinear z transform from s plane 508 509Definition at line 391 of file bpm\_\-dsp.h.\index{dsp@{dsp}!MATCHED\_\-Z\_\-TRANSFORM@{MATCHED\_\-Z\_\-TRANSFORM}} 510\index{MATCHED\_\-Z\_\-TRANSFORM@{MATCHED\_\-Z\_\-TRANSFORM}!dsp@{dsp}} 511\paragraph[MATCHED\_\-Z\_\-TRANSFORM]{\setlength{\rightskip}{0pt plus 5cm}\#define MATCHED\_\-Z\_\-TRANSFORM}\hfill\label{group__dsp_g3760e0e98d0cc986cc0cd5ad69f327c8} 512 513 514Get z poles via matches z transform from s plane 515 516Definition at line 392 of file bpm\_\-dsp.h. 517 518Referenced by zplane\_\-transform().\index{dsp@{dsp}!NO\_\-PREWARP@{NO\_\-PREWARP}} 519\index{NO\_\-PREWARP@{NO\_\-PREWARP}!dsp@{dsp}} 520\paragraph[NO\_\-PREWARP]{\setlength{\rightskip}{0pt plus 5cm}\#define NO\_\-PREWARP}\hfill\label{group__dsp_g00c885f3fbae267b1a194a1451c6c0fd} 521 522 523Don't do the prewarp correction 524 525Definition at line 393 of file bpm\_\-dsp.h. 526 527Referenced by create\_\-filter().\index{dsp@{dsp}!CAUSAL@{CAUSAL}} 528\index{CAUSAL@{CAUSAL}!dsp@{dsp}} 529\paragraph[CAUSAL]{\setlength{\rightskip}{0pt plus 5cm}\#define CAUSAL}\hfill\label{group__dsp_g1325d477c181914de6e34377f85e1782} 530 531 532Filter is purely causal (only depends on past ) 533 534Definition at line 394 of file bpm\_\-dsp.h. 535 536Referenced by apply\_\-filter(), create\_\-filter(), and print\_\-filter().\index{dsp@{dsp}!ANTICAUSAL@{ANTICAUSAL}} 537\index{ANTICAUSAL@{ANTICAUSAL}!dsp@{dsp}} 538\paragraph[ANTICAUSAL]{\setlength{\rightskip}{0pt plus 5cm}\#define ANTICAUSAL}\hfill\label{group__dsp_g7ac031f6a8bf39034b82cb3910c5ae64} 539 540 541.... purely anticausal (only depends on future) 542 543Definition at line 395 of file bpm\_\-dsp.h. 544 545Referenced by apply\_\-filter(), and print\_\-filter().\index{dsp@{dsp}!NONCAUSAL@{NONCAUSAL}} 546\index{NONCAUSAL@{NONCAUSAL}!dsp@{dsp}} 547\paragraph[NONCAUSAL]{\setlength{\rightskip}{0pt plus 5cm}\#define NONCAUSAL}\hfill\label{group__dsp_g1ca4ab5665f98b5fa329196b585a591d} 548 549 550Filter is both causal and acausal 551 552Definition at line 396 of file bpm\_\-dsp.h. 553 554Referenced by create\_\-filter().\index{dsp@{dsp}!GAUSSIAN\_\-SIGMA\_\-BW@{GAUSSIAN\_\-SIGMA\_\-BW}} 555\index{GAUSSIAN\_\-SIGMA\_\-BW@{GAUSSIAN\_\-SIGMA\_\-BW}!dsp@{dsp}} 556\paragraph[GAUSSIAN\_\-SIGMA\_\-BW]{\setlength{\rightskip}{0pt plus 5cm}\#define GAUSSIAN\_\-SIGMA\_\-BW}\hfill\label{group__dsp_g542c0ef4de56e474ddde83cf0f4c7f75} 557 558 559Gaussian sigma bandwidth in stead of -3 dB (def) 560 561Definition at line 397 of file bpm\_\-dsp.h. 562 563Referenced by gaussian\_\-filter\_\-coeffs().\index{dsp@{dsp}!LOWPASS@{LOWPASS}} 564\index{LOWPASS@{LOWPASS}!dsp@{dsp}} 565\paragraph[LOWPASS]{\setlength{\rightskip}{0pt plus 5cm}\#define LOWPASS}\hfill\label{group__dsp_gb88b316b336dadc6e77f04d6f035d86e} 566 567 568Normalise filter as lowpass 569 570Definition at line 399 of file bpm\_\-dsp.h. 571 572Referenced by calculate\_\-filter\_\-coefficients(), and normalise\_\-filter().\index{dsp@{dsp}!HIGHPASS@{HIGHPASS}} 573\index{HIGHPASS@{HIGHPASS}!dsp@{dsp}} 574\paragraph[HIGHPASS]{\setlength{\rightskip}{0pt plus 5cm}\#define HIGHPASS}\hfill\label{group__dsp_gb55942c743e16f6629ad144214ced198} 575 576 577Normalise filter as highpass 578 579Definition at line 400 of file bpm\_\-dsp.h. 580 581Referenced by calculate\_\-filter\_\-coefficients(), and normalise\_\-filter().\index{dsp@{dsp}!BANDPASS@{BANDPASS}} 582\index{BANDPASS@{BANDPASS}!dsp@{dsp}} 583\paragraph[BANDPASS]{\setlength{\rightskip}{0pt plus 5cm}\#define BANDPASS}\hfill\label{group__dsp_g3ebfa4d7e384f53e6a37ff0d0d98627d} 584 585 586Normalise filter as bandpass 587 588Definition at line 401 of file bpm\_\-dsp.h. 589 590Referenced by calculate\_\-filter\_\-coefficients(), get\_\-mode\_\-response(), and normalise\_\-filter().\index{dsp@{dsp}!BANDSTOP@{BANDSTOP}} 591\index{BANDSTOP@{BANDSTOP}!dsp@{dsp}} 592\paragraph[BANDSTOP]{\setlength{\rightskip}{0pt plus 5cm}\#define BANDSTOP}\hfill\label{group__dsp_g889ef557cbf5adfd002eab3f69d59a4c} 593 594 595Normalise filter as bandstop 596 597Definition at line 402 of file bpm\_\-dsp.h. 598 599Referenced by calculate\_\-filter\_\-coefficients(), create\_\-resonator\_\-representation(), and normalise\_\-filter().\index{dsp@{dsp}!NOTCH@{NOTCH}} 600\index{NOTCH@{NOTCH}!dsp@{dsp}} 601\paragraph[NOTCH]{\setlength{\rightskip}{0pt plus 5cm}\#define NOTCH}\hfill\label{group__dsp_gfc5c94321c320b7db339b511e6905cce} 602 603 604Normalise filter as notch filter (=bandstop) 605 606Definition at line 403 of file bpm\_\-dsp.h.\index{dsp@{dsp}!ALLPASS@{ALLPASS}} 607\index{ALLPASS@{ALLPASS}!dsp@{dsp}} 608\paragraph[ALLPASS]{\setlength{\rightskip}{0pt plus 5cm}\#define ALLPASS}\hfill\label{group__dsp_g88cf96ad30a3bdf745ac7cc883b4cc25} 609 610 611Normalise filter as allpass ( resonator ) 612 613Definition at line 404 of file bpm\_\-dsp.h. 614 615Referenced by create\_\-resonator\_\-representation().\index{dsp@{dsp}!FIR@{FIR}} 616\index{FIR@{FIR}!dsp@{dsp}} 617\paragraph[FIR]{\setlength{\rightskip}{0pt plus 5cm}\#define FIR}\hfill\label{group__dsp_g34e4945cab9dbce5d535cd599409014d} 618 619 620Filter is of FIR type 621 622Definition at line 406 of file bpm\_\-dsp.h. 623 624Referenced by apply\_\-filter(), and create\_\-filter().\index{dsp@{dsp}!IIR@{IIR}} 625\index{IIR@{IIR}!dsp@{dsp}} 626\paragraph[IIR]{\setlength{\rightskip}{0pt plus 5cm}\#define IIR}\hfill\label{group__dsp_g67004975983f9c99226d63db17ba74c4} 627 628 629Filter is of IIR type 630 631Definition at line 407 of file bpm\_\-dsp.h. 632 633Referenced by create\_\-filter().\index{dsp@{dsp}!MAXORDER@{MAXORDER}} 634\index{MAXORDER@{MAXORDER}!dsp@{dsp}} 635\paragraph[MAXORDER]{\setlength{\rightskip}{0pt plus 5cm}\#define MAXORDER}\hfill\label{group__dsp_g623810946946d9e0d69affd3906871cf} 636 637 638Maximum filter order 639 640Definition at line 409 of file bpm\_\-dsp.h.\index{dsp@{dsp}!MAXPZ@{MAXPZ}} 641\index{MAXPZ@{MAXPZ}!dsp@{dsp}} 642\paragraph[MAXPZ]{\setlength{\rightskip}{0pt plus 5cm}\#define MAXPZ}\hfill\label{group__dsp_ge6099fd066a0d0ccea7af9a725451cdd} 643 644 645Maximum number of poles and zeros $>$2$\ast$MAXORDER 646 647Definition at line 410 of file bpm\_\-dsp.h. 648 649Referenced by calculate\_\-filter\_\-coefficients(), create\_\-resonator\_\-representation(), and gaussian\_\-filter\_\-coeffs().\index{dsp@{dsp}!FILT\_\-EPS@{FILT\_\-EPS}} 650\index{FILT\_\-EPS@{FILT\_\-EPS}!dsp@{dsp}} 651\paragraph[FILT\_\-EPS]{\setlength{\rightskip}{0pt plus 5cm}\#define FILT\_\-EPS}\hfill\label{group__dsp_g7782897f56b1db64e9aef60d5fcb8867} 652 653 654A small number used in bpmdsp 655 656Definition at line 411 of file bpm\_\-dsp.h. 657 658Referenced by \_\-expand\_\-complex\_\-polynomial(), create\_\-resonator\_\-representation(), and print\_\-filter().\index{dsp@{dsp}!MAX\_\-RESONATOR\_\-ITER@{MAX\_\-RESONATOR\_\-ITER}} 659\index{MAX\_\-RESONATOR\_\-ITER@{MAX\_\-RESONATOR\_\-ITER}!dsp@{dsp}} 660\paragraph[MAX\_\-RESONATOR\_\-ITER]{\setlength{\rightskip}{0pt plus 5cm}\#define MAX\_\-RESONATOR\_\-ITER}\hfill\label{group__dsp_g7eeaec212ff7b30e0f1aaea1f75090d2} 661 662 663Maximum iterations in resonator poles calculation 664 665Definition at line 412 of file bpm\_\-dsp.h. 666 667Referenced by create\_\-resonator\_\-representation().\index{dsp@{dsp}!FFT\_\-FORWARD@{FFT\_\-FORWARD}} 668\index{FFT\_\-FORWARD@{FFT\_\-FORWARD}!dsp@{dsp}} 669\paragraph[FFT\_\-FORWARD]{\setlength{\rightskip}{0pt plus 5cm}\#define FFT\_\-FORWARD}\hfill\label{group__dsp_g7769d6eabe1e3ec538cf182e453b0e9c} 670 671 672Perform FFT from time -$>$ frequency 673 674Definition at line 414 of file bpm\_\-dsp.h. 675 676Referenced by complexfft(), fft\_\-waveform(), and realfft().\index{dsp@{dsp}!FFT\_\-BACKWARD@{FFT\_\-BACKWARD}} 677\index{FFT\_\-BACKWARD@{FFT\_\-BACKWARD}!dsp@{dsp}} 678\paragraph[FFT\_\-BACKWARD]{\setlength{\rightskip}{0pt plus 5cm}\#define FFT\_\-BACKWARD}\hfill\label{group__dsp_g5fcdb491cd42667dc09e79aa17caea60} 679 680 681Perform FFT from frequency -$>$ time 682 683Definition at line 415 of file bpm\_\-dsp.h. 684 685Referenced by complexfft(), and realfft(). 686 687\subsubsection{Function Documentation} 688\index{dsp@{dsp}!create\_\-filter@{create\_\-filter}} 689\index{create\_\-filter@{create\_\-filter}!dsp@{dsp}} 690\paragraph[create\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}EXTERN {\bf filter\_\-t}$\ast$ create\_\-filter (char {\em name}[$\,$], \/ unsigned int {\em options}, \/ int {\em order}, \/ int {\em ns}, \/ double {\em fs}, \/ double {\em f1}, \/ double {\em f2}, \/ double {\em par})}\hfill\label{group__dsp_g9a69282273c256d3fd7481652b360b93} 691 692 693Creates the filter. \begin{Desc} 694\item[Parameters:] 695\begin{description} 696\item[{\em name}]a name for the filter \item[{\em options}]filter specification and options bitword \item[{\em order}]filter order \item[{\em ns}]number of samples of the waveforms \item[{\em fs}]sampling frequency \item[{\em f1}]first frequency \item[{\em f2}]optional second frequency ( bandpass/bandstop ) \item[{\em par}]optional parameter\begin{itemize} 697\item for chebyshev : ripple in dB\item for resonator : Q factor \end{itemize} 698\end{description} 699\end{Desc} 700\begin{Desc} 701\item[Returns:]A pointer to the created filter structure, memory is allocated on the heap inside this routine, the user has to take of deleting it using \doxyref{delete\_\-filter()}{p.}{group__dsp_g182f6ed138d07cce1940be6c7dc7d843}. \end{Desc} 702 703 704Definition at line 10 of file create\_\-filter.c. 705 706References filter\_\-t::alpha1, filter\_\-t::alpha2, BESSEL, bpm\_\-error(), bpm\_\-warning(), BUTTERWORTH, calculate\_\-filter\_\-coefficients(), CAUSAL, filter\_\-t::cheb\_\-ripple, CHEBYSHEV, filter\_\-t::cplane, create\_\-resonator\_\-representation(), create\_\-splane\_\-representation(), filter\_\-t::f1, filter\_\-t::f2, FIR, filter\_\-t::fs, filter\_\-t::gauss\_\-cutoff, GAUSSIAN, gaussian\_\-filter\_\-coeffs(), IIR, filter\_\-t::name, NO\_\-PREWARP, NONCAUSAL, normalise\_\-filter(), filterrep\_\-t::npoles, filter\_\-t::ns, filter\_\-t::options, filter\_\-t::order, filter\_\-t::Q, RESONATOR, filter\_\-t::w\_\-alpha1, filter\_\-t::w\_\-alpha2, filter\_\-t::wfbuffer, filter\_\-t::yc, and zplane\_\-transform(). 707 708Referenced by get\_\-mode\_\-response().\index{dsp@{dsp}!apply\_\-filter@{apply\_\-filter}} 709\index{apply\_\-filter@{apply\_\-filter}!dsp@{dsp}} 710\paragraph[apply\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int apply\_\-filter ({\bf filter\_\-t} $\ast$ {\em f}, \/ {\bf doublewf\_\-t} $\ast$ {\em w})}\hfill\label{group__dsp_g06e897b615044a7169dc84b8eb4a7cfc} 711 712 713Apply the filter to the given waveform. Note that the filter is applied in place, the user has to make a copy of the waveform if he/she wants to keep the original before applying the filter. The number of samples in the waveform has to be set in advance when creating the filter, it is stored in the filter structure (f-$>$ns). 714 715\begin{Desc} 716\item[Parameters:] 717\begin{description} 718\item[{\em f}]pointer to a filter that was created using create\_\-filter \item[{\em wf}]an array containing the waveform to be filtered \end{description} 719\end{Desc} 720\begin{Desc} 721\item[Returns:]BPM\_\-SUCCESS upon success and BPM\_\-FAILURE upon failure \end{Desc} 722 723 724Definition at line 19 of file apply\_\-filter.c. 725 726References ANTICAUSAL, bpm\_\-error(), CAUSAL, FIR, filter\_\-t::gain, filter\_\-t::ns, filter\_\-t::nxc, filter\_\-t::nxc\_\-ac, filter\_\-t::nyc, filter\_\-t::options, doublewf\_\-t::wf, filter\_\-t::wfbuffer, filter\_\-t::xc, filter\_\-t::xc\_\-ac, filter\_\-t::xv, filter\_\-t::xv\_\-ac, filter\_\-t::yc, filter\_\-t::yv, and filter\_\-t::yv\_\-ac. 727 728Referenced by ddc(), filter\_\-impulse\_\-response(), filter\_\-step\_\-response(), generate\_\-diodesignal(), and get\_\-mode\_\-response().\index{dsp@{dsp}!print\_\-filter@{print\_\-filter}} 729\index{print\_\-filter@{print\_\-filter}!dsp@{dsp}} 730\paragraph[print\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}EXTERN void print\_\-filter (FILE $\ast$ {\em of}, \/ {\bf filter\_\-t} $\ast$ {\em f})}\hfill\label{group__dsp_gb1dc802390cc2794e545a635b833e819} 731 732 733Prints the filter to the given file pointer. \begin{Desc} 734\item[Parameters:] 735\begin{description} 736\item[{\em of}]the filepointer, use \char`\"{}stdout\char`\"{} to print to the terminal \item[{\em f}]the filter to be printed \end{description} 737\end{Desc} 738\begin{Desc} 739\item[Returns:]void \end{Desc} 740 741 742Definition at line 8 of file print\_\-filter.c. 743 744References ANTICAUSAL, bpm\_\-error(), CAUSAL, filter\_\-t::cplane, filter\_\-t::dc\_\-gain, filter\_\-t::fc\_\-gain, FILT\_\-EPS, filter\_\-t::gain, filter\_\-t::hf\_\-gain, filter\_\-t::name, filter\_\-t::nxc, filter\_\-t::nxc\_\-ac, filter\_\-t::nyc, filter\_\-t::options, print\_\-filter\_\-representation(), filter\_\-t::xc, filter\_\-t::xc\_\-ac, and filter\_\-t::yc.\index{dsp@{dsp}!delete\_\-filter@{delete\_\-filter}} 745\index{delete\_\-filter@{delete\_\-filter}!dsp@{dsp}} 746\paragraph[delete\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}EXTERN void delete\_\-filter ({\bf filter\_\-t} $\ast$ {\em f})}\hfill\label{group__dsp_g182f6ed138d07cce1940be6c7dc7d843} 747 748 749Clears the memory that was allocated on the heap for the filter f. \begin{Desc} 750\item[Parameters:] 751\begin{description} 752\item[{\em f}]a pointer to the filter \end{description} 753\end{Desc} 754\begin{Desc} 755\item[Returns:]void \end{Desc} 756 757 758Definition at line 7 of file delete\_\-filter.c. 759 760References filter\_\-t::cplane, and filter\_\-t::wfbuffer. 761 762Referenced by get\_\-mode\_\-response().\index{dsp@{dsp}!filter\_\-step\_\-response@{filter\_\-step\_\-response}} 763\index{filter\_\-step\_\-response@{filter\_\-step\_\-response}!dsp@{dsp}} 764\paragraph[filter\_\-step\_\-response]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int filter\_\-step\_\-response ({\bf filter\_\-t} $\ast$ {\em f}, \/ {\bf doublewf\_\-t} $\ast$ {\em w}, \/ int {\em itrig})}\hfill\label{group__dsp_g8ffa4c94e6673b1a73fe7266f1321e44} 765 766 767This routine fills the given wf with the step response of the filter. The step response is defined as wf[i] = 0. for i $<$ itrig and wf[i] = 1. for i $>$= itrig. 768 769\begin{Desc} 770\item[Parameters:] 771\begin{description} 772\item[{\em f}]a pointer to the filter to use \item[{\em wf}]pointer to a waveform which will be overwritten with the step response \item[{\em itrig}]the sample number in the waveform which will have the step \end{description} 773\end{Desc} 774\begin{Desc} 775\item[Returns:]BPM\_\-SUCCESS upon succes and BPM\_\-FAILURE upon failure \end{Desc} 776 777 778Produces a stepresponse for the filter, step is defined by the trigger sample number the starting level and the endlevel 779 780Definition at line 8 of file filter\_\-step\_\-response.c. 781 782References apply\_\-filter(), bpm\_\-error(), filter\_\-t::ns, and doublewf\_\-t::wf.\index{dsp@{dsp}!filter\_\-impulse\_\-response@{filter\_\-impulse\_\-response}} 783\index{filter\_\-impulse\_\-response@{filter\_\-impulse\_\-response}!dsp@{dsp}} 784\paragraph[filter\_\-impulse\_\-response]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int filter\_\-impulse\_\-response ({\bf filter\_\-t} $\ast$ {\em f}, \/ {\bf doublewf\_\-t} $\ast$ {\em w}, \/ int {\em itrig})}\hfill\label{group__dsp_gf12c84bb45e297f3bb0799341298942c} 785 786 787This routine fills the given wf with the impulse response of the filter. The impulse response is defined as wf[i] = 1. for i == itrig and wf[i] = 0. elsewhere. 788 789\begin{Desc} 790\item[Parameters:] 791\begin{description} 792\item[{\em f}]a pointer to the filter to use \item[{\em wf}]pointer to a waveform which will be overwritten with the impulse response \item[{\em itrig}]the sample number in the waveform which will have the impulse \end{description} 793\end{Desc} 794\begin{Desc} 795\item[Returns:]BPM\_\-SUCCESS upon succes and BPM\_\-FAILURE upon failure \end{Desc} 796 797 798Produces an impulse response for the filter, step is defined by the trigger sample number the starting level and the endlevel 799 800Definition at line 7 of file filter\_\-impulse\_\-response.c. 801 802References apply\_\-filter(), bpm\_\-error(), filter\_\-t::ns, and doublewf\_\-t::wf.\index{dsp@{dsp}!create\_\-splane\_\-representation@{create\_\-splane\_\-representation}} 803\index{create\_\-splane\_\-representation@{create\_\-splane\_\-representation}!dsp@{dsp}} 804\paragraph[create\_\-splane\_\-representation]{\setlength{\rightskip}{0pt plus 5cm}EXTERN {\bf filterrep\_\-t}$\ast$ create\_\-splane\_\-representation ({\bf filter\_\-t} $\ast$ {\em f})}\hfill\label{group__dsp_g22c12acc1f0031b41236dd009182f0b3} 805 806 807This routine returns a pointer to a filter representation \doxyref{filterrep\_\-t}{p.}{structfilterrep__t} in the s plane for Butterworth, Chebyshev and Bessel filters. It need an initialised filter structure which has the filter type and the order set. Memory is allocated for this routine on the heap, so the user is responsible to delete this memory using free(). 808 809\begin{Desc} 810\item[Parameters:] 811\begin{description} 812\item[{\em f}]the initialised filter with the correct options in f-$>$options \end{description} 813\end{Desc} 814\begin{Desc} 815\item[Returns:]the filter representation in the s plane \end{Desc} 816 817 818Definition at line 32 of file create\_\-splane\_\-representation.c. 819 820References BESSEL, bpm\_\-error(), BUTTERWORTH, filter\_\-t::cheb\_\-ripple, CHEBYSHEV, filterrep\_\-t::npoles, filter\_\-t::options, filter\_\-t::order, and filterrep\_\-t::pole. 821 822Referenced by create\_\-filter().\index{dsp@{dsp}!create\_\-resonator\_\-representation@{create\_\-resonator\_\-representation}} 823\index{create\_\-resonator\_\-representation@{create\_\-resonator\_\-representation}!dsp@{dsp}} 824\paragraph[create\_\-resonator\_\-representation]{\setlength{\rightskip}{0pt plus 5cm}EXTERN {\bf filterrep\_\-t}$\ast$ create\_\-resonator\_\-representation ({\bf filter\_\-t} $\ast$ {\em f})}\hfill\label{group__dsp_g21615df94a81d7f49ebab1b94843b796} 825 826 827This routine returns a pointer to a filter representation \doxyref{filterrep\_\-t}{p.}{structfilterrep__t} in the z plane for resonance filters. It needs an initialised filter structure which has the filter type and the Q factor set. Memory is allocated for this routine on the heap, so the user is responsible to delete this memory using free(). 828 829\begin{Desc} 830\item[Parameters:] 831\begin{description} 832\item[{\em f}]the initialised filter with the correct options in f-$>$options \end{description} 833\end{Desc} 834\begin{Desc} 835\item[Returns:]the filter representation in the z plane \end{Desc} 836 837 838Definition at line 15 of file create\_\-resonator\_\-representation.c. 839 840References \_\-eval\_\-complex\_\-polynomial(), \_\-expand\_\-complex\_\-polynomial(), ALLPASS, filter\_\-t::alpha1, BANDSTOP, bpm\_\-error(), FILT\_\-EPS, complex\_\-t::im, MAX\_\-RESONATOR\_\-ITER, MAXPZ, filterrep\_\-t::npoles, filterrep\_\-t::nzeros, filter\_\-t::options, filterrep\_\-t::pole, filter\_\-t::Q, complex\_\-t::re, and filterrep\_\-t::zero. 841 842Referenced by create\_\-filter().\index{dsp@{dsp}!zplane\_\-transform@{zplane\_\-transform}} 843\index{zplane\_\-transform@{zplane\_\-transform}!dsp@{dsp}} 844\paragraph[zplane\_\-transform]{\setlength{\rightskip}{0pt plus 5cm}EXTERN {\bf filterrep\_\-t}$\ast$ zplane\_\-transform ({\bf filter\_\-t} $\ast$ {\em f}, \/ {\bf filterrep\_\-t} $\ast$ {\em s})}\hfill\label{group__dsp_g56db3510d9bcff5794866f57edf626f8} 845 846 847This routine transforms the poles and zeros for Bessel, Chebyshev and Butterworth filters to the z plane either via matched z transform or bilinear z transform. This is set in f-$>$options. Memory is allocated for this routine on the heap, so the user is responsible to delete this memory using free(). 848 849\begin{Desc} 850\item[Parameters:] 851\begin{description} 852\item[{\em f}]the filter, needs the options from it to check how to transform \item[{\em s}]filter s plane poles and zeros \end{description} 853\end{Desc} 854\begin{Desc} 855\item[Returns:]a pointer to the z plane representation \end{Desc} 856 857 858Definition at line 8 of file zplane\_\-transform.c. 859 860References bpm\_\-error(), MATCHED\_\-Z\_\-TRANSFORM, filterrep\_\-t::npoles, filterrep\_\-t::nzeros, filter\_\-t::options, filterrep\_\-t::pole, and filterrep\_\-t::zero. 861 862Referenced by create\_\-filter().\index{dsp@{dsp}!print\_\-filter\_\-representation@{print\_\-filter\_\-representation}} 863\index{print\_\-filter\_\-representation@{print\_\-filter\_\-representation}!dsp@{dsp}} 864\paragraph[print\_\-filter\_\-representation]{\setlength{\rightskip}{0pt plus 5cm}EXTERN void print\_\-filter\_\-representation (FILE $\ast$ {\em of}, \/ {\bf filterrep\_\-t} $\ast$ {\em r})}\hfill\label{group__dsp_g77d84f27e5a88390cd5f263249256958} 865 866 867Prints the filter representation in terms of poles and zeros to the filepointer. \begin{Desc} 868\item[Parameters:] 869\begin{description} 870\item[{\em of}]the filepointer, use \char`\"{}stdout\char`\"{} to print to the terminal \item[{\em r}]the filter representation to be printed \end{description} 871\end{Desc} 872\begin{Desc} 873\item[Returns:]void \end{Desc} 874 875 876Display filter representation 877 878Definition at line 8 of file print\_\-filter\_\-representation.c. 879 880References filterrep\_\-t::npoles, filterrep\_\-t::nzeros, filterrep\_\-t::pole, and filterrep\_\-t::zero. 881 882Referenced by print\_\-filter().\index{dsp@{dsp}!normalise\_\-filter@{normalise\_\-filter}} 883\index{normalise\_\-filter@{normalise\_\-filter}!dsp@{dsp}} 884\paragraph[normalise\_\-filter]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int normalise\_\-filter ({\bf filter\_\-t} $\ast$ {\em f}, \/ {\bf filterrep\_\-t} $\ast$ {\em s})}\hfill\label{group__dsp_g086b8f12f06df3ac5d3892c6c378346c} 885 886 887Normalises the Butterworth, Chebyshev or Bessel filters to be Bandpass/stop or Low/Highpass \begin{Desc} 888\item[Parameters:] 889\begin{description} 890\item[{\em f}]the filter \item[{\em s}]the filter's representation in the s plane \end{description} 891\end{Desc} 892\begin{Desc} 893\item[Returns:]BPM\_\-SUCCESS upon success or BPM\_\-FAILURE upon failure. \end{Desc} 894 895 896Definition at line 7 of file normalise\_\-filter.c. 897 898References BANDPASS, BANDSTOP, bpm\_\-error(), HIGHPASS, LOWPASS, filterrep\_\-t::npoles, filterrep\_\-t::nzeros, filter\_\-t::options, filterrep\_\-t::pole, filter\_\-t::w\_\-alpha1, filter\_\-t::w\_\-alpha2, and filterrep\_\-t::zero. 899 900Referenced by create\_\-filter().\index{dsp@{dsp}!calculate\_\-filter\_\-coefficients@{calculate\_\-filter\_\-coefficients}} 901\index{calculate\_\-filter\_\-coefficients@{calculate\_\-filter\_\-coefficients}!dsp@{dsp}} 902\paragraph[calculate\_\-filter\_\-coefficients]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int calculate\_\-filter\_\-coefficients ({\bf filter\_\-t} $\ast$ {\em f})}\hfill\label{group__dsp_gd51e74023863f312dc8f78143203cdda} 903 904 905Calculates the filter coefficients from the z plane representation for Butterworth, Chebyshev, Bessel and Resonators. Before this routine is called, one has to make sure that the member cplane, which holds a pointer to the filter's representation in the complex plane is set. This routine than calculates the filter coefficients and stores them in f-$>$xc ( coefficients of x[n], x[n-1], x[n-2]...) and f-$>$yc ( coefficients of y[n-1], y[n-2], y[n-3], ... in case of IIR filters ). 906 907\begin{Desc} 908\item[Parameters:] 909\begin{description} 910\item[{\em f}]the filter, having it's f-$>$cplane member set to the z plan representation \end{description} 911\end{Desc} 912\begin{Desc} 913\item[Returns:]BPM\_\-SUCCESS upon success or BPM\_\-FAILURE upon failure. \end{Desc} 914 915 916Calculates the filter coefficients from the poles and zeros in the cplane representation... Also calculates the filter gains... 917 918Definition at line 56 of file calculate\_\-filter\_\-coefficients.c. 919 920References \_\-eval\_\-complex\_\-polynomial(), \_\-expand\_\-complex\_\-polynomial(), filter\_\-t::alpha1, filter\_\-t::alpha2, BANDPASS, BANDSTOP, filter\_\-t::cplane, filter\_\-t::dc\_\-gain, filter\_\-t::fc\_\-gain, filter\_\-t::gain, filter\_\-t::hf\_\-gain, HIGHPASS, LOWPASS, MAXPZ, filterrep\_\-t::npoles, filter\_\-t::nxc, filter\_\-t::nyc, filterrep\_\-t::nzeros, filter\_\-t::options, filterrep\_\-t::pole, filter\_\-t::xc, filter\_\-t::yc, and filterrep\_\-t::zero. 921 922Referenced by create\_\-filter().\index{dsp@{dsp}!gaussian\_\-filter\_\-coeffs@{gaussian\_\-filter\_\-coeffs}} 923\index{gaussian\_\-filter\_\-coeffs@{gaussian\_\-filter\_\-coeffs}!dsp@{dsp}} 924\paragraph[gaussian\_\-filter\_\-coeffs]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int gaussian\_\-filter\_\-coeffs ({\bf filter\_\-t} $\ast$ {\em f})}\hfill\label{group__dsp_ga890982cd403efa5e312ab0877021d16} 925 926 927Calculates the gaussian filter coefficients from the original gaussian filter implementation in the digital downconversion algortithm in Yury's code. Note that this filter is implemented as a FIR non-causal filter. \begin{Desc} 928\item[Parameters:] 929\begin{description} 930\item[{\em f}]the filter structure with the coefficients to fill \end{description} 931\end{Desc} 932\begin{Desc} 933\item[Returns:]BPM\_\-SUCCESS upon success or BPM\_\-FAILURE upon failure. \end{Desc} 934 935 936Definition at line 8 of file gaussian\_\-filter\_\-coeffs.c. 937 938References bpm\_\-error(), dround(), filter\_\-t::f1, filter\_\-t::fs, filter\_\-t::gain, filter\_\-t::gauss\_\-cutoff, GAUSSIAN\_\-SIGMA\_\-BW, MAXPZ, filter\_\-t::ns, filter\_\-t::nxc, filter\_\-t::nxc\_\-ac, filter\_\-t::options, filter\_\-t::xc, and filter\_\-t::xc\_\-ac. 939 940Referenced by create\_\-filter().\index{dsp@{dsp}!\_\-expand\_\-complex\_\-polynomial@{\_\-expand\_\-complex\_\-polynomial}} 941\index{\_\-expand\_\-complex\_\-polynomial@{\_\-expand\_\-complex\_\-polynomial}!dsp@{dsp}} 942\paragraph[\_\-expand\_\-complex\_\-polynomial]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int \_\-expand\_\-complex\_\-polynomial ({\bf complex\_\-t} $\ast$ {\em w}, \/ int {\em n}, \/ {\bf complex\_\-t} $\ast$ {\em a})}\hfill\label{group__dsp_gf174b4706cf2aa8dc8223d21e10b066a} 943 944 945Helper routine to expand a complex polynomial from a set of zeros. \begin{Desc} 946\item[Parameters:] 947\begin{description} 948\item[{\em w}]array of complex zeros for the polynomial \item[{\em n}]nunber of zeros \item[{\em a}]array of coeffiecients for the polynomial that is returned \end{description} 949\end{Desc} 950\begin{Desc} 951\item[Returns:]BPM\_\-SUCCESS upon success or BPM\_\-FAILURE upon failure. \end{Desc} 952 953 954Calculate the polynomial coefficients in a0 + a1 $\ast$ z + a2 $\ast$ z$^\wedge$2 + a3 $\ast$ z$^\wedge$3 + ... = (z-w1)(z-w2)(z-w3)... from the n polynomial's zero's \char`\"{}w\char`\"{} returns the results in a, the array of coefficients... 955 956Definition at line 8 of file calculate\_\-filter\_\-coefficients.c. 957 958References bpm\_\-error(), and FILT\_\-EPS. 959 960Referenced by calculate\_\-filter\_\-coefficients(), and create\_\-resonator\_\-representation().\index{dsp@{dsp}!\_\-eval\_\-complex\_\-polynomial@{\_\-eval\_\-complex\_\-polynomial}} 961\index{\_\-eval\_\-complex\_\-polynomial@{\_\-eval\_\-complex\_\-polynomial}!dsp@{dsp}} 962\paragraph[\_\-eval\_\-complex\_\-polynomial]{\setlength{\rightskip}{0pt plus 5cm}EXTERN {\bf complex\_\-t} \_\-eval\_\-complex\_\-polynomial ({\bf complex\_\-t} $\ast$ {\em a}, \/ int {\em n}, \/ {\bf complex\_\-t} {\em z})}\hfill\label{group__dsp_gaa71bf94e489845a3c6f193146eecd51} 963 964 965Helper routine to evaluate a complex polynomial for value z \begin{Desc} 966\item[Parameters:] 967\begin{description} 968\item[{\em a}]array of coeffiecients for the polynomial that is returned \item[{\em n}]number of zeros \item[{\em z}]the value for which to evalute the polynomial \end{description} 969\end{Desc} 970\begin{Desc} 971\item[Returns:]the value of the polynomial for z ( \doxyref{complex\_\-t}{p.}{structcomplex__t} ) \end{Desc} 972 973 974Definition at line 44 of file calculate\_\-filter\_\-coefficients.c. 975 976Referenced by calculate\_\-filter\_\-coefficients(), and create\_\-resonator\_\-representation().\index{dsp@{dsp}!ddc\_\-initialise@{ddc\_\-initialise}} 977\index{ddc\_\-initialise@{ddc\_\-initialise}!dsp@{dsp}} 978\paragraph[ddc\_\-initialise]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int ddc\_\-initialise (int {\em ns}, \/ double {\em fs})}\hfill\label{group__dsp_gf449577391d3318d8434c5533e35336e} 979 980 981Initialises and allocates memory for the DDC buffers with the correct number of samples and sampling frequency \begin{Desc} 982\item[Parameters:] 983\begin{description} 984\item[{\em ns}]Nuber of samples in waveforms to be processed \item[{\em fs}]The sampling frequency of the waveforms \end{description} 985\end{Desc} 986\begin{Desc} 987\item[Returns:]BPM\_\-SUCCESS upon success, BPM\_\-FAILURE upon failure \end{Desc} 988 989 990Definition at line 50 of file ddc.c. 991 992References bpm\_\-error(), and doublewf().\index{dsp@{dsp}!ddc\_\-cleanup@{ddc\_\-cleanup}} 993\index{ddc\_\-cleanup@{ddc\_\-cleanup}!dsp@{dsp}} 994\paragraph[ddc\_\-cleanup]{\setlength{\rightskip}{0pt plus 5cm}EXTERN void ddc\_\-cleanup (void)}\hfill\label{group__dsp_g86ecee7954632e5f6588fab658ad57e4} 995 996 997Clears up and frees the buffer memory for the ddc routines 998 999Definition at line 70 of file ddc.c. 1000 1001References doublewf\_\-delete().\index{dsp@{dsp}!ddc@{ddc}} 1002\index{ddc@{ddc}!dsp@{dsp}} 1003\paragraph[ddc]{\setlength{\rightskip}{0pt plus 5cm}int ddc ({\bf doublewf\_\-t} $\ast$ {\em w}, \/ double {\em f}, \/ {\bf filter\_\-t} $\ast$ {\em filter}, \/ {\bf complexwf\_\-t} $\ast$ {\em dcw}, \/ {\bf doublewf\_\-t} $\ast$ {\em bufre}, \/ {\bf doublewf\_\-t} $\ast$ {\em bufim})}\hfill\label{group__dsp_g9d8c64898ae5afc694d20c3b7224f728} 1004 1005 1006Do a digital downconversion on the waveform f. The routine returns a complex DC waveform \char`\"{}wdc\char`\"{}. If the buffer arguments are NULL pointers, the DDC routine will use an internal buffer. This is a good option when all the BPMs in the system have the same sampling frequency and number of samples. \begin{Desc} 1007\item[Parameters:] 1008\begin{description} 1009\item[{\em w}]The waveform of doubles to process \item[{\em f}]The frequency of the digital local oscillator \item[{\em filter}]The lowpass filter to get rid of the 2omega component \item[{\em dcw}]The complex DC waveform \item[{\em bufre}]The real ddc buffer \item[{\em bufim}]The imaginary ddc buffer \end{description} 1010\end{Desc} 1011\begin{Desc} 1012\item[Returns:]BPM\_\-SUCCESS upon success, BPM\_\-FAILURE upon failure \end{Desc} 1013 1014 1015Definition at line 78 of file ddc.c. 1016 1017References apply\_\-filter(), complexwf\_\-setimag(), complexwf\_\-setreal(), doublewf\_\-t::fs, complexwf\_\-t::fs, doublewf\_\-t::ns, complexwf\_\-t::ns, and doublewf\_\-t::wf. 1018 1019Referenced by ddc\_\-waveform().\index{dsp@{dsp}!fft\_\-gen\_\-tables@{fft\_\-gen\_\-tables}} 1020\index{fft\_\-gen\_\-tables@{fft\_\-gen\_\-tables}!dsp@{dsp}} 1021\paragraph[fft\_\-gen\_\-tables]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int fft\_\-gen\_\-tables (void)}\hfill\label{group__dsp_g0044b20270242b942305a7a8308751fa} 1022 1023 1024Regenerates the sin/cos tables that are needed for the fast DFT algorithm. 1025 1026Definition at line 116 of file discrete\_\-fourier\_\-transforms.c. 1027 1028References bpm\_\-error(). 1029 1030Referenced by fft\_\-initialise().\index{dsp@{dsp}!fft\_\-initialise@{fft\_\-initialise}} 1031\index{fft\_\-initialise@{fft\_\-initialise}!dsp@{dsp}} 1032\paragraph[fft\_\-initialise]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int fft\_\-initialise (int {\em ns})}\hfill\label{group__dsp_gfc4c99bc5d39d6b118e1ccd629bc0967} 1033 1034 1035This one initialised the FFT buffers, checks whether they are large enough for the given number of samples and frees and re-allocates memory where necessary \begin{Desc} 1036\item[Parameters:] 1037\begin{description} 1038\item[{\em ns}]The number of samples in the waveforms to be transformed \end{description} 1039\end{Desc} 1040\begin{Desc} 1041\item[Returns:]BPM\_\-SUCCESS upon succes, BPM\_\-FAILURE upon failure \end{Desc} 1042 1043 1044Definition at line 130 of file discrete\_\-fourier\_\-transforms.c. 1045 1046References bpm\_\-error(), and fft\_\-gen\_\-tables().\index{dsp@{dsp}!fft\_\-cleanup@{fft\_\-cleanup}} 1047\index{fft\_\-cleanup@{fft\_\-cleanup}!dsp@{dsp}} 1048\paragraph[fft\_\-cleanup]{\setlength{\rightskip}{0pt plus 5cm}EXTERN void fft\_\-cleanup (void)}\hfill\label{group__dsp_gc994a163e29de65a3d7eaee79c91f6a7} 1049 1050 1051This routine frees up the memory used by the FFT buffers 1052 1053Definition at line 163 of file discrete\_\-fourier\_\-transforms.c.\index{dsp@{dsp}!complexfft@{complexfft}} 1054\index{complexfft@{complexfft}!dsp@{dsp}} 1055\paragraph[complexfft]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int complexfft ({\bf complexwf\_\-t} $\ast$ {\em z}, \/ int {\em fft\_\-mode})}\hfill\label{group__dsp_g1c5a7dc710dd12ebdb8418623d0a3a91} 1056 1057 1058Executes a complex fast fourier transform in line. See the reference guide for details. \begin{Desc} 1059\item[Parameters:] 1060\begin{description} 1061\item[{\em z}]The complex waveform to transform (original waveform is destroyed) Note that the number of samples need to be a power of 2. \item[{\em fft\_\-mode}]Specifies whether to do the forward or backward transform \end{description} 1062\end{Desc} 1063\begin{Desc} 1064\item[Returns:]BPM\_\-SUCCESS upon succes, BPM\_\-FAILURE upon failure \end{Desc} 1065 1066 1067Definition at line 178 of file discrete\_\-fourier\_\-transforms.c. 1068 1069References bpm\_\-error(), bpm\_\-warning(), FFT\_\-BACKWARD, FFT\_\-FORWARD, complex\_\-t::im, complexwf\_\-t::ns, complex\_\-t::re, and complexwf\_\-t::wf.\index{dsp@{dsp}!realfft@{realfft}} 1070\index{realfft@{realfft}!dsp@{dsp}} 1071\paragraph[realfft]{\setlength{\rightskip}{0pt plus 5cm}EXTERN int realfft ({\bf doublewf\_\-t} $\ast$ {\em y}, \/ int {\em fft\_\-mode}, \/ {\bf complexwf\_\-t} $\ast$ {\em z})}\hfill\label{group__dsp_g897fcf096d8b347969edcba67759d83e} 1072 1073 1074Executes a real fast fourier transform, between the real waveform y and the complex waveform z. See documentation for further explanation. \begin{Desc} 1075\item[Parameters:] 1076\begin{description} 1077\item[{\em y}]Pointer to the real wavefrom \item[{\em fft\_\-mode}]Specifies whether to do the forward or backward transform \item[{\em z}]Pointer to the complex waveform \end{description} 1078\end{Desc} 1079\begin{Desc} 1080\item[Returns:]BPM\_\-SUCCESS upon succes, BPM\_\-FAILURE upon failure \end{Desc} 1081 1082 1083Definition at line 230 of file discrete\_\-fourier\_\-transforms.c. 1084 1085References bpm\_\-error(), bpm\_\-warning(), FFT\_\-BACKWARD, FFT\_\-FORWARD, complex\_\-t::im, complexwf\_\-t::ns, complex\_\-t::re, complexwf\_\-t::wf, and doublewf\_\-t::wf. 1086 1087Referenced by fft\_\-waveform().\index{dsp@{dsp}!norm\_\-phase@{norm\_\-phase}} 1088\index{norm\_\-phase@{norm\_\-phase}!dsp@{dsp}} 1089\paragraph[norm\_\-phase]{\setlength{\rightskip}{0pt plus 5cm}EXTERN void norm\_\-phase (double $\ast$ {\em phase})}\hfill\label{group__dsp_g42ddaa15fe4fde56ada52d19ec786e8a} 1090 1091 1092Normalises the phase, to the interval [0,2pi[ \begin{Desc} 1093\item[Parameters:] 1094\begin{description} 1095\item[{\em phase}]Pointer to the phase value to normalise \end{description} 1096\end{Desc} 1097 1098 1099Definition at line 8 of file norm\_\-phase.c. 1100 1101Referenced by complexwf\_\-getphase(), complexwf\_\-getphase\_\-new(), postprocess\_\-waveform(), process\_\-caltone(), and process\_\-waveform().