uk.ac.ed.ph.signal
Class Signal

java.lang.Object
  extended by uk.ac.ed.ph.signal.Signal
Direct Known Subclasses:
ComplexSignal, RealSignal

public abstract class Signal
extends Object

Abstract class to represent a Signal where the signal in held as a one-dimensional DataArray from the jfftw package.

Use of this class should be via RealSignal and ComplexSignal the two extending classes.


Field Summary
protected  DataArray data
          The DataArray to hold the data
protected static String fmt
          Format string for output
protected  ptolemy.plot.Plot plot
          Plot holding graphical information.
 
Constructor Summary
Signal()
           
 
Method Summary
 void add(int i, Complex c)
          Method to add a Complex to an element.
 void add(int i, double a)
          Method to add a scalar to an element.
 void add(int i, double a, double b)
          Method to add a complex to an element.
 void add(Signal s)
          Method to add a specified Signal to the current Signal, both must be the same size.
 void centreFourier()
          Method to form centred Fourier using applying checker pattern to shift DC the centre of the array.
 void conjugate()
          Method to take conjugate of the whole Signal.
 void conjugate(int i)
          Method to form the Complex conjugate of an element.
 void fillSine(double amp, double freq, double phase, double offset)
          Method to fill the signal with a sin() function using the sample time.
 void fourier()
          Method to take the unshifted Fourier transform.
 Complex getComplex(double x)
          Method to get the Complex closest to the analogue value
 Complex getComplex(int i)
          Method to get a Complex data point
 int getConversion()
          Get the Complex to real conversion flag
 int getCurrentWidth()
          Get the current width of the sample
 double[] getDataBuffer()
          Method to get the underlying double[] databuffer
 double getDouble(double x)
          Method to get the Double closest to the analogue value
 double getDouble(int i)
          Method to get a double data point.
 ptolemy.plot.Plot getPlot()
          Method to get the internal plot (if there is one)
 RealSignal getRealSignal()
          Get the current Signal as a RealSignal using the internal conversion flag
 RealSignal getRealSignal(int conversion)
          Get the current Signal as a RealSignal array using the specified conversion flag.
 int getSample(double t)
          Method to get the index of the samples closest t the speciied time, will be -1 of outside the Signal
 double getSampleInterval()
          Method to get the sample interval
 int getSpace()
          Method to get the space flag
 double getStart()
          Get the signal start time
 double getTime(int n)
          Get the time of the nth sample point, this will be a frequency if the data is in Fourier space.
 String getTitle()
          Method Get the title
 String getType()
          Method to get the type
 int getWidth()
          Get the width of the sample
 void mult(Complex c)
          Method to multiply the whole Signal by a Complex.
 void mult(double a)
          Method to muliply the whole Signal by a scalar
 void mult(double a, double b)
          Method to multiply the whole Signal by a complex specifed as two doubles.
 void mult(int i, Complex c)
          Method to multiply an element by a Complex.
 void mult(int i, double a)
          Method to multiply an element by a scalar
 void mult(int i, double a, double b)
          Method to multiply an element by a Complex
 void mult(Signal s)
          Method to multiply the current Signal by a specified Signal which must be of the same size, the result overwriting the contents of the current Signal.
 void multConjugate(Signal s)
          Method to multiply the current Signal by the Complex Conjugate of specified Signal which must be of the same size the result overwriting the contents of the current Signal.
 RealSignal powerSpectrum(boolean logPower)
          Method to get the PowerSpectrum as a RealDataArray In data is in real space, then it is automatically Fourier transformed using centreFourier.
 void setComplex(int i, Complex c)
          Method to set element with a Complex
 void setComplex(int i, double a, double b)
          Method to set element with a Complex
 void setConversion(int flag)
          Method to set the Complex to real conversion flag.
 void setDouble(int i, double v)
          Method to set and element with a double
 void setSampleFrequency(double freq)
          Method to set the sample interval by frequency.
 void setSampleInterval(double delta)
          Method to set the sample interval
 void setStart(double t)
          Method to set the signal start time
 void setTitle(String t)
          Method to set the title
 void toGraph(int ds, boolean line)
          Display the signal as a default PtPlot graph
 void toPlot(int ds, boolean line)
          Plot the signal to an interal plot.
 void toPlot(ptolemy.plot.Plot p, int ds, boolean line)
          Method to plot signal to a specifed plot.
 boolean toPrintWriter(PrintWriter out)
          Output the signal to a PrintWriter in a format acceptable to gnuplot
 boolean toTextFile(File file)
          Output signal to a text file
 boolean toTextFile(String fileName)
          Output signal to a text file.
 void weight(Window w)
          Method to apply a Window function to the Signal,.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected DataArray data
