plotFilterResponse: Function plotting the filter frequency response.

Description Usage Arguments Details Value Author(s) Examples

Description

The function calculates and plots the frequency response of the given list of filters.

Usage

1
2
plotFilterResponse(filterList, timeStep = 1, resolution = 512,
  xAxis = "period", xAxisLimits = c(0, 1), returnPlottingData = FALSE)

Arguments

filterList

List of filters of class Ma or Arma; FIR or IIR filters as derived from package signal

timeStep

Numeric value (default: 1); time between two samples.

resolution

Numeric value (default: 512); defining frequency resolution of filter response.

xAxis

Character string (default: "period"); Either "frequency" or "period". Defining if on the x-axis the linear frequency or the reciprocal oscillation period is displayed.

xAxisLimits

Numeric vector of length 2 (default: c(0, 1)); Defines the range of the spectrum being displayed. 0 -> 0Hz/Inf Period, 1 -> Nyquist Frequency/Nyquist Period (twice the time step). The range is the same as for band edges during filter design in package signal (i.e. fir1())

returnPlottingData

Logical value; Should plot data be returned as data frame.

Details

This function takes a list of filters either developed via the signal package (i.e. fir1() or butter()), or custom developed filters such as moving average, which need to have the class Ma added manually. Several arguments allow customizing the plot generated by the function. The main purpose is to provide the right scaling on the x-Axis which is often a problem for beginners. Also, the filter response of Arma models can be calculated and plotted.

Value

Plots the filter response of all filters in argument filterList. Returns a data frame in long format with all plotting information.

Author(s)

Daniel Beiter, daniel.beiter@gfz-potsdam.de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
### plot FIR filters with various cutoff frequencies
cutoffFrequencies <- seq(0.1, 0.9, 0.1)
lowPassFIR <- lapply(cutoffFrequencies, function(x) signal::fir1(n = 10, w = x, type = "low"))
names(lowPassFIR) <- paste0("Cutoff frequency=", cutoffFrequencies)
plotFilterResponse(lowPassFIR)

### plot filter repsonse of moving average with various window lengths
windowLength <- seq(2, 5)
movingAverage <- lapply(windowLength, function(x) {averageFilter <- rep(1/x, x); class(averageFilter) <- "Ma"; averageFilter})
names(movingAverage) <- c(paste0("Moving Average n=", windowLength))
plotFilterResponse(movingAverage)

### comparing moving average with FIR filter
movingAverage <- rep(1/10, 10)
class(movingAverage) <- "Ma"
filterList <- list(signal::fir1(n = 15, w = 0.01, type = "low"), movingAverage)
names(filterList) <- c("FIR_n=15_w=0.01", "MA_n=10")
plotFilterResponse(filterList)

baender/fats documentation built on May 12, 2019, 7:41 a.m.