// totallength and N are number of complex samples void PeriodogramComponent::periodogram(int totallength,int N,float data[],float result[]) { int num_of_block = 2*totallength/N-1; float datablock[2*N],PSDresult[N],PSDresultshift[N]; int offset; clearArray(result,N); for( int i= 1;i<=num_of_block;i++) { offset = N/2*(i-1); copyblock(offset,N,data,datablock); winHan(N,datablock); FFT (datablock, N, 1); PSD(datablock,PSDresult,N); PSDshift(PSDresult,PSDresultshift,N); addArray(result,PSDresultshift,N); } avgArray(result,N,num_of_block); }
int main(int argc, char *argv[]) { # include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" // Get times list instantList Times = runTime.times(); // set startTime and endTime depending on -time and -latestTime options # include "checkTimeOptions.H" runTime.setTime(Times[startTime], startTime); # include "createMesh.H" for (label i=startTime; i<endTime; i++) { runTime.setTime(Times[i], i); Info<< "Time = " << runTime.timeName() << endl; mesh.readUpdate(); IOobject tauHeader ( "tau", runTime.timeName(), mesh, IOobject::MUST_READ ); // Check tau exists if (tauHeader.headerOk()) { mesh.readUpdate(); Info<< " Reading tau" << endl; volSymmTensorField tau(tauHeader, mesh); Info<< " Calculating PSD"<< endl; volScalarField PSD ( IOobject ( "PSD", runTime.timeName(), mesh, IOobject::NO_READ ), Foam::sqrt ( Foam::sqr(tau.component(symmTensor::YY) - tau.component(symmTensor::XX)) + 4*Foam::sqr(tau.component(symmTensor::XY)) ) ); PSD.write(); } else { Info<< " No tau" << endl; } Info<< endl; } //for time Info<< endl; Info<< " End"<< nl << endl; return(0); }