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

FreqBeamLine.cc

Go to the documentation of this file.
00001 /*
00002 
00003     Frequency-domain beamforming for line array
00004     Copyright (C) 2000-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 <math.h>
00024 #include <float.h>
00025 #include <sys/types.h>
00026 
00027 #include <dsp/DSPVector.hh>
00028 
00029 #include "FreqBeamLine.hh"
00030 
00031 
00032 clFreqBeamLine::~clFreqBeamLine ()
00033 {
00034     while (vSensors.size() > 0)
00035     {
00036         delete vSensors[vSensors.size() - 1];
00037         vSensors.pop_back();
00038     }
00039 }
00040 
00041 
00042 void clFreqBeamLine::SetDebug (bool bDebug)
00043 {
00044     size_t uiSensorCntr;
00045 
00046     for (uiSensorCntr = 0; uiSensorCntr < vSensors.size(); uiSensorCntr++)
00047     {
00048         if (bDebug) vSensors[uiSensorCntr]->EnableDebug();
00049         else vSensors[uiSensorCntr]->DisableDebug();
00050     }
00051 }
00052 
00053 
00054 bool clFreqBeamLine::Initialize (long lSensors, GDT fSpacing, long lWinSize, 
00055     GDT fSampleRate)
00056 {
00057     long lSensorCntr;
00058     clDSPVector<GDT> dspvShade(lSensors);
00059     clArraySensor *Sensor;
00060 
00061     lSensorCount = lSensors;
00062     fSensorSpacing = fSpacing;
00063     dspvShade.WinDolphChebyshev(
00064         (GDT) 1.0 / (GDT) pow(10.0, 3.0 * lSensorCount / 20.0), 
00065         lSensorCount);
00066     for (lSensorCntr = 0; lSensorCntr < lSensorCount; lSensorCntr++)
00067     {
00068         Sensor = new clArraySensor;
00069         if (!Sensor->Initialize(lSensorCntr * fSpacing, 
00070             (lSensorCount - 1) - lSensorCntr * fSpacing,
00071             lWinSize)) return false;
00072         Sensor->SetSampleRate(fSampleRate);
00073         Sensor->SetShading(dspvShade[lSensorCntr]);
00074         vSensors.push_back(Sensor);
00075     }
00076     return true;
00077 }
00078 
00079 
00080 void clFreqBeamLine::SetSoundSpeed (GDT fSoundSpeed)
00081 {
00082     size_t uiSensorCntr;
00083 
00084     for (uiSensorCntr = 0; uiSensorCntr < vSensors.size(); uiSensorCntr++)
00085     {
00086         vSensors[uiSensorCntr]->SetSoundSpeed(fSoundSpeed);
00087         vSensors[uiSensorCntr]->SetArrayFrequency(
00088             fSoundSpeed / 2 / fSensorSpacing);
00089     }
00090 }
00091 
00092 
00093 void clFreqBeamLine::SetDirection (GDT fDirection, bool bLowPass)
00094 {
00095     size_t uiSensorCntr;
00096 
00097     for (uiSensorCntr = 0; uiSensorCntr < vSensors.size(); uiSensorCntr++)
00098     {
00099         if (fDirection < 0 && uiSensorCntr == (vSensors.size() - 1))
00100             vSensors[uiSensorCntr]->SetDirection(fDirection, bLowPass);
00101         else if (fDirection >= 0 && uiSensorCntr == 0)
00102             vSensors[uiSensorCntr]->SetDirection(fDirection, bLowPass);
00103         else
00104             vSensors[uiSensorCntr]->SetDirection(fDirection, true);
00105     }
00106 }
00107 
00108 
00109 void clFreqBeamLine::Put (const GDT *fpSrc, long lSrcCount, 
00110     long lSensorOffs, long lChannels)
00111 {
00112     size_t uiSensorCntr;
00113     clDSPVector<GDT> dspvSensorData;
00114     clDSPVector<GDT> dspvSrc(fpSrc, lSrcCount);
00115 
00116     for (uiSensorCntr = 0; uiSensorCntr < vSensors.size(); uiSensorCntr++)
00117     {
00118         dspvSensorData.Extract(dspvSrc, lSensorOffs + uiSensorCntr, lChannels);
00119         vSensors[uiSensorCntr]->Put(dspvSensorData.Ptr(), 
00120             dspvSensorData.Size());
00121         dspvSensorData.Clear();
00122     }
00123 }
00124 
00125 
00126 bool clFreqBeamLine::Get (GDT *fpDest, long lDestCount)
00127 {
00128     size_t uiSensorCntr;
00129     clDSPVector<GDT> dspvSensorData(lDestCount);
00130     clDSPVector<GDT> dspvOutData(lDestCount);
00131 
00132     dspvOutData.Zero();
00133     for (uiSensorCntr = 0; uiSensorCntr < vSensors.size(); uiSensorCntr++)
00134     {
00135         if (!vSensors[uiSensorCntr]->Get(dspvSensorData.Ptr(), 
00136             dspvSensorData.Size())) return false;
00137         dspvOutData += dspvSensorData;
00138     }
00139     dspvOutData *= (GDT) 1.0 / (GDT) lSensorCount;
00140     return dspvOutData.Get(fpDest, lDestCount);
00141 }

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