import ChaosDemos.*; import java.awt.*; import java.util.*; //******************************************************************** /** * Poswer spectrum diagnostics for Odes
* @version 24 October 1997 * @author Michael Cross */ //******************************************************************** public class OdesSpectrum extends OdesDiagnostics { /** updated number of points in plot */ int nplot; /** index of first data curve */ int ncurve1; /** copy of x */ double[] xp={0.,0.,0.,0.}; /** Number of points in FFT */ int fourierLength=256; /** index of point added to FFT */ int fourierIndex; /** data for power spectrum */ double[] fourierData; /** window type in power spectrum */ int winNum=2; /** number of iterations between each point for power spectrum */ int FFTskip=1; /** number of iterations since last FFT */ int skip=1; private powerSpectrum mySpectrum; String xTitle="Frequency"; String yTitle= "log(Power)"; //****************************************************************** /** * @param inParent parent class * @see Map1D */ //****************************************************************** public OdesSpectrum(Odes inParent) { super(inParent); } //******************************************************************** /** * Updates parameters from the text controls in parent class */ //******************************************************************** public void updateParameters() { super.updateParameters(); FFTskip=parent.variables.parseTextField(4,FFTskip,true); fourierLength=parent.variables.parseTextField(5,fourierLength,true); int test=fourierLength; int power=0; while(test>1) { test=test/2; power++; } test=1; for(int i=0;ierr) err=errp; if(parent.showTime) parent.status.setText(" Time ="+(float)t); return true; } //********************************************************************** /** * Sets default values of parameters depending on plot type */ //********************************************************************** public void setDefaults() { parent.variables.show(4); parent.variables.show(5); parent.variables.show(6); parent.variables.setText(4,"4"); parent.variables.setLabelText(4,"Interval"); parent.variables.setText(5,"256"); parent.variables.setLabelText(5,"Points "); parent.variables.setText(6,"2"); parent.variables.setLabelText(6,"Window"); parent.topRightPanel.validate(); } //********************************************************************** /** * Sets delay for movie iteration */ //********************************************************************** public void setDelay(int inDelay) { delay=inDelay; dt=dtp/((double) delay); ntrans=(int) (trans/dtp); } //********************************************************************** /** * process data * @param x variable * @param data for plotting * @param nplot number of points indata * @return nplot new number of points in data */ //********************************************************************** int process(double x[], int nplot) { if(skip==FFTskip) { fourierData[fourierIndex]=x[plot_y]; fourierIndex++; fourierData[fourierIndex]=0; fourierIndex++; if(fourierIndex >= 2*fourierLength) { mySpectrum.transform(fourierData); if(ncurve>=0) ncurve = parent.graph.deleteAllCurves(); ncurve = parent.graph.addCurve( fourierData,1+fourierLength/2,Color.blue); parent.graph.paintAll=true; parent.graph.repaint(); fourierIndex=0; } nplot++; skip=1; } else skip++; return nplot; } }