The DataArray to hold the data


fmt

protected static String fmt
Format string for output


plot

protected ptolemy.plot.Plot plot
Plot holding graphical information.

Constructor Detail

Signal

public Signal()
Method Detail

setTitle

public void setTitle(String t)
Method to set the title

Parameters:
t - the title

getTitle

public String getTitle()
Method Get the title

Returns:
String the title

getType

public String getType()
Method to get the type

Returns:
String the type

setStart

public void setStart(double t)
Method to set the signal start time

Parameters:
t - the start time

getStart

public double getStart()
Get the signal start time

Returns:
double the signal start time

setSampleInterval

public void setSampleInterval(double delta)
Method to set the sample interval

Parameters:
delta - the sampling internal

setSampleFrequency

public void setSampleFrequency(double freq)
Method to set the sample interval by frequency.

Parameters:
freq -

getSampleInterval

public double getSampleInterval()
Method to get the sample interval

Returns:
double the sample interval

getTime

public double getTime(int n)
Get the time of the nth sample point, this will be a frequency if the data is in Fourier space.

Returns:
double the time or frequency

getSample

public int getSample(double t)
Method to get the index of the samples closest t the speciied time, will be -1 of outside the Signal


getSpace

public int getSpace()
Method to get the space flag


getPlot

public ptolemy.plot.Plot getPlot()
Method to get the internal plot (if there is one)


getDataBuffer

public double[] getDataBuffer()
Method to get the underlying double[] databuffer

Returns:
double[] the databuffer

getWidth

public int getWidth()
Get the width of the sample

Returns:
int width of the signal

getCurrentWidth

public int getCurrentWidth()
Get the current width of the sample

Returns:
int current width.

getConversion

public int getConversion()
Get the Complex to real conversion flag

Returns:
int the conversion flag

setConversion

public void setConversion(int flag)
Method to set the Complex to real conversion flag. The default is Complex.MODULUS.

Parameters:
flag - the convesion flag

getComplex

public Complex getComplex(int i)
Method to get a Complex data point

Parameters:
i - the elemnt

getComplex

public Complex getComplex(double x)
Method to get the Complex closest to the analogue value

Parameters:
x - the continious variable

getDouble

public double getDouble(int i)
Method to get a double data point. If elemeent is complex, then the current conversion flag is used.

Parameters:
i - the element

getDouble

public double getDouble(double x)
Method to get the Double closest to the analogue value

Parameters:
x - the continious variable

setComplex

public void setComplex(int i,
                       Complex c)
Method to set element with a Complex

Parameters:
i - the element
c - the Complex

setComplex

public void setComplex(int i,
                       double a,
                       double b)
Method to set element with a Complex

Parameters:
i - the element
a - the real part
b - the imaginary part

setDouble

public void setDouble(int i,
                      double v)
Method to set and element with a double

Parameters:
i - the element
v - the value

add

public void add(int i,
                double a)
Method to add a scalar to an element.

Parameters:
i - the element
a - the scalar

mult

public void mult(int i,
                 double a)
Method to multiply an element by a scalar

Parameters:
i - the element
a - the scalar

add

public void add(int i,
                double a,
                double b)
Method to add a complex to an element.

Parameters:
i - the element index
a - the real part
b - the imaginary parts

mult

public void mult(int i,
                 double a,
                 double b)
Method to multiply an element by a Complex

Parameters:
i - the element index
a - the real part
b - the imaginary parts

add

public void add(int i,
                Complex c)
Method to add a Complex to an element.

Parameters:
i - the element index
c - to be added

mult

public void mult(int i,
                 Complex c)
Method to multiply an element by a Complex.

Parameters:
i - the element index
c - the multiplier

mult

public void mult(double a)
Method to muliply the whole Signal by a scalar

Parameters:
a - the scalar

mult

public void mult(double a,
                 double b)
Method to multiply the whole Signal by a complex specifed as two doubles. This is only valid if the data is Complex.

Parameters:
a - the real part
b - the imaginary.

mult

public void mult(Complex c)
Method to multiply the whole Signal by a Complex. This is only valid if the data is Complex.

Parameters:
c - the Complex multiplier.

conjugate

public void conjugate(int i)
Method to form the Complex conjugate of an element.

Parameters:
i - the element index

conjugate

public void conjugate()
Method to take conjugate of the whole Signal. If data is real this call is ignored.


weight

public void weight(Window w)
Method to apply a Window function to the Signal,. Works for all expect real function in Fourier space.

Parameters:
w - the Window fucntion

add

public void add(Signal s)
Method to add a specified Signal to the current Signal, both must be the same size.

This will work for all conbinations expect for current Signal being Real and specifed Signal being Complex.

Internally this uses direct array access so it much more efficient than loops with setter/getters.

Parameters:
s - the Signal to be added.

mult

public void mult(Signal s)
Method to multiply the current Signal by a specified Signal which must be of the same size, the result overwriting the contents of the current Signal.

This will work for all conbinations expect for current Signal being Real and specifed Signal being Complex.

Internal this uses uses direct array access so it much more efficient than loops with setter/getters.

Parameters:
s - the specified Signal

multConjugate

public void multConjugate(Signal s)
Method to multiply the current Signal by the Complex Conjugate of specified Signal which must be of the same size the result overwriting the contents of the current Signal.

If the current or specifed DataArray(s) are real, then this method is identical to mult(Signal)

Parameters:
s - the Signal
See Also:
mult(Signal)

fourier

public void fourier()
Method to take the unshifted Fourier transform. This will also change the sampling intervals.


centreFourier

public void centreFourier()
Method to form centred Fourier using applying checker pattern to shift DC the centre of the array.

This will only work for even dimensions, if called with data of odd size, an error message will be printed and the normal fourier() will be taken.


toPrintWriter

public boolean toPrintWriter(PrintWriter out)
Output the signal to a PrintWriter in a format acceptable to gnuplot


toTextFile

public boolean toTextFile(File file)
Output signal to a text file

Parameters:
file - the File to output to

toTextFile

public boolean toTextFile(String fileName)
Output signal to a text file.

Parameters:
fileName - the File to output to

toPlot

public void toPlot(ptolemy.plot.Plot p,
                   int ds,
                   boolean line)
Method to plot signal to a specifed plot.


toPlot

public void toPlot(int ds,
                   boolean line)
Plot the signal to an interal plot. If this is the first call, a new plot will be allocated, if not the data set will be added to the current plot

Parameters:
ds - the data set
line - draw with line

toGraph

public void toGraph(int ds,
                    boolean line)
Display the signal as a default PtPlot graph

Parameters:
ds - the dataset
line - draw a line

fillSine

public void fillSine(double amp,
                     double freq,
                     double phase,
                     double offset)
Method to fill the signal with a sin() function using the sample time.

Parameters:
amp - amplitude of the sin
freq - frequency of the sin
phase - starting phase
offset - constant offset
See Also:
getTime(int)

getRealSignal

public RealSignal getRealSignal(int conversion)
Get the current Signal as a RealSignal array using the specified conversion flag.

If the current DataArray is RealDataArray in real space then the current DataArray is returned, else a new ReadDataArray of the correct dimensions is returned.

Parameters:
conversion - the conversion flag
Returns:
RealSignal the converted Real array

getRealSignal

public RealSignal getRealSignal()
Get the current Signal as a RealSignal using the internal conversion flag

Returns:
RealSignal the converted RealSignal

powerSpectrum

public RealSignal powerSpectrum(boolean logPower)
Method to get the PowerSpectrum as a RealDataArray In data is in real space, then it is automatically Fourier transformed using centreFourier.

After this call the current DataArray will be in Fourie space.

Parameters:
logPower - if true the log power formed, else modulus squared used.
Returns:
RealSignal the power spectrum.