calculateSpectrum: Function calculating and plotting the amplitude spectrum.

Description Usage Arguments Details Value Author(s) Examples

Description

The function calculates and plots the amplitude/energy spectrum via the FFT and also the corresponding frequencies or periods.

Usage

1
2
3
calculateSpectrum(timeSignal, timeStep = 1, xAxis = "period",
  yAxis = "amplitude", xAxisLimits = c(0, 1), region = "half",
  plotFlag = TRUE)

Arguments

timeSignal

Numeric vector; Time signal which should be transformed into the frequency domain.

timeStep

Numeric value (default: 1); Elapsed time between two data points.

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.

yAxis

Character string (default: "amplitude"); Either "amplitude" or "energy". The spectral energy is proportional to the square of the amplitude. Normalized by the maximum energy.

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())

region

Character string (default: "half"); Either "half" or "whole". Defines wether the region till the Nyquist frequency is shown or the range until the sample frequency with aliases.

plotFlag

Logical value (default: TRUE); Defining if amplitude/energy spectrum should be plotted or not.

Details

This function takes a numeric vector containing the time series and returns the corresponding frequency spectrum over the full bandwidth 0Hz -> sample frequency.

Value

Returns a list containing information about the time and frequency paratmeters, the original time series, the frequency spectrum and quantiles of the spectral energy.

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
N <- 200 # number of samples
d_t <- 2 # time step (temporal resolution)
A_1 <- 3 # signal amplitude
A_2 <- 5
A_3 <- 2
T_1 <- 5 # signal periods
T_2 <- 10
T_3 <- 25

t <- seq(from = 0, length.out = N, by = d_t) # setting up time vector
y <- A_1 * cos(2*pi / T_1 * t) +
     A_2 * cos(2*pi / T_2 * t) +
     A_3 * cos(2*pi / T_3 * t) # calculating signal values

frequencySpectrum <- calculateSpectrum(timeSignal = y, timeStep = d_t) # calculates the frequency spectrum

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