Skip to content

[breeze.signal] Designing Filters

Kenta Takagaki edited this page Aug 14, 2014 · 8 revisions

Use the following functions to design FIR and IIR filters in breeze.signal. The functions will output either FIRKernel1D or IIRKernel1D objects, which can be fed to breeze.signal.filter. (2D filters are not supported yet.)

#FIR Filters

Window method (firwin)

object FilterFirWindowed{
  def design(order: OptOrder, omega: OptOmega, window: OptWindow, 
            tpe: OptTpe, samplingRate: Double = 2d): FIRKernel1D[Double]
}

Equiripple (firls)

Decimation Filter

object FilterDecimation{
  def design(order: OptOrder, decimationFactor: Int): FIRKernel1D[Double]
}

#IIR Filters

Butterworth (butter)

object FilterButterworth {
  def design(order = 10, omega = 0.2, tpe = Opt.LowPass): IIRKernel1D = {...}
  def order(omega: Double or (Double, Double),  attenuationPass: Double, attenuationStop: Double, type: OptType): Int = { .... }
}

Elliptical (ellip)

#Options Common to all Filters ###Filter Order

val order: OptOrder
//the order variable can be specified as an Int, which will be implicit'ed to 'OptOrder'
implicit def intToOptOrder(n: Int): OptOrder

//the order variable can be specified as Automatic, which will determine the necessary order based on filter parameters
case object OptOrder.Automatic

###Sampling Rate

//default is nyqist frequency
val samplingRate: Double = 2d

###Filter Frequencies

//specified in multiples of the `samplingRate` option above.
//If sampling rate is the default Nyqist frequency (i.e. samplingRate == 2),
//values must be in (0,1)
val omega: OptOmega
//can be specified as a Double for high-pass or low-pass filters
//(i.e. filters with only one cutoff frequency)
implicit def doubleToOptOmega(omega: Double): OptOmega

//can be specified as a Tuple of Doubles for band-stop or band-pass filters
//(i.e. filters with 2 cutoff frequencies
implicit def tuple2ToOptOmega(omega: Tuple2[Double, Double]): OptOmega

###Filter Type

abstract class OptTpe extends Opt

object OptTpe{
  case object LowPass extends OptTpe
  case object HighPass extends OptTpe
  case object BandPass extends OptTpe
  case object BandStop extends OptTpe
}