PamUtils
Class PamUtils

java.lang.Object
  extended by PamUtils.PamUtils

public class PamUtils
extends java.lang.Object

Author:
Doug Gillespie

Constructor Summary
PamUtils()
           
 
Method Summary
static double constrainedAngle(double angle)
          Force an angle to sit 0<= angle < 360.
static double constrainedAngle(double angle, double maxAngle)
          Force an angle to sit within some range.
static java.lang.String formatFrequency(double f)
          Format a frequency in Hz as Hz, kHz, MHz, etc.
static int[] getChannelArray(int channelMap)
          Turn a bitmap into an array of channel numbers.
static java.lang.String getChannelList(int channelMap)
           
static int getChannelPos(int singleChannel, int channelBitmap)
          Works out the index of a particular channel in a channel list - often, if channelBitmap is a set of continuous channels starting with 0, then the channel pos is the same as the single channel number.
static int[] getChannelPositionLUT(int channelBitmap)
           
static int getHighestChannel(int channelBitmap)
           
static int getLowestChannel(int channelBitmap)
           
static int getMinFftLength(long len)
           
static int getNthChannel(int singleChannel, int channelBitmap)
          get's the number of the nth used channel in a bitmap.
static int getNumChannels(int channelBitmap)
           
static int getSingleChannel(int channelMap)
          check that the bits represent a single channel and return the number of that channel
static int[] getSortedInds(int[] data)
          Leave data alone, but create a list of indexes which will give the ascending order of data.
static double linterp(double x0, double x1, double y0, double y1, double x)
          Linear interpolation.
static int log2(int n)
           
static int makeChannelMap(int nChannels)
          Make a simple bitmap for nChannels of data, i.e.
static int makeChannelMap(int[] channelList)
          Make a channel bitmap from a list.
static int makeChannelMap(int nChannels, int[] channelList)
          Deprecated.  
static double roundNumber(double number, double step)
           
static int SetBit(int bitMap, int bitNumber, boolean bitSet)
           
static int SetBit(int bitMap, int bitNumber, int bitValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PamUtils

public PamUtils()
Method Detail

getSingleChannel

public static int getSingleChannel(int channelMap)
check that the bits represent a single channel and return the number of that channel

Parameters:
channelMap - bitmap for multiple channels
Returns:
singel channel (or -1 if >1 or zero channels)

getNumChannels

public static int getNumChannels(int channelBitmap)

getChannelPos

public static int getChannelPos(int singleChannel,
                                int channelBitmap)
Works out the index of a particular channel in a channel list - often, if channelBitmap is a set of continuous channels starting with 0, then the channel pos is the same as the single channel number. However, if there are gaps in the channelBitmap, then the channel pos will be < than the channel Number.

Parameters:
singleChannel -
channelBitmap -
Returns:
the channel position in the channel list

getNthChannel

public static int getNthChannel(int singleChannel,
                                int channelBitmap)
get's the number of the nth used channel in a bitmap. e.g. if the channelBitmap were 0xc (1100), then the 0th channel would be 2 and the 1st channel would be 3.

Parameters:
singleChannel - nth channel in a list
channelBitmap - bitmap of all used channels.
Returns:
true channel number

getChannelPositionLUT

public static int[] getChannelPositionLUT(int channelBitmap)

getHighestChannel

public static int getHighestChannel(int channelBitmap)

getLowestChannel

public static int getLowestChannel(int channelBitmap)

makeChannelMap

public static int makeChannelMap(int nChannels)
Make a simple bitmap for nChannels of data, i.e.

if nChannels = 1, map = 1

if nChannels = 2, map = 3

if nChannels = 3, map = 7

if nChannels = 4, map = 15

etc.

Parameters:
nChannels -
Returns:
a bitmap representing the set channels

makeChannelMap

public static int makeChannelMap(int nChannels,
                                 int[] channelList)
Deprecated. 

Make a channel map from a list

Parameters:
nChannels - number of elements in the list
channelList - list
Returns:
channel bitmap

makeChannelMap

public static int makeChannelMap(int[] channelList)
Make a channel bitmap from a list.

Parameters:
channelList - channel list
Returns:
bitmap of channels.

SetBit

public static int SetBit(int bitMap,
                         int bitNumber,
                         int bitValue)

SetBit

public static int SetBit(int bitMap,
                         int bitNumber,
                         boolean bitSet)

getMinFftLength

public static int getMinFftLength(long len)

log2

public static int log2(int n)

linterp

public static double linterp(double x0,
                             double x1,
                             double y0,
                             double y1,
                             double x)
Linear interpolation. Define f() as the linear mapping from the domain [x0,x1] to the range [y0,y1]. Return y=f(x) according to this mapping.

author Dave Mellinger


getChannelList

public static java.lang.String getChannelList(int channelMap)

getChannelArray

public static int[] getChannelArray(int channelMap)
Turn a bitmap into an array of channel numbers.

Parameters:
channelMap - channel map
Returns:
channel list array

constrainedAngle

public static double constrainedAngle(double angle)
Force an angle to sit 0<= angle < 360.

Parameters:
angle - input angle (degrees)
Returns:
output angle (degrees)

constrainedAngle

public static double constrainedAngle(double angle,
                                      double maxAngle)
Force an angle to sit within some range.

Parameters:
angle - input angle (degrees)
maxAngle - maximum angle in degrees
Returns:
output angle (degrees)

roundNumber

public static double roundNumber(double number,
                                 double step)

formatFrequency

public static java.lang.String formatFrequency(double f)
Format a frequency in Hz as Hz, kHz, MHz, etc.

Parameters:
f - frequency value in Hz
Returns:
Formatted string

getSortedInds

public static int[] getSortedInds(int[] data)
Leave data alone, but create a list of indexes which will give the ascending order of data.
Uses a simple bubble sort, so only suitable for short arrays.

Parameters:
data - array to sort
Returns:
sort indexes