Gast
#1347318
Hallo,
ich bin gerade dabei ein CIC Filter zur SampleRate Reduzierung zu
entwerfen (dsPic). Jedoch bin ich mir nicht ganz sicher, ob ich es
richtig umgesetzt habe. Vielleicht hat noch jemand Anregungen für
Verbesserungen.
Es müssen NumbOutputSample * DecimationFactor Inputsamples im
Eingangsarray vorhanden sein.
Ich bin mir deswegen unsicher, da bei konstanten Eingangssamples eine
Verstärkung >1 auftritt.
Stefan
typedef struct
{
uint16 R; // decimation factor
uint16 N; // number of stages
uint16 M; // comb delay, select 1 or 2 (not used now)
int32 *intDelay; // ptr to delay array
int32 *combDelay; // ptr to comb delay array
} CICStruct;
// protoype declaration
void CIC ( // CIC filtering
uint16 numSamps, // number of input samples (N)
// N = R*p (p integer)
int16 *dstSamps, // ptr to output samples
// (y[n], 0 <= n < N)
int16 *srcSamps, // ptr to input samples
// (x[n], 0 <= n < N*R)
CICStruct *filter // filter structure:
);
void CIC (uint16 numSamps, int16 *dstSamps, int16 *srcSamps, CICStruct
*filter)
{
uint16 i;
uint16 i_cic;
uint16 samples = 0;
int32 tempX; // holds value between CIC stages
int32 combY;
for(i = 0; i < numSamps; i++)
{
// save new input sample into variable
tempX = (int32)*srcSamps;
// process for all N CIC stages
for(i_cic = 0; i_cic < filter->N; i_cic++)
{
// y[n] = x[n] + y[n-1]
tempX = tempX + *(filter->intDelay + i_cic);
// make y[n] to y[n-1] for next loop
*(filter->intDelay + i_cic) = tempX;
}//for stages
// select next input sample
srcSamps++;
samples++;
// decimation and COMB filter
if (samples == filter->R)
{
samples = 0;
// process for all CIC stages
for(i_cic = 0; i_cic < filter->N; i_cic++)
{
// backup x[n]
combY = tempX;
// y[n] = x[n] - x[n-1]
tempX = tempX - *(filter->combDelay + i_cic);
// make: x[n] to x[n-1] for next sample
*(filter->combDelay + i_cic) = combY;
}//for stages
// save to output and select next output destination
*dstSamps = (int16)tempX;
dstSamps++;
}//if COMB
}//for numSamps
}//CIC