| 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 complex vector
Input/Output
Input parameters: Complex vector X, int r, int nfilt
Output parameters: Complex 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, and 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 (In the a area, the first half stores the real part, and the second half stores the imaginary part)
b (In the b area, the first half stores the real part, and the second half stores the imaginary part)
zi/zf (In the zi/zf area, the first half stores the real part, and the second half stores the imaginary part)
idata idatarnfilta, b, zi, zfnfactitemp, n+2*nfactnoutnbegodata (C)odata (D)Length of idata is n
Length of odata (C,D) = (the length of idata)+2*nfact
Length of tb is nfilt+1
Length of zi, zf is nfilt+1
idata (n)rnfilt b (nfilt+1)Status Register
The assembly function decimate-iir-c.asm does not explicitly set any status registers/bits during the function execution.
Data Size Limit
Input vector X length must be 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 of input vector X must be between -1.0 and +1.0.
Precision
In the case of DSP563, precision is 21 bits.
In the case of DSP566, precision is 12 bits.
| decimate-iir-r.asm | diff-r.asm | ![]() |