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

CorrDipole.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Correlator class for dipole array
00004     Copyright (C) 1999-2002 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 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <math.h>
00026 #include <float.h>
00027 
00028 #include "CorrDipole.hh"
00029 
00030 
00031 clCorrDipole::clCorrDipole (clArrayDipole *ArrayPtr, GDT fIntegrationTime, 
00032     int iSampleRate, long lWindowSize, bool bDisableFilter, bool bEnableDebug)
00033 {
00034     long lSensCntr;
00035     
00036     bDebug = bEnableDebug;
00037     bFilter = !bDisableFilter;
00038     Array = ArrayPtr;
00039     lWinSize = lWindowSize;
00040     lSampleCount = (long) ((GDT) iSampleRate * fIntegrationTime + (GDT) 0.5);
00041     if ((lSampleCount % lWinSize) > (lWinSize / 2))
00042         lSampleCount += lSampleCount % lWinSize;
00043     else
00044         lSampleCount -= lSampleCount % lWinSize;
00045     fIntTime = (GDT) lSampleCount / (GDT) iSampleRate;
00046     if (bDebug) printf("Integration time %f -> %f\n", fIntegrationTime,
00047         fIntTime);
00048     lBaseIdx = Array->GetMaxDelay();
00049     if (bDebug) printf("Integration buffers %li/%li samples (%li/%li bytes)\n",
00050         lSampleCount, lBaseIdx + lSampleCount,
00051         lSampleCount * (long) sizeof(GDT), 
00052         (lBaseIdx + lSampleCount) * (long) sizeof(GDT));
00053     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00054     {
00055         Data[lSensCntr].Size((lBaseIdx + lSampleCount) * sizeof(GDT));
00056         DSPBank[lSensCntr].Zero((GDT *) Data[lSensCntr], 
00057             lBaseIdx + lSampleCount);
00058     }
00059     if (bDebug && !bFilter) printf("Array phi/2 filtering disabled\n");
00060 }
00061 
00062 
00063 clCorrDipole::~clCorrDipole ()
00064 {
00065 }
00066 
00067 
00068 bool clCorrDipole::AddData ()
00069 {
00070     long lReBufRes;
00071     long lSensCntr;
00072     GDT *fpSensPtr;
00073     
00074     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00075     {
00076         fpSensPtr = Data[lSensCntr];
00077         if (bFilter)
00078         {
00079             lReBufRes = DSPBank[lSensCntr].ReBuffer(&fpSensPtr[lBaseIdx], 
00080                 Array->GetFiltPtr(lSensCntr), lSampleCount, lWinSize);
00081         }
00082         else
00083         {
00084             lReBufRes = DSPBank[lSensCntr].ReBuffer(&fpSensPtr[lBaseIdx], 
00085                 Array->GetRawPtr(lSensCntr), lSampleCount, lWinSize);
00086         }
00087     }
00088     if (lReBufRes >= 1) return true;
00089     return false;
00090 }
00091 
00092 
00093 GDT clCorrDipole::Process (GDT fDirection)
00094 {
00095     long lDelay1;
00096     long lDelay2;
00097     GDT fCrossCorrelation;
00098     GDT *fpDataPtr1;
00099     GDT *fpDataPtr2;
00100 
00101     lDelay1 = Array->GetDelaySamples(0, fDirection);
00102     lDelay2 = Array->GetDelaySamples(1, fDirection);
00103     fpDataPtr1 = Data[0];
00104     fpDataPtr2 = Data[1];
00105     fCrossCorrelation = DSP.CrossCorr(&fpDataPtr1[lBaseIdx - lDelay1],
00106         &fpDataPtr2[lBaseIdx - lDelay2], lSampleCount);
00107     return fCrossCorrelation;
00108 }
00109 
00110 
00111 void clCorrDipole::SetHistory ()
00112 {
00113     long lSensCntr;
00114     GDT *fpDataPtr;
00115 
00116     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00117     {
00118         fpDataPtr = Data[lSensCntr];
00119         DSPBank[lSensCntr].Copy(fpDataPtr, &fpDataPtr[lSampleCount],
00120             lBaseIdx);
00121     }    
00122 }
00123 
00124 
00125 GDT clCorrDipole::GetPeakLevel ()
00126 {
00127     long lSensCntr;
00128     GDT fBufMin;
00129     GDT fBufMax;
00130     GDT fRealMax;
00131     GDT *fpDataPtr;
00132 
00133     fRealMax = (GDT) 0.0;
00134     for (lSensCntr = 0; lSensCntr < 2; lSensCntr++)
00135     {
00136         fpDataPtr = Data[lSensCntr];
00137         DSPBank[lSensCntr].MinMax(&fBufMin, &fBufMax, &fpDataPtr[lBaseIdx], 
00138             lSampleCount);
00139         fBufMin = (GDT) fabs(fBufMin);
00140         if (fBufMin > fRealMax) fRealMax = fBufMin;
00141         else if (fBufMax > fRealMax) fRealMax = fBufMax;
00142     }
00143     if (fRealMax > (GDT) 0.0)
00144         return ((GDT) (20.0 * log10(fRealMax)));
00145     return (-DIR_DB_SCALE);
00146 }
00147 

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