8/11/2019 k omega.PDF
1/27
1
V S I P L F o r u m
k-Omega Beamforming Example
Randall JuddSSC-SD
619 553 3086 judd@ spawar.navy.mil
8/11/2019 k omega.PDF
2/27
2
V S I P L F o r u m
k-Omega Example
Include Simple k-Omega beamformer Simple data generator A parameter file input method Methods to output data and to create a simple image
Demonstrates Early Binding FFT Random FIR Filters View manipulation using support functions
8/11/2019 k omega.PDF
3/27
3
V S I P L F o r u m
A very brief introduction to k-Omegabeamforming
r
k = 2 ( )cos( )e x +sin( )e y( )i =0L Nsens 1rri = x ie x =i Dsens e x
p(t ,r
r ) = po exp jr
k r
r( )exp j 2 ft ( )n
=0L Nts
1
t n =n Fs propagating wave
k r
ir r
sensor
Nsens => Number of sensors
Nts => Length of time series sample
Fs => Sample rate
p i,n = po exp jx i2
cos ( ) exp jt n 2 f ( )
xe
Dsens => Sensor spacing
k => wave number
p => pressure
DISCLAIMER: This is a brief, probably not entirelycorrect, beamforming explanation. For better information see:
Array Signal Processing
Johnson & Dudgeon
ISBN 0-13-048513-6
8/11/2019 k omega.PDF
4/27
4
V S I P L F o r u m
Some basics
This is an example. Some things would be donedifferently in production code.
The program is built around objects with aparameter object at the top.
In the context of this demonstration an object is A C structure in a file called something _obj.h A header file something .h Some functionality in a C file called something .c
For instance the parameter object consists of param_ob j.h, param.h, and pa ram.c
Other objects are kw (k-omega), ts (time series) ts_sim(time series simulation) and image (scale and output asimple image).
8/11/2019 k omega.PDF
5/27
5
V S I P L F o r u m
Some more basics
I designed things so that most functions take theparameter object as the argument.
A couple functions also take a file name argument. Every object has an initialization and a
finalization. This is where VSIPL objects are created and destroyed
Supports early binding Since everything exists below the parameter object
initializing the parameter object initializes all theobjects.
The main program is called beamformer . Program beamformer takes a file name (parameter file)
as an argument. The included parameter file is called param_file
8/11/2019 k omega.PDF
6/27
6
V S I P L F o r u m
Parameter File
*1500 c*1024 Fs sample rate*1024 Nts*1.5 Dsens*128 Nsens*8 Data sets to average*4 nsim_freqs*450 hertz*300 hertz*150 hertz*50 hertz*50 degrees
*130 degrees*130 degrees*90 degrees*64 Nnoise
The parameter File containsenvironmental parameters,array information, sampling
information, and datasimulation information.Nothing about VSIPL here, juststuff the program needs so itcan do something interesting.
8/11/2019 k omega.PDF
7/27
7
V S I P L F o r u m
Beamformer
Initialize
Init?
Zero AvgAccumulator
Get Data k
Done?
Finalize
OutputImage
CalculateImage
Outputk data
No Yes
Yes
No
START END
8/11/2019 k omega.PDF
8/27
8
V S I P L F o r u m
Beamformer (main)
#include#include#include"beamformer.h int ma in (int argc, char *arg v[]){ param_obj obj ; if(ar gc < 2){/*complain about an error and exit */} if(par am _o bj_init(& ob j,argv [1])){ printf("failed to initialize\n"); ffl ush(st do ut); } el se { int i; kw_z ero( & o b j); /* zero gram */ for(i=0; i< o b j.Na vg ; i++){ ts _sim (&o bj); /* sim ula te som e dat a */ kw(& o b j); /* do the k-omega */ }
image(& ob j);/ * calc ula te imag e dat a */ image_output("image_output",&obj); kw_output("gram_output",&obj); }
param_obj_fin(&obj);
return;
}
8/11/2019 k omega.PDF
9/27
9
V S I P L F o r u m
Initialize and Finalize
To support early binding it is handy to use aninitialization phase which initializes VSIPL andcreates all the VSIPL objects and user memoryneeded by the program.
It is required to destroy all VSIPL objects beforecalling vsip_finalize. Writing a finalize functionwhich mirrors your initialize function helps toensure that everything is destroyed in the proper order and at the proper time.
Note that it is not a mistake to destroy a NULL
VSIPL object so by careful initialization it ispossible to put in place a simple failuremechanism which allows a proper vsip_finalize.
8/11/2019 k omega.PDF
10/27
10
V S I P L F o r u m
Parameter Structure
typedef struct{ in t init; vsi p _scal ar_f c; /* propaga tion speed */ vsi p _sca lar _f Fs; /* Sa mpl e Ra te */ vsi p _lengt h Nts ; /* length of time series */
vsip _scalar_f Ds en s ; /* dist ance bet wee n sens ors */
vsip _length Nse ns ; /* num be r of se nso rs */
v sip _lengt h Na vg ; /* date sets to average */ /* Data simul at ion */ int Nsim _freq s; /* nu mbe r of to nes */ float *sim _freq s; /* arr ay of fre que nci es */ float *sim _be ari ngs ; /* array of bearings */ int Nsim _no ise /* number of noise directions */
ts _ob j ts; /* ti me ser ie s obj ec t */ kw _ob j kw; /* k- om eg a ob je ct */ im ag e_o bj ima ge; /* image object */} param _ob j;
8/11/2019 k omega.PDF
11/27
11
V S I P L F o r u m
Parameter init and fin
intparam_obj_init( para m_o bj *ob j, cha r *param _file) { int retval = 0; /* rea d par ame ter s in */ param_read(param_file,obj);
/* ini tia liz e VSI PL */ retval = vsi p _init((void*)0); if( retval == 0){
/* vsi p _init was su cc es fu ll */ o b j->init = 1; retval += ts _o b j_init(ob j); retval += kw_obj_init(obj);
retval += image_obj_init(obj); } e l se { /* vsi p init failed */ obj->init=0 ; } return retval;}
voidpara m _ob j_fin(para m _obj *ob j){ if( obj->init ){
/* if vsi p _init was su cce sf ul l */ if(ob j->sim _freq s != NULL)
free(ob j->sim _freqs ); ts_obj_fin(obj); kw_obj_fin(obj); image_obj_fin(obj); } obj->init = 0; /* set the obj ect un- in it */ vsip_finalize((void*)0);
}
8/11/2019 k omega.PDF
12/27
12
V S I P L F o r u m
Basics of K-Omega Calculation
Window the data in time and space Do a 2 D FFT
Generally the input data is real so real to complex out of place in the time dimension and then complex to
complex in place along the space dimension. Calculate the power Average
8/11/2019 k omega.PDF
13/27
13
V S I P L F o r u m
K-Omega Calculation
void kw( param _obj *ob j)
{
kw _obj *kw = &(o b j->kw);
t s_o bj *ts = &(o b j->ts);
/* data tapers */
vsip_vmmul_f(kw->ts_taper,ts->m_data,VSIP_ROW,ts->m_data);
vsip_vmmul_f(kw->array_taper,ts->m_data,VSIP_COL,ts->m_data); /* do 2-d FFT; first in time, then in space */
vsi p _rcfft mop_f(kw->rcfftm ,ts->m_data,kw->cm_freq);
vs ip _ccfftm ip _f(kw->ccfftm ,kw->cm_freq);
vsi p _mc ma gs q_f(kw->cm_freq,kw->rm_freq); /* po wer */
/* Scal e for averagi ng and add to prev ious data */
vs ip _s m mu l_f(1.0/ob j->Na vg ,kw->rm_fre q,kw->rm_freq); vsip_blockadmit_f(vsip_mgetblock_f(kw->m_gram),VSIP_TRUE);
vsip_madd_f(kw->rm_freq,kw->m_gram,kw->m_gram);
vsip_blockrelease_f(vsip_mgetblock_f(kw->m_gram),VSIP_TRUE);
return;
}
8/11/2019 k omega.PDF
14/27
14
V S I P L F o r u m
K-Omega Structure
typedef struct{ vs ip _l en gt h Nf re q; /* Nts /2 + 1 */ vs ip _cmv ie w_f *cm_freq; /* (Ns en s , Nfreq) col maj */ vs ip _mvie w_f *rm _freq; /* (Ns en s , Nts ) rwo maj */
vs ip _scalar_f *data_gram; /* siz e N se ns * Nfr eq */ vs ip _mvie w_f *m_gram; /* (Ns en s , Nfreq) col maj */
vs ip _fftm _f *rcfftm ; /* by row N se ns by Nts */ vs ip _fftm _f *ccfftm ; /* b y co l N se ns by Nfr eq */ vs ip _vv iew _f *ts_taper; /* of len gth Nt s */ vsi p _vvie w_f *array_taper; /* of lengt h Ns e ns */} kw _ob j;
8/11/2019 k omega.PDF
15/27
15
V S I P L F o r u m
Initialization of a Block and Its Views
Create Block
NULL?Set all Views ofBlock to NULL
Set Failure Flag
Create View
NULL?Set Failure
Flag
Done?
ENTER
EXIT
You want to ensure all
views are either NU LL
or valid.
If you find a failure flag
when you are done then
it is safe to finalize.
Yes
Yes
YesNo
No
No
8/11/2019 k omega.PDF
16/27
16
V S I P L F o r u m
K-Omega initialize
intkw_ob j_init(pa ram_obj *obj){ kw_obj *kw = &(obj->kw); int retval = 0; vsip _length Ns en s = obj->Ns en s; vsip _length Nts = obj->Nts ; vsip _length Nfreq; if(ob j->Nts %2){ printf("data length must be even"); retval++; } kw->Nfreq = Nts /2 + 1; Nfreq = kw->Nfreq ; kw->cm_freq = vsip _cmcreate _f(Nse ns ,Nfreq,VSIP_ CO L, VS IP_MEM_ NONE) ; if(kw->cm_freq == NULL){ retval++; } else { kw->rm_f req = vsi p_mrealview_f(kw->cm_freq); if(kw->rm_freq == NULL) retval++; }
8/11/2019 k omega.PDF
17/27
17
V S I P L F o r u m
K-Omega initialize (cont) { /* create data space and block for gram */
vsip _block_f *block; vsip _length L = Ns en s * Nfreq; kw->data_gram = (vsip _scalar_f*) mal loc ( L * sizeof(vsip _scalar_f)); if(kw->data_gram == NULL) retval++; block = vsip _blockbind _f(kw->data_gram,L,VSIP_MEM_NONE); if(block != NULL){ kw->m_gram = vsip _mbind_f(block,0,1,Nsen s , Nsen s , Nfreq); if(kw->m_gram == NULL){ retval++; vsip _blockdestroy _f(block); /* On fa ilure clean up the blo ck sin ce it i s local */ } } else { retval ++; kw->m_gram = NULL; } } kw->rcfftm = vsi p_rcfftmop _create_f(Nsens ,Nts ,1,VSIP_ROW,0,0); if(kw->rcf ftm == NULL) retval++; kw->ccfftm = vsip _ccfftmip _create_f(Nse ns ,Nfreq,VSIP_FFT_FW D,1, VSIP_COL ,0,0); if(kw->cc ff tm == NULL) retval++; kw->ts_taper = vsip _vcreate_hanning _f(Nts,0); if(kw->ts_taper == NULL) retval++; kw->array_taper = vsip _vcreate_hann ing _f(Ns en s,0); if(kw->array_taper == NULL) retval++; return retval;}
8/11/2019 k omega.PDF
18/27
18
V S I P L F o r u m
K-Omega finalize
voidkw _ob j_fin( param _obj *ob j){ kw _obj *kw = &(o b j->kw); vsip_malldestroy_f(kw->m_gram); if(kw->data_gram != NULL) free(kw->data_gr am); vsi p _fftm_destroy_f(kw->rcfftm ); vsip _fftm_destroy_f(kw->ccfftm ); vsip_valldestroy_f(kw->ts_taper); vsip_valldestroy_f(kw->array_taper); vsip_mdestroy_f(kw->rm_freq); vsip_cmalldestroy_f(kw->cm_freq); return;}
8/11/2019 k omega.PDF
19/27
19
V S I P L F o r u m
K-Omega Zero & Output
voidkw_z ero (param _obj *ob j){ kw _obj *kw = &(o b j->kw); vsip_blockadmit_f(vsip_mgetblock_f(kw->m_gram),VSIP_FALSE); vsip_mfill_f(0.0,kw->m_gram); vsip_blockrelease_f(vsip_mgetblock_f(kw->m_gram),VSIP_TRUE);}
voidkw_ou tput ( /* out put gra m to a fi le */ cha r *output, para m_o bj *ob j){ F IL E *fptr = fo pe n(output,"w"); fwrite( obj->kw.data_gram ,o b j->Ns e n s * o b j->kw.N freq, sizeof(vsip_scalar_f),fptr);
fclose(fptr);}
8/11/2019 k omega.PDF
20/27
20
V S I P L F o r u m
Final Output
( )
cos
60
120
8/11/2019 k omega.PDF
21/27
21
V S I P L F o r u m
So whats next? That concludes the basics of the example. In the remaining time we will touch on some
additional information by looking at some of thecode not covered yet. In particular we will look at:
Some details of admit and release. User written support functions. Talk about
Random number generation FIR Filter functionality.
And other things, feel free to ask Questions ?
8/11/2019 k omega.PDF
22/27
22
V S I P L F o r u m
Admit and Release
Doing I/O from the library involves allocating user memory, associating the memory with a block,and admitting and releasing the block fromVSIPL.
The TASP VSIPL implementation is very forgivingof admit release errors. Other implementationsmay not be.
So lets look at the image.c code to examine acharacteristics of admit release that may not be
well understood.
8/11/2019 k omega.PDF
23/27
23
V S I P L F o r u m
The library Owns the user datawhen the block is admitted
In image.c we have the code vsip_blockadmit_f(vsip_mgetblock_f(m_gram),VSIP_TRUE);
vsip_mcopy_f_f(m_gram, minput);vsip _blockrele ase_f(vsip _mget bloc k_f(m_gram),VSIP_TRUE);
Even though we dont do anything to the data duringthe copy to ensure that user data associated withm_gram remains the same we must release with a
V S IP _ T R U E flag. Use V S IP _F A L S E only if plan to overwrite the data and
really dont care what it is.
8/11/2019 k omega.PDF
24/27
24
V S I P L F o r u m
Dont Reassign User Data Pointers Release functions return a convenience pointer to the
user data array. Store it in a new pointer created for that purpose. Dont
reassign the original user data array pointer. Note that VSIPL does not assign new memory for user data.
The pointer returned is the one initially bound. Reassigning the pointer risks loosing a pointer to allocated
memory from the heap and serves no purpose. For complex block release you must supply pointers to
two data array pointers even if the user data isinterleaved. In the interleaved case the second pointer
will be returned pointing to NULL. {
vsip _scalar_f *ptr1,*ptr2; vsip_cb loc kre lea se_f(block,VSIP_TRUE,&ptr1,&ptr2)}
8/11/2019 k omega.PDF
25/27
25
V S I P L F o r u m
Data Simulation
The data is created in a simple simulator. First zero the data array Fill the data array with directional noise
VSIPL random functionality is used to produce somerandom noise.
The noise is low pass filtered. A simple time delay mechanism is used to simulate noise
from many directions (defined in the parameter file). We need this step to give the k-omega its characteristic
cone shape. Simulate narrow band data and add it to the noise data
for some defined set of frequencies and directions.
8/11/2019 k omega.PDF
26/27
26
V S I P L F o r u m
Plotting The Output A simple Matlab script called plt.m is included for
plotting the output of the K-omega. An image routine is included which outputs a
simple unsigned char bitmap for use in someother plotting packages.
A simple script for the open source GRI plottingpackage is included to convert the image bitmap to apostscript output.
GRI is available for many platforms. It resides atgri.sourceforge.net
A simple routine to convert the image bitmap to
PNG format is available but not included. It needs two libraries libgd.a and libpng.a
8/11/2019 k omega.PDF
27/27
27
V S I P L F o r u m
Finish
I plan to make and run the example. Plot the output. Answer any remaining Questions .
Top Related