edu.mines.jtk.dsp
Class Real1

java.lang.Object
  extended by edu.mines.jtk.dsp.Real1

public class Real1
extends java.lang.Object

A real-valued sampled function of one variable. A Real1 combines a Sampling with a reference to an an array of function values. In this way, a Real1 wraps an array of function values. Because array values are referenced (not copied), the cost of wrapping any array with a Real1 is small.

One consequence of referencing the array of function values is that changes to elements in such an array are reflected in all Real1s that reference that array. If this behavior is not desired, the copy constructor Real1(Real1) creates a new array copy of function values.

Version:
2005.08.25
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
Real1(float[] v)
          Constructs a function with specified values and default sampling.
Real1(int n, double d, double f)
          Constructs a function with specified sampling and values zero.
Real1(int n, double d, double f, float[] v)
          Constructs a function with specified sampling and values.
Real1(Real1 r)
          Constructs a copy of the specified sampled function.
Real1(Sampling s)
          Constructs a function with specified sampling and values zero.
Real1(Sampling s, float[] v)
          Constructs a function with specified sampling and values.
 
Method Summary
static Real1 add(float ar, Real1 rb)
          Returns the sum ar + rb of constant ar and function rb.
static Real1 add(Real1 ra, float br)
          Returns the sum ra + br of function ra and constant br.
static Real1 add(Real1 ra, Real1 rb)
          Returns the sum ra + rb of two functions ra and rb.
 Real1 convolve(Real1 ra)
          Convolves this function with the specified function.
static Real1 div(float ar, Real1 rb)
          Returns the quotient ar / rb of constant ar and function rb.
static Real1 div(Real1 ra, float br)
          Returns the quotient ra / br of function ra and constant br.
static Real1 div(Real1 ra, Real1 rb)
          Returns the quotient ra / rb of two functions ra and rb.
static Real1 fill(double ar, int n)
          Returns a function with constant values.
static Real1 fill(double ar, Sampling s)
          Returns a function with constant values.
 Sampling getFourierSampling(int nmin)
          Gets sampling for the Fourier transform of this function.
 Sampling getSampling()
          Gets the sampling for this function.
 float[] getValues()
          Gets the array of function values for this function.
static Real1 mul(float ar, Real1 rb)
          Returns the product ar * rb of constant ar and function rb.
static Real1 mul(Real1 ra, float br)
          Returns the product ra * br of function ra and constant br.
static Real1 mul(Real1 ra, Real1 rb)
          Returns the product ra * rb of two functions ra and rb.
 Real1 plus(float ar)
          Returns the sum this + ar of this function and constant ar.
 Real1 plus(Real1 ra)
          Returns the sum this + ra of functions this and ra.
static Real1 ramp(double fv, double dv, int nv)
          Returns a sampled linear (ramp) function.
static Real1 ramp(double fv, double dv, Sampling s)
          Returns a sampled linear (ramp) function.
 Real1 resample(Sampling s)
          Returns this function resampled to have the specified sampling.
static Real1 sub(float ar, Real1 rb)
          Returns the difference ar - rb of constant ar and function rb.
static Real1 sub(Real1 ra, float br)
          Returns the difference ra - br of function ra and constant br.
static Real1 sub(Real1 ra, Real1 rb)
          Returns the difference ra - rb of two functions ra and rb.
static Real1 zero(int n)
          Returns a sampled function with values zero.
static Real1 zero(Sampling s)
          Returns a sampled function with values zero.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Real1

public Real1(Sampling s)
Constructs a function with specified sampling and values zero.

Parameters:
s - the sampling.

Real1

public Real1(float[] v)
Constructs a function with specified values and default sampling. The default sampling has number (count) of samples = v.length, sampling interval (delta) = 1.0 and first sample value (first) = 0.0.

Parameters:
v - array of function values; referenced, not copied.

Real1

public Real1(Sampling s,
             float[] v)
Constructs a function with specified sampling and values.

Parameters:
s - the sampling.
v - array of function values; referenced, not copied. The array length v.length must equal the number of samples in s.

Real1

public Real1(int n,
             double d,
             double f)
Constructs a function with specified sampling and values zero.

Parameters:
n - the number (count) of samples.
d - the sampling interval (delta).
f - the value of the first sample.

Real1

public Real1(int n,
             double d,
             double f,
             float[] v)
Constructs a function with specified sampling and values.

Parameters:
n - the number (count) of time samples.
d - the sampling interval (delta).
f - the value of the first sample.
v - array of function values; referenced, not copied. The array length v.length must equal n.

Real1

public Real1(Real1 r)
Constructs a copy of the specified sampled function. This constructor copies (does not reference) the array of function values from the specified sampled function.

Parameters:
r - the function to copy.
Method Detail

getSampling

public Sampling getSampling()
Gets the sampling for this function.

Returns:
the sampling.

getValues

public float[] getValues()
Gets the array of function values for this function.

Returns:
the array of function values; by reference, not by copy.

resample

public Real1 resample(Sampling s)
Returns this function resampled to have the specified sampling.

If the specified sampling is compatible with the sampling of this function, this method copies the function values in the overlap between the two samplings, and assigns zero values to the function values where the two samplings do not overlap.

If the specified sampling is incompatible with the sampling of this function, then this method must interpolate or decimate this function Neither interpolation or decimation is supported, yet.

Parameters:
s - the sampling.
Returns:
the resampled function.
Throws:
java.lang.UnsupportedOperationException - if the specified sampling is incompatible with this sampling.

plus

public Real1 plus(Real1 ra)
Returns the sum this + ra of functions this and ra. The samplings of this and ra must be equivalent.

Parameters:
ra - a function.
Returns:
the sum.

plus

public Real1 plus(float ar)
Returns the sum this + ar of this function and constant ar.

Parameters:
ar - a constant.
Returns:
the sum.

convolve

public Real1 convolve(Real1 ra)
Convolves this function with the specified function. The two functions must be uniformly sampled with equal sampling intervals.

Parameters:
ra - the function with which to convolve.
Returns:
the convolution function.

getFourierSampling

public Sampling getFourierSampling(int nmin)
Gets sampling for the Fourier transform of this function. The first sample value will be zero, because the Fourier transform of a real function has conjugate-symmetry.

A minimum number of Fourier transform samples must be specified, and the number of samlpes in the returned sampling will not be less than the larger of that specified minimum and the number of samples in this function.

Parameters:
nmin - the minimum number of samples after Fourier transform.
Returns:
the Fourier transform sampling.

zero

public static Real1 zero(int n)
Returns a sampled function with values zero.

Parameters:
n - the number of samples.
Returns:
the function.

zero

public static Real1 zero(Sampling s)
Returns a sampled function with values zero.

Parameters:
s - the sampling.
Returns:
the function.

fill

public static Real1 fill(double ar,
                         int n)
Returns a function with constant values.

Parameters:
ar - the constant.
n - the number of samples.
Returns:
the function.

fill

public static Real1 fill(double ar,
                         Sampling s)
Returns a function with constant values.

Parameters:
ar - the constant.
s - the sampling.
Returns:
the function.

ramp

public static Real1 ramp(double fv,
                         double dv,
                         int nv)
Returns a sampled linear (ramp) function. The function values are fv+iv*dv, for iv in [0:nv).

Parameters:
fv - the first function value.
dv - the function value delta.
nv - the number of values.
Returns:
the function.

ramp

public static Real1 ramp(double fv,
                         double dv,
                         Sampling s)
Returns a sampled linear (ramp) function. The function values are fv+dv*(s-f), for s = f, f+d, ..., f+d*(n-1), where n, d, and f are the sampling count, delta, and first value.

Parameters:
fv - the first function value.
dv - the function value delta.
s - the sampling.
Returns:
the function.

add

public static Real1 add(Real1 ra,
                        Real1 rb)
Returns the sum ra + rb of two functions ra and rb. The samplings of ra and rb must be equivalent.

Parameters:
ra - a function.
rb - a function.
Returns:
the sum.

add

public static Real1 add(float ar,
                        Real1 rb)
Returns the sum ar + rb of constant ar and function rb.

Parameters:
ar - a constant.
rb - a function.
Returns:
the sum.

add

public static Real1 add(Real1 ra,
                        float br)
Returns the sum ra + br of function ra and constant br.

Parameters:
ra - a function.
br - a constant.
Returns:
the sum.

sub

public static Real1 sub(Real1 ra,
                        Real1 rb)
Returns the difference ra - rb of two functions ra and rb. The samplings of ra and rb must be equivalent.

Parameters:
ra - a function.
rb - a function.
Returns:
the difference.

sub

public static Real1 sub(float ar,
                        Real1 rb)
Returns the difference ar - rb of constant ar and function rb.

Parameters:
ar - a constant.
rb - a function.
Returns:
the sum.

sub

public static Real1 sub(Real1 ra,
                        float br)
Returns the difference ra - br of function ra and constant br.

Parameters:
ra - a function.
br - a constant.
Returns:
the sum.

mul

public static Real1 mul(Real1 ra,
                        Real1 rb)
Returns the product ra * rb of two functions ra and rb. The samplings of ra and rb must be equivalent.

Parameters:
ra - a function.
rb - a function.
Returns:
the difference.

mul

public static Real1 mul(float ar,
                        Real1 rb)
Returns the product ar * rb of constant ar and function rb.

Parameters:
ar - a constant.
rb - a function.
Returns:
the sum.

mul

public static Real1 mul(Real1 ra,
                        float br)
Returns the product ra * br of function ra and constant br.

Parameters:
ra - a function.
br - a constant.
Returns:
the sum.

div

public static Real1 div(Real1 ra,
                        Real1 rb)
Returns the quotient ra / rb of two functions ra and rb. The samplings of ra and rb must be equivalent.

Parameters:
ra - a function.
rb - a function.
Returns:
the difference.

div

public static Real1 div(float ar,
                        Real1 rb)
Returns the quotient ar / rb of constant ar and function rb.

Parameters:
ar - a constant.
rb - a function.
Returns:
the sum.

div

public static Real1 div(Real1 ra,
                        float br)
Returns the quotient ra / br of function ra and constant br.

Parameters:
ra - a function.
br - a constant.
Returns:
the sum.