SpectralFocus.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "SpectralFocus.hxx"
00023 #include "ProcessingFactory.hxx"
00024
00025 namespace CLAM
00026 {
00027
00028 namespace Hidden
00029 {
00030 static const char * metadata[] = {
00031 "key", "SpectralFocus",
00032
00033
00034 0
00035 };
00036 static FactoryRegistrator<ProcessingFactory, SpectralFocus> reg = metadata;
00037 }
00038
00039 bool SpectralFocus::Do(const Spectrum&
00040 inSpec,Spectrum& outSpec)
00041 {
00042
00043 if (!mConfig.GetPreserveOuts())
00044 {
00045 outSpec = inSpec;
00046 }
00047
00048 int spectrumSize = inSpec.GetSize();
00049 TData spectralResolution = spectrumSize/inSpec.GetSpectralRange();
00050
00051 int centerPoint = Round (mCenterFreqCtl.GetLastValue()*spectralResolution);
00052 int amount= Round(mAmount.GetLastValue()*spectralResolution);
00053
00054 mBPFSpectrum.SetSize(spectrumSize);
00055
00056
00057
00058 Array<Point>& magBPF=mBPFSpectrum.GetMagBPF().GetPointArray();
00059
00060 Array<Point>& phaseBPF=mBPFSpectrum.GetPhaseBPF().GetPointArray();
00061
00062
00063 magBPF.SetSize(0);
00064 phaseBPF.SetSize(0);
00065
00066 DataArray& inMag = inSpec.GetMagBuffer();
00067 DataArray& inPhase = inSpec.GetPhaseBuffer();
00068
00069 TData binWidth = 1./spectralResolution;
00070 int i;
00071 TData freq = amount*binWidth;
00072 TData mag;
00073 TData phase;
00074 int nPoints = 0;
00075 for (i=amount; i<centerPoint; i++)
00076 {
00077 mag = inMag[i-amount];
00078 phase = inPhase[i-amount];
00079 magBPF.AddElem(Point(freq,mag));
00080 phaseBPF.AddElem(Point(freq, phase));
00081 freq += binWidth;
00082 nPoints++;
00083 }
00084
00085 freq = centerPoint * binWidth;
00086 magBPF.AddElem(Point(freq, inMag[centerPoint]));
00087 phaseBPF.AddElem(Point(freq, inPhase[centerPoint]));
00088 nPoints++;
00089
00090 freq = (centerPoint+1)*binWidth;
00091
00092 for (i=centerPoint+1 ; i<spectrumSize-amount; i++)
00093 {
00094 mag = inMag[i+amount];
00095 phase = inPhase[i+amount];
00096 magBPF.AddElem(Point(freq,mag));
00097 phaseBPF.AddElem(Point(freq, phase));
00098 freq += binWidth;
00099 nPoints++;
00100 }
00101
00102 mBPFSpectrum.SetBPFSize(nPoints);
00103 mBPFSpectrum.SynchronizeTo(mFlag);
00104 outSpec.SetMagBuffer(mBPFSpectrum.GetMagBuffer());
00105 outSpec.SetPhaseBuffer(mBPFSpectrum.GetPhaseBuffer());
00106
00107 return true;
00108 }
00109
00110
00111 }
00112