Description Usage Arguments Details Value Author(s) Examples
The function calculates and plots the amplitude/energy spectrum via the FFT and also the corresponding frequencies or periods.
1 2 3 | calculateSpectrum(timeSignal, timeStep = 1, xAxis = "period",
yAxis = "amplitude", xAxisLimits = c(0, 1), region = "half",
plotFlag = TRUE)
|
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. |
This function takes a numeric vector containing the time series and returns the corresponding frequency spectrum over the full bandwidth 0Hz -> sample frequency.
Returns a list containing information about the time and frequency paratmeters, the original time series, the frequency spectrum and quantiles of the spectral energy.
Daniel Beiter, daniel.beiter@gfz-potsdam.de
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.