Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

BeamDipole.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Beamformer class for dipole array
00004     Copyright (C) 1999-2001 Jussi Laako
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 */
00021 
00022 
00023 #ifdef HAVE_GLIBC
00024     #ifndef _ISOC9X_SOURCE
00025         #define _ISOC9X_SOURCE
00026     #endif
00027 #endif
00028 
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <math.h>
00033 #include <float.h>
00034 
00035 #include "BeamDipole.hh"
00036 
00037 
00038 clBeamDipole::clBeamDipole (clArrayDipole *ArrayPtr, GDT fIntegrationTime, 
00039     int iSampleRate, long lWindowSize, bool bEnableDebug)
00040 {
00041     long lSensCntr;
00042     
00043     bDebug = bEnableDebug;
00044     Array = ArrayPtr;
00045     lWinSize = lWindowSize;
00046     lSampleCount = (long) ((GDT) iSampleRate * fIntegrationTime + (GDT) 0.5);
00047     if ((lSampleCount % lWinSize) > (lWinSize / 2))
00048         lSampleCount += lSampleCount % lWinSize;
00049     else
00050         lSampleCount -= lSampleCount % lWinSize;
00051     fIntTime = (GDT) lSampleCount / (GDT) iSampleRate;
00052     if (bDebug) printf("Integration time %f -> %f\n", fIntegrationTime,
00053         fIntTime);
00054     lBaseIdx = Array->GetMaxDelay();
00055     if (bDebug) printf("Integration buffers %li/%li samples (%li/%li bytes)\n",
00056         lSampleCount, lBaseIdx + lSampleCount,
00057         lSampleCount * (long) sizeof(GDT), 
00058         (lBaseIdx + lSampleCount) * (long) sizeof(GDT));
00059     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00060     {
00061         Data[lSensCntr].Size((lBaseIdx + lSampleCount) * sizeof(GDT));
00062         DSPBank[lSensCntr].Zero((GDT *) Data[lSensCntr], 
00063             lBaseIdx + lSampleCount);
00064     }
00065 }
00066 
00067 
00068 clBeamDipole::~clBeamDipole ()
00069 {
00070 }
00071 
00072 
00073 bool clBeamDipole::AddData ()
00074 {
00075     long lReBufRes;
00076     long lSensCntr;
00077     GDT *fpSensPtr;
00078     
00079     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00080     {
00081         fpSensPtr = Data[lSensCntr];
00082         lReBufRes = DSPBank[lSensCntr].ReBuffer(&fpSensPtr[lBaseIdx], 
00083             Array->GetFiltPtr(lSensCntr), lSampleCount, lWinSize);
00084     }
00085     if (lReBufRes >= 1) return true;
00086     return false;
00087 }
00088 
00089 
00090 GDT clBeamDipole::Process (GDT fDirection)
00091 {
00092     long lWorkCntr;
00093     long lDelay1;
00094     long lDelay2;
00095     GDT fWorkMix;
00096     GDT fWorkEnergy;
00097     GDT *fpDataPtr1;
00098     GDT *fpDataPtr2;
00099 
00100     lDelay1 = Array->GetDelaySamples(0, fDirection);
00101     lDelay2 = Array->GetDelaySamples(1, fDirection);
00102     fpDataPtr1 = Data[0];
00103     fpDataPtr2 = Data[1];
00104     fWorkEnergy = (GDT) 0.0;
00105     for (lWorkCntr = 0; lWorkCntr < lSampleCount; lWorkCntr++)
00106     {
00107         fWorkMix = (fpDataPtr1[lBaseIdx - lDelay1 + lWorkCntr] + 
00108             fpDataPtr2[lBaseIdx - lDelay2 + lWorkCntr]) * (GDT) 0.5;
00109         #ifndef _ISOC9X_SOURCE
00110             fWorkEnergy += fWorkMix * fWorkMix;
00111         #else
00112             #if (GDT == float)
00113                 fWorkEnergy = fmaf(fWorkMix, fWorkMix, fWorkEnergy);
00114             #elif (GDT == double)
00115                 fWorkEnergy = fma(fWorkMix, fWorkMix, fWorkEnergy);
00116             #else
00117                 #error Unknown FP type
00118             #endif
00119         #endif
00120     }
00121     return (fWorkEnergy / (GDT) lSampleCount);
00122 }
00123 
00124 
00125 void clBeamDipole::SetHistory ()
00126 {
00127     long lSensCntr;
00128     GDT *fpDataPtr;
00129 
00130     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00131     {
00132         fpDataPtr = Data[lSensCntr];
00133         DSPBank[lSensCntr].Copy(fpDataPtr, &fpDataPtr[lSampleCount],
00134             lBaseIdx);
00135     }    
00136 }
00137 
00138 
00139 GDT clBeamDipole::GetPeakLevel ()
00140 {
00141     long lSensCntr;
00142     GDT fBufMin;
00143     GDT fBufMax;
00144     GDT fRealMax;
00145     GDT *fpDataPtr;
00146 
00147     fRealMax = (GDT) 0.0;
00148     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00149     {
00150         fpDataPtr = Data[lSensCntr];
00151         DSPBank[lSensCntr].MinMax(&fBufMin, &fBufMax, &fpDataPtr[lBaseIdx], 
00152             lSampleCount);
00153         fBufMin = (GDT) fabs(fBufMin);
00154         if (fBufMin > fRealMax) fRealMax = fBufMin;
00155         else if (fBufMax > fRealMax) fRealMax = fBufMax;
00156     }
00157     if (fRealMax > (GDT) 0.0)
00158         return ((GDT) (20.0 * log10(fRealMax)));
00159     return (-DIR_DB_SCALE);
00160 }
00161 

Generated on Sun Oct 26 19:11:18 2003 for HASAS by doxygen 1.3.3