Motorola DSP Developer's Kit | ![]() ![]() |
Y = mot###_decimate( X, r, nfilt )
Description
Function decimate
resamples data at a lower rate after lowpass IIR filtering. Input vector X is a real vector
Input/Output
Input parameters: Real vector X, int r
, int nfilt
Output parameters: Real vector Y
Algorithm
The MEX function decimate_iir.m
calculates vector b
, vector a
, vector zi
, int
nout
, and int nbeg
. The CMEX function loads these parameters into dsp
memory for asm
function use.
nd = length(idata); m = size(idata,1); nout = ceil(nd/r); rip = 0.05; [b,a] = cheby1(nfilt, rip, 0.8/r); while (abs(filtmag_db(b, a, 0.8/r)+rip)>1e-6) nfilt = nfilt - 1; if nfilt == 0 break end [b,a] = cheby1(nfilt, rip, 0.8/r); end if nfilt == 0 error('Bad Chebyshev design, likely R is too big; try mult. decimation (R=R1*R2).') end len = m; b = b(:).'; a = a(:).'; nb = length(b); na = length(a); n_filt = max(nb,na); nfact = 3*(n_filt-1); % length of edge transient if nb < n_filt, b(n_filt)=0; end % zero-pad if necessary if na < n_filt, a(n_filt)=0; end rows = [1:n_filt-1 2:n_filt-1 1:n_filt-2]; cols = [ones(1,n_filt-1) 2:n_filt-1 2:n_filt-1]; data = [1+a(2) a(3:n_filt) ones(1,n_filt-2) -ones(1,n_filt-2)]; sp = sparse(rows,cols,data); zi = sp \ ( b(2:n_filt).' - a(2:n_filt).'*b(1) ); nbeg = r-(r*nout-nd); Assembly function decimate-iir-r.asm then follow these steps to calculate decimated vector Y: y=[2*x(1)-x((nfact+1):-1:2);x;2*x(len)-x((len-1):-1:len-nfact)] y = filter(b,a,y,[zi*y(1)]) y = y(length(y):-1:1) y = filter(b,a,y,[zi*y(1)]) y = y(length(y):-1:1) y([1:nfact len+nfact+(1:nfact)]) = [] nbeg = r - (r*nout - nd) odata = odata(nbeg:r:nd)
Memory & Register
r
is loaded in register N3nfilt
is loaded in register N5a
b
zi/zf
idata
list
list
nbeg
odata (C)
odata (D)
Length of idata
is n
Length of odata
(C,D) is +2*nfact
Length of tb
is nfilt+1
Length of zi, zf
is nfilt+1
idata (n)
r
nfilt
b
(nfilt+1
)Status Register
The assembly function decimate-iir-r.asm
does not set explicitly any status registers/bits during the function execution.
Data Size Limit
The input vector X length must longer than r*(nfilt+1).
The length of vector X can't be larger than the continuous available data memory size.
Data Range Limit
The value range of the input vector X is [-1.0, +1.0].
Precision
In the case of DSP563, precision is 21 bits.
In the case of DSP566, precision is 12 bits.
![]() | decimate-fir-c.asm | decimate-iir-c.asm | ![]() |