decz
Recursive sampling rate decimator
Syntax
[y,z] = decz(x,df) % Matlab & Octave [y,Z] = decz(x,Z) % Matlab & Octave list <- decz(x, df=NULL, Z=NULL, nf=12, frbw=0.8) # R
Description
Recursive sampling rate decimator. This is a version of decdc that can be run iteratively over a long data set, e.g., to decimate an entire recording that is too large to be read into memory. See wavdec() for a use of this function to decimate an entire WAV format file.
1. First call to decz, use the following format:
[y,z] = decz(x,df) % Matlab & Octave
2. Subsequent calls to decz for contiguous input data
[y,z] = decz(x,z) % Matlab & Octave
3.Final call to decz when there is no more input data
y = decz([],z) % Matlab & Octave
Each output y in the above contains a segment of the decimated signal and so these need to be concatenated. See example below.
Inputs
Matlab & Octave
Input var | Description | Units | Default value |
---|---|---|---|
x | x is a vector or matrix containing the signal(s) to be decimated. If x is a matrix, each column is decimated separately. | N/A | N/A |
df | Decimation factor. The output sampling rate is the input sampling rate divided by df. df must be an integer greater than 1.df can also be a three element vector in which case: - df(1) is the decimation factor - df(2) is the number of output samples spanned by the filter (default value is 12). A larger value makes the filter steeper. - df(3) is the fractional bandwidth of the filter (default value is 0.8) relative to the output Nyquist frequency.If df(2) is greater than 12, df(3) can be closer to 1. | N/A | N/A |
Z | 'state' structure that is generated by a previous call to decz.This is how the function keeps track of filter internal values (i.e., memory) from call-to-call. | N/A | N/A |
R
Input var | Description | Units | Default value |
---|---|---|---|
x | A vector, matrix, or tag data list containing the signal(s) to be decimated. If x is a matrix, each column is decimated separately. If inputs df and Z are both provided, then the value of df stored in Z will override the user-provided df. | N/A | N/A |
df | The decimation factor. The output sampling rate is the input sampling rate divided by df. df must be an integer greater than 1. df can also be a three element vector in which case: df(1) is the decimation factor; df(2) is the number of output samples spanned by the filter (default value is 12). A larger value makes the filter steeper; df(3) is the fractional bandwidth of the filter (default value is 0.8) relative to the output Nyquist frequency. If df(2) is greater than 12, df(3) can be closer to 1. | N/A | .8 |
nf | The number of output samples spanned by the filter (default value is 12). A larger value makes the filter steeper. | N/A | 12 |
frbw | The fractional bandwidth of the filter (default value is 0.8) relative to the output Nyquist frequency. If nf is greater than 12, frbw can be closer to 1. | N/A | .8 |
Z | The 'state' list that is generated by a previous call to decz. This is how the function keeps track of filter internal values (i.e., memory) from call-to-call. | N/A | N/A |
Outputs
Matlab & Octave
Output var | Description | Units |
---|---|---|
y | is the decimated signal vector or matrix. It has the same number of columns as x but has, on average, 1/df of the rows. | N/A |
R
Output var | Description | Units |
---|---|---|
y | The decimated signal vector or matrix. It has the same number of columns as x but has, on average, 1/df of the rows. | N/A |
Z | The state list (for internal tracking of filter internal values). Contains elements df (the decimation factor), nf (used to compute the filter length), frbw (the bandwidth of the filter relative to the new Nyquist frequency), h (the FIR filter coefficients), n (the filter length), z (padded signal used for filtering), and ov (“overflow” samples to be passed to future iterations). | N/A |
Notes & assumptions
- Decimation is performed in the same way as for decdc. The group delay of the filter is removed. For large decimation factors (e.g., df»20), it is better to perform several nested decimations with lower factors.
Example
Matlab & Octave
Assuming you have a function called 'load_next_block' which reads in the next piece of a contiguous input data stream, decimate as follows: z = 4 ; % set the decimation factor Y = [] ; x = load_next_block ; while ~isempty(x), [y,z]=decz(x,z); Y(end+(1:size(y,1)),1:size(y,2)) = y ; x = load_next_block ; end y=decz([],z); Y(end+(1:size(y,1)),1:size(y,2)) = y ;
R
#Decimate beaked whale acceleration data from testset1 by a factor of 10 in 3 chunks bw <- load_nc('data/testset1.nc') a_rows <- nrow(bw$A$data) a_ind <- data.frame(start=c(1, floor(a_rows/3), floor(2*a_rows/3))) a_ind$end <- c(a_ind$start[2:3] - 1, a_rows) df <- 10 Z <- NULL y <- NULL for (k in 1:nrow(a_ind)){ decz_out <- decz(x=bw$A$data[c(a_ind[k,1]:a_ind[k,2]), ], df=df, Z=Z) df <- NULL Z <- decz_out$Z y <- rbind(y,decz_out$y) }
References
About
bugs@animaltags.org Last modified: 10 May 2017