import ChaosDemos.*;
import java.awt.*;
import java.util.*;
//********************************************************************
/**
* Diagnostics for Map1D
* Plots power spectrum.
* Three different windowing functions can be used, set by WinNum:
*
- 0=NONE
*
- 1=BARTLETT
*
- 2=WELCH
*
- 3=HANN
* @version 10 October 1997
* @author Michael Cross
*/
//********************************************************************
public class Map1DFourier extends Map1DDiagnostics {
/** number of data points for power spectrum (must be power of 2!) and histogram */
private int dataLength ;
/** 2*dataLength */
private int dataLength2;
/** index point in accumulating Fourier data */
private int fourierIndex;
/** windowing in power spectrum */
private int winNum=0;
/** array for plotting power spectrum and histogram */
private double[] plotData;
/** floor for Fourier transform, so don't take log(0) */
private double FLOOR=1.e-12;
/** class for performing FFT */
private powerSpectrum mySpectrum;
//******************************************************************
/**
* @param inParent parent class
* @see Map1D
*/
//******************************************************************
public Map1DFourier(Map1D inParent) {
super(inParent);
parameters = new double[parent.nParameters];
}
//********************************************************************
/**
* Updates parameters from the text controls in parent class
*/
//********************************************************************
public void updateParameters() {
int i;
x0=parent.variables.parseTextField(5,x0);
x=x0;
ntrans=parent.variables.parseTextField(3,ntrans);
if(ntrans>0) runTrans=true;
nf=parent.variables.parseTextField(2,nf,true);
parent.mapFunction.setCompose(nf);
dataLength=parent.variables.parseTextField(4,256,true);
dataLength2=2*dataLength;
// Check for power of 2
int test=dataLength;
int power=0;
while(test>1) {
test=test/2;
power++;
}
test=1;
for(i=0;i=0) ncurve = parent.graph.deleteAllCurves();
ncurve = parent.graph.addCurve(plotData,1+dataLength/2,Color.blue);
ncurve1=ncurve;
parent.graph.paintAll=true;
parent.graph.clearAll=true;
parent.graph.repaint();
// parent.graph.repaint(delay/2);
// Reset spectrum
mySpectrum = new powerSpectrum(dataLength, winNum, scale);
mySpectrum.setFloor(FLOOR);
fourierIndex=0;
if(parent.showTime) parent.status.setText("No. of Iterations "+ iterations);
}
//*********************************************************************
/**
* Iterates Map equations and updates graph according to value of plot
*/
//*********************************************************************
public boolean iterate() {
int i,j;
double[] moredata = new double[6];
double[] moredata1 = new double[6];
x=parent.mapFunction.iterate(x);
plotData[fourierIndex]=x;
fourierIndex++;
plotData[fourierIndex]=0;
fourierIndex++;
iterations+=nf;
if(parent.showTime)
parent.status.setText("No. of Iterations "+ iterations);
if(fourierIndex>=dataLength2){
mySpectrum.transform(plotData);
parent.graph.paintAll=false;
// if(ncurve>=0) ncurve = graph.deleteAllCurves();
parent.graph.appendToCurve(plotData,1+dataLength/2,ncurve1);
parent.graph.deleteFromCurve(1+dataLength/2,ncurve1);
parent.graph.paintAll=true;
parent.graph.repaint();
// parent.graph.repaint(delay/2);
// nplot++;
fourierIndex=0;
}
return true;
}
//**********************************************************************
/**
* Sets default values of parameters
*/
//**********************************************************************
public void setPlotDefaults() {
String[] label={"Transient","Points","Start x","Window"};
String[] text={"64","256","0.2","0"};
parent.setPlotTextBoxes(label,text);
parent.choices.enable(0);
}
//**********************************************************************
}