LPModel.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
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 #include "LPModel.hxx"
00023 #include "Spectrum.hxx"
00024 #include "SpectrumConfig.hxx"
00025 #include "SpectrumConversions.hxx"
00026 #include "ProcessingDataPlugin.hxx"
00027 
00028 namespace CLAM
00029 {
00030         namespace Hidden
00031         {
00032                 static ProcessingDataPlugin::Registrator<CLAM::LPModel> dataRegistrator("orange");
00033         }
00034 
00035         void LPModel::DefaultInit()
00036         {
00037                 AddAll();
00038                 UpdateData();
00039                 // MRJ: 11 seems to be a 'wise' number
00040                 UpdateModelOrder( 11 );
00041         }
00042 
00043         void LPModel::UpdateModelOrder( TSize order )
00044         {
00045                 SetOrder( order );
00046                 GetFilterCoefficients().Resize( order );
00047                 GetFilterCoefficients().SetSize( order );
00048                 GetReflectionCoefficients().Resize( order );
00049                 GetReflectionCoefficients().SetSize( order );
00050         }
00051 
00052         void LPModel::ToSpectrum( Spectrum& spec ) const
00053         {
00054                 SpecTypeFlags specFlags;
00055                 spec.GetType( specFlags );
00056                 spec.SetScale( EScale::eLinear );
00057                 
00058                 spec.SetSpectralRange( GetSpectralRange() );
00059 
00060                 const DataArray& ak_vec = GetFilterCoefficients();
00061                 int order = ak_vec.Size();
00062 
00063                 // we build the array of polarCoeffs from the filter poles
00064                 Array< Complex > spectrumCoeffs;
00065                 Array< Complex > cmplxCoeffs;
00066                 spectrumCoeffs.Resize( spec.GetSize() );
00067                 spectrumCoeffs.SetSize( spec.GetSize() );
00068                 cmplxCoeffs.Resize( order );
00069                 cmplxCoeffs.SetSize( order );
00070 
00071                 const TData dw = PI/TData(spec.GetSize()-1);
00072                 TData w =0.0;
00073                 Complex unitComplex;
00074                 unitComplex.SetReal( 1.0 );
00075                 unitComplex.SetImag( 0.0 );
00076 
00077                 for ( int j = 0; j < spec.GetSize(); j++ )
00078                 {
00079                         spectrumCoeffs[j].SetReal( 1.0 );
00080                         spectrumCoeffs[j].SetImag( 0.0 );
00081 
00082                         for ( int i = 0; i < order; i++ )
00083                         {
00084                                 cmplxCoeffs[i].SetReal( ak_vec[i]*cos( -1.0*(float)(i+1)*w ) );
00085                                 cmplxCoeffs[i].SetImag( ak_vec[i]*sin( 1.0*(float)(i+1)*w ) );
00086 
00087                                 spectrumCoeffs[j] += cmplxCoeffs[i];
00088                         }
00089                         spectrumCoeffs[j] = unitComplex / spectrumCoeffs[j];
00090                         w += dw;
00091                 }
00092                 
00093                 if ( specFlags.bComplex )
00094                 {
00095                         spec.SetComplexArray( spectrumCoeffs );
00096                 }
00097                 if ( specFlags.bPolar )
00098                 {
00099                 //      Complex2Polar( spectrumCoeffs, spec.GetPolarArray() );
00100                 }
00101                 if ( specFlags.bMagPhase )
00102                 {
00103                         Complex2MagPhase( spectrumCoeffs, spec.GetMagBuffer(), spec.GetPhaseBuffer() );
00104                 }
00105         }
00106 }
00107 
Generated by  doxygen 1.6.3