Skip to contents

Downsample a signal by an integer factor

Usage

downsample(x, n, phase = 0)

# Default S3 method
downsample(x, n, phase = 0)

# S3 method for class 'ts'
downsample(x, n, phase = 0)

Arguments

x

input data, specified as a numeric vector or matrix. In case of a vector it represents a single signal; in case of a matrix each column is a signal.

n

downsampling factor, specified as a positive integer.

phase

offset, specified as a positive integer from 0 to n - 1. Default: 0.

Details

This provides a simple wrapper around the gsignal::downsample() function with support for the time series functionality found in the base R stats::ts() functions and friends.

Examples

x=1:10
x
#>  [1]  1  2  3  4  5  6  7  8  9 10
downsample(x, 2)
#> [1] 1 3 5 7 9
x3=matrix(1:30, ncol=3, dimnames=list(NULL, c("x", "y", "z")))
x3
#>        x  y  z
#>  [1,]  1 11 21
#>  [2,]  2 12 22
#>  [3,]  3 13 23
#>  [4,]  4 14 24
#>  [5,]  5 15 25
#>  [6,]  6 16 26
#>  [7,]  7 17 27
#>  [8,]  8 18 28
#>  [9,]  9 19 29
#> [10,] 10 20 30
downsample(x3, 2)
#>      x  y  z
#> [1,] 1 11 21
#> [2,] 3 13 23
#> [3,] 5 15 25
#> [4,] 7 17 27
#> [5,] 9 19 29
xts=stats::ts(1:10, start=0, deltat=0.1)
xts
#> Time Series:
#> Start = c(0, 1) 
#> End = c(0, 10) 
#> Frequency = 10 
#>  [1]  1  2  3  4  5  6  7  8  9 10
downsample(xts, 2)
#> Time Series:
#> Start = c(0, 1) 
#> End = c(0, 5) 
#> Frequency = 5 
#> [1] 1 3 5 7 9

x3ts=stats::ts(matrix(1:30, ncol=3, dimnames=list(NULL, c("x", "y", "z"))), start=0, deltat=0.1)
x3ts
#> Time Series:
#> Start = c(0, 1) 
#> End = c(0, 10) 
#> Frequency = 10 
#>      x  y  z
#> 0.0  1 11 21
#> 0.1  2 12 22
#> 0.2  3 13 23
#> 0.3  4 14 24
#> 0.4  5 15 25
#> 0.5  6 16 26
#> 0.6  7 17 27
#> 0.7  8 18 28
#> 0.8  9 19 29
#> 0.9 10 20 30
downsample(x3ts, 2)
#> Time Series:
#> Start = c(0, 1) 
#> End = c(0, 5) 
#> Frequency = 5 
#>     x  y  z
#> 0.0 1 11 21
#> 0.2 3 13 23
#> 0.4 5 15 25
#> 0.6 7 17 27
#> 0.8 9 19 29