com.oregondsp.signalProcessing
Class Sequence

java.lang.Object
  extended by com.oregondsp.signalProcessing.Sequence

public class Sequence
extends java.lang.Object

Class to implement basic signal processing operations on scalar sequences. This class can be used in two ways. Objects of this class may be instantiated to represent sequences and in that case will serve as a containers for sequence values (float precision). For this use, methods are supplied that alter or operate on the values of the contained sequence. Alternatively, the methods (where it makes sense) are supplied in static form. The class may be used to operate on the user's float arrays without need to instantiate a Sequence object. This class is far from comprehensive; it primarily implements methods used by other classes in this package.


Constructor Summary
Sequence(float[] x)
          Instantiates a new sequence from an array of float values.
Sequence(int N)
          Instantiates a new sequence of all zeros, of length N samples.
 
Method Summary
static void alias(float[] src, float[] dst)
          Method to alias a source sequence into a destination sequence.
 void alias(int N)
          Aliases the current sequence into a smaller sequence.
static void circularShift(float[] y, int shift)
          Performs a circular shift of a sequence.
 void circularShift(int shift)
          Performs a circular shift on this sequence, in-place
static void decimate(float[] y, int decrate, float[] ydecimated)
          Decimates a sequence by a specified rate.
 void decimate(int decrate)
          Decimates this sequence in-place.
 float get(int index)
          Accessor for an individual value of the sequence.
 float[] getArray()
          Accessor for the entire array of sequence values.
 void reverse()
          Reverses this sequence in-place.
static void reverse(float[] y)
          Reverses a sequence in place.
 void rmean()
          Removes the mean of this sequence in-place.
static void rmean(float[] y)
          Removes the mean of a sequence.
static void stretch(float[] y, int rate, float[] ystretched)
          Stretches a sequence by a specified rate.
 void stretch(int rate)
          Stretches this sequence by a specified rate, in place.
 void timesEquals(float f)
          Multiplies this sequence by a constant, in-place.
static void timesEquals(float[] y, float f)
          Multiplies a sequence by a constant.
static void zeroShift(float[] y, int shift)
          Shifts a sequence left or right and pads with zeros (unlike the circular shift, sequence values are lost).
 void zeroShift(int shift)
          Performs a shift on this sequence with zero-fill.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sequence

public Sequence(float[] x)
Instantiates a new sequence from an array of float values.

Parameters:
x - float[] containing the Sequence values.

Sequence

public Sequence(int N)
Instantiates a new sequence of all zeros, of length N samples.

Parameters:
N - int specifying the length of the sequence.
Method Detail

alias

public static void alias(float[] src,
                         float[] dst)
Method to alias a source sequence into a destination sequence. Source value src[n] is added to dst[ mod(n,dst.length) ].

Parameters:
src - float[] containing the source sequence.
dst - float[] containing the destination sequence.

alias

public void alias(int N)
Aliases the current sequence into a smaller sequence. Modifies this Sequence.

Parameters:
N - New length of the sequence, and alias modulus.

get

public float get(int index)
Accessor for an individual value of the sequence.

Parameters:
index - int containing the index of the desired sequence value.
Returns:
Sequence value at index.

getArray

public float[] getArray()
Accessor for the entire array of sequence values. Allows the sequence to be modified.

Returns:
float[] reference to the sequence. Does not return a copy.

reverse

public static void reverse(float[] y)
Reverses a sequence in place.

Parameters:
y - float[] containing the sequence to be reversed.

reverse

public void reverse()
Reverses this sequence in-place.


rmean

public static void rmean(float[] y)
Removes the mean of a sequence.

Parameters:
y - float[] specifying the sequence to be demeaned.

rmean

public void rmean()
Removes the mean of this sequence in-place.


circularShift

public static void circularShift(float[] y,
                                 int shift)
Performs a circular shift of a sequence.

Parameters:
y - float[] containing sequence to be shifted.
shift - int specifying the size and direction of the shift. A negative number specifies a left shift, a positive number, a right shift. A zero shift leaves the sequence unchanged.

circularShift

public void circularShift(int shift)
Performs a circular shift on this sequence, in-place

Parameters:
shift - int specifying the size and direction of the shift. A negative number specifies a left shift and a positive number, a right shift. A zero shift leaves the sequence unchanged.

zeroShift

public static void zeroShift(float[] y,
                             int shift)
Shifts a sequence left or right and pads with zeros (unlike the circular shift, sequence values are lost).

Parameters:
y - float[] containing the sequence to be shifted.
shift - int specifying the direction and size of the shift. A negative shift is to the left. Zeros are fed in from the right in that case. A positive shift is to the right. Zeros are fed in from the left in that case. A zero shift leaves the sequence unchanged.

zeroShift

public void zeroShift(int shift)
Performs a shift on this sequence with zero-fill.

Parameters:
shift - int specifying the direction and size of the shift. A negative shift is to the left. Zeros are fed in from the right in that case. A positive shift is to the right. Zeros are fed in from the left in that case. A zero shift leaves the sequence unchanged.

decimate

public static void decimate(float[] y,
                            int decrate,
                            float[] ydecimated)
Decimates a sequence by a specified rate.

Parameters:
y - float[] containing the sequence to be decimated.
decrate - int specifying the decimation rate.
ydecimated - float[] containing the decimated sequence.

decimate

public void decimate(int decrate)
Decimates this sequence in-place.

Parameters:
decrate - int specifying the decimation rate.

stretch

public static void stretch(float[] y,
                           int rate,
                           float[] ystretched)
Stretches a sequence by a specified rate. This operation spreads the sequence values out and fills between them with interstitial zeros. It is a basic operation needed for interpolation by an integer rate.

Parameters:
y - float[] containing the sequence to be stretched.
rate - int containing the stretch rate.
ystretched - float[] containing the stretched sequence.

stretch

public void stretch(int rate)
Stretches this sequence by a specified rate, in place. This operation spreads the sequence values out and fills between them with interstitial zeros. It is a basic operation needed for interpolation by an integer rate.

Parameters:
rate - int containing the stretch rate (factor).

timesEquals

public static void timesEquals(float[] y,
                               float f)
Multiplies a sequence by a constant.

Parameters:
y - float[] containing the sequence to be scaled.
f - float containing the multiplicative constant.

timesEquals

public void timesEquals(float f)
Multiplies this sequence by a constant, in-place.

Parameters:
f - float specifying the multiplicative constant.