Ctcss Htm

CTCSS-tietoa
logo.jpg

CTCSS (Continuous Tone Coded Squelch System). käytetään mm. radioamatöörien toistimissa. Toistin avataan vain jos lähetteessä on oikea aliääni. Aliääni ei kuulu normaalilla signaalitiellä, joka radiossa ja puhelimissa on 300Hz- 3.2 kHz.
CTCSS järjestelmä on EIA:n määrittelemä. Motorola (Private Line=PL) ja GE (Channel Guard=CG) ovat käyttäneet omia kauppanimiään CTCSS-järjestelmästä. Helsingin radioamatööritoistin OH2RAA 145.750MHz vaatii aliäänen 118.8Hz. Samaa aliääntä käytetään Helsingin seudun muillakin toistinasemilla, Tampereelle on ehdotettu 103.5Hz aliääntä. Sitä ei ole vielä otettu käyttöön, koska silloin Tampereella ei ole yhtään asemaa joka toimii vanhoilla radioilla, joissa ei ole aliääntä.

CTCSS-järjestelmässä on 50 ääntä taajuuksilla 67…254,1 Hz:. Lisää CTCSS- tietoa

[http://en.wikipedia.org/wiki/CTCSS]

67.0 Hz 94.8 Hz 131.8 Hz 171.3 Hz 203.5 Hz
69.3 Hz 97.4 Hz 136.5 Hz 173.8 Hz 206.5 Hzj
71.9 Hz 100.0 Hz 141.3 Hz 177.3 Hz 210.7 Hz
74.4 Hz 103.5 Hz 146.2 Hz 179.9 Hz 218.1 Hz
77.0 Hz 107.2 Hz 151.4 Hz 183.5 Hz 225.7 Hz
79.7 Hz 110.9 Hz 156.7 Hz 186.2 Hz 229.1 Hz
82.5 Hz 114.8 Hz 159.8 Hz 189.9 Hz 233.6 Hz
85.4 Hz 118.8 Hz 162.2 Hz 192.8 Hz 241.8 Hz
88.5 Hz 123.0 Hz 165.5 Hz 196.6 Hz 250.3 Hz
91.5 Hz 127.3 Hz 167.9 Hz 199.5 Hz 254.1 Hz

Suomen Robottiyhdistys

------ 
67Hz FIR  koodit dsPIC:lle    64 tappia 
/***************************************************************************
****************************************************************************
*   File: D:\grafiikka\2007\robo\kimikangasala\pieni\firkoodi67.c
*   Created for  dsPIC   18:31:10 Nov 03 2007
*   Suomen Robottiyhdistys 2007  by OH3GDO  
 * 67Hz FIR suidin 64 tappia Kaiser menetemällä    
 * DSPIC koodi 
*  extern FIR_filter FIR_firkoodi67;
*  init_fir_float (&FIR_firkoodi67);  // initialize filter structure 
*
*  FIR_firkoodi67.filter ( x, y, n, &FIR_firkoodi67);  // x on tuloADC  array  
*                                            // y anto array   
*                                            // n on monta näytettää käsitellään 
*                                            // &FIR_firkoodi67 osoitin funktioon 
*                                            //    
*****************************************************************************
 
*****************************************************************************
****************************************************************************/
 
/* qed_cgen.h vakiot  */
 
/* filtteri koodit  'qed_filt.c'  */
 
float firkoodi67_coeff[64] = {
   3.051757812500e-005F,  /* filter tap #    0 */
  -3.967285156250e-004F,  /* filter tap #    1 */
  -9.765625000000e-004F,  /* filter tap #    2 */
   1.403808593750e-003F,  /* filter tap #    3 */
   3.143310546875e-003F,  /* filter tap #    4 */
  -2.014160156250e-003F,  /* filter tap #    5 */
  -6.225585937500e-003F,  /* filter tap #    6 */
   1.678466796875e-003F,  /* filter tap #    7 */
   9.490966796875e-003F,  /* filter tap #    8 */
   0.000000000000e+000F,  /* filter tap #    9 */
  -1.138305664063e-002F,  /* filter tap #   10 */
  -2.380371093750e-003F,  /* filter tap #   11 */
   1.052856445313e-002F,  /* filter tap #   12 */
   3.906250000000e-003F,  /* filter tap #   13 */
  -6.072998046875e-003F,  /* filter tap #   14 */
  -1.953125000000e-003F,  /* filter tap #   15 */
  -1.129150390625e-003F,  /* filter tap #   16 */
  -5.706787109375e-003F,  /* filter tap #   17 */
   8.911132812500e-003F,  /* filter tap #   18 */
   2.053833007813e-002F,  /* filter tap #   19 */
  -1.348876953125e-002F,  /* filter tap #   20 */
  -4.147338867188e-002F,  /* filter tap #   21 */
   1.135253906250e-002F,  /* filter tap #   22 */
   6.539916992188e-002F,  /* filter tap #   23 */
   0.000000000000e+000F,  /* filter tap #   24 */
  -8.709716796875e-002F,  /* filter tap #   25 */
  -2.026367187500e-002F,  /* filter tap #   26 */
   1.013183593750e-001F,  /* filter tap #   27 */
   4.641723632813e-002F,  /* filter tap #   28 */
  -1.038818359375e-001F,  /* filter tap #   29 */
  -7.287597656250e-002F,  /* filter tap #   30 */
   9.371948242188e-002F,  /* filter tap #   31 */
   9.371948242188e-002F,  /* filter tap #   32 */
  -7.287597656250e-002F,  /* filter tap #   33 */
  -1.038818359375e-001F,  /* filter tap #   34 */
   4.641723632813e-002F,  /* filter tap #   35 */
   1.013183593750e-001F,  /* filter tap #   36 */
  -2.026367187500e-002F,  /* filter tap #   37 */
  -8.709716796875e-002F,  /* filter tap #   38 */
   0.000000000000e+000F,  /* filter tap #   39 */
   6.539916992188e-002F,  /* filter tap #   40 */
   1.135253906250e-002F,  /* filter tap #   41 */
  -4.147338867188e-002F,  /* filter tap #   42 */
  -1.348876953125e-002F,  /* filter tap #   43 */
   2.053833007813e-002F,  /* filter tap #   44 */
   8.911132812500e-003F,  /* filter tap #   45 */
  -5.706787109375e-003F,  /* filter tap #   46 */
  -1.129150390625e-003F,  /* filter tap #   47 */
  -1.953125000000e-003F,  /* filter tap #   48 */
  -6.072998046875e-003F,  /* filter tap #   49 */
   3.906250000000e-003F,  /* filter tap #   50 */
   1.052856445313e-002F,  /* filter tap #   51 */
  -2.380371093750e-003F,  /* filter tap #   52 */
  -1.138305664063e-002F,  /* filter tap #   53 */
   0.000000000000e+000F,  /* filter tap #   54 */
   9.490966796875e-003F,  /* filter tap #   55 */
   1.678466796875e-003F,  /* filter tap #   56 */
  -6.225585937500e-003F,  /* filter tap #   57 */
  -2.014160156250e-003F,  /* filter tap #   58 */
   3.143310546875e-003F,  /* filter tap #   59 */
   1.403808593750e-003F,  /* filter tap #   60 */
  -9.765625000000e-004F,  /* filter tap #   61 */
  -3.967285156250e-004F,  /* filter tap #   62 */
   3.051757812500e-005F}; /* filter tap #   63 */
 
float firkoodi67_smpl[64];  /* naytteet */ 
 
float firkoodi67_gain = 1.000000000000e+000F; /* gain kerroin   FIR  varten */
 
FIR_filter FIR_firkoodi67 = {
 
     0,     /* quantization: 0 off, 1 on   */
     1,     /* quantization type */
            /*   0  Floating point         */
            /*   1  Fixed point fractional */
     0,     /* quantization type */
            /*   0 - No scaling of filter */
            /*   1 - Center tap scaled to be > 0.5 and < 1.0  */
            /*   2 - Center tap scaled to be 1.0 - gain factor
                     (essentially largest positive value) */
   0,           /* shift count - fixed point fractional */ 
   64,           /* filter length */ 
   0,            /* initial delay line index */
   &firkoodi67_gain,  /* ptr to gain value          */
   firkoodi67_coeff,  /* ptr to filter coefficients */
   firkoodi67_smpl,   /* ptr to delay line */
   fir_float_reg}; /* ptr to filter routine */
 
/* aluatusfunkti  */
/* init_fir_float (&FIR_firkoodi67)  */
/*     &FIR_firkoodi67 on  pointteri  -> FIR_filter */
 
/* FIR suodin    n näyettä  */
/* FIR_firkoodi67.filter (pIn, pOut, int n, &FIR_firkoodi67); */
 
/*    pIn  on pointteri arrayn, jossa suodatettava data    */
/*         pOut on  pointteri arrayn, jossa anto data */
/*         n   monta naytettä mitattavana  */
/*         &FIR_firkoodi67 osoite struktuuriin ,missä on firkertoimet  */
 
/*   testaa suodinta  mainilla        */
/*    'in' tulodata tiedosto  ja  'out'antodata pointteri */
/*    data  ascii lliukuvan pilkun lukuja        */
/*     1.0342   1  näyte rivillä                                */
/*              */
 
#include "qed_filt.c"  // valilaskeketna file dsPIC:lle 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
 
#define INSZ1  1000
#define OUTSZ1 1000
 
static    float x[INSZ1], y[OUTSZ1];
 
int main(int argc, char *argv[])
 
{
  int i, in_count, file_status, error;
 
  FILE *fin;              /* tulo */
  FILE *fout;             /* anto */ 
 
  fprintf (stderr," ***** FIR testi  SRY 2007 ****\n");
 
  fprintf (stderr,"    0,1 tai 2 komnetoriviparametria \n");
  fprintf (stderr," 0 tulofile   \n");
  fprintf (stderr," 1 antofile \n");
 
  fin  = stdin;
  fout = stdout;
  error = 0;
 
  if (argc == 1) {
        fprintf(stderr," ***** anna input file parametri *****\n");
  }
  if (argc >= 2) {
      fin = fopen (argv[1], "r");
      if (fin == NULL) {
          fprintf(stderr,"\n virhe tiesdodto  %s  ->  input\n", argv[1]);
          error = 1;
      }
  }
  if (argc >= 3) {
      fout = fopen (argv[2], "w");
      if (fout == NULL) {
          fprintf(stderr,"\n virhe tiedosdto  %s  -> output\n", argv[2]);
          error = 1;
      }
  }
  if (error) {
      fprintf(stderr," ***** Loetus virhe  *****\n");
      return(0);
  }
 
  init_fir_float (&FIR_firkoodi67);  // laske FIR 
 
  do {
 
      /*luetaan tulotiedot  */ 
      for (in_count = 0; in_count < INSZ1; in_count++) { 
          file_status = fscanf(fin,"%f",&x[in_count]); 
          if (file_status != 1) 
              break; 
      }
 
      /* monta näytettä luettu */ 
 
      if (in_count == 0) break;
 
      FIR_firkoodi67.filter( x, y, in_count, &FIR_firkoodi67);
 
      for (i = 0; i < in_count; i++)
          fprintf (fout,"%f\n",y[i]);
 
  } while (file_status == 1);
 
  fclose (fin); 
  fclose (fout);
 
  fprintf(stderr," ***** loppu  *****\n");
  return(1);
 
}
 
------
/**************************************************************
***************************************************************
*  fir.h         
* 2007 
*
***************************************************************
**************************************************************/
 
typedef struct{
    int fract;
    int shift;
} FractGain;
 
typedef struct {
    int nosect;        /* number of sections */
 
    int rMthd;        /* realization method */
                    /*   0  Cascaded second order sections */
                    /*   1  Parallel second order sections */
    int quant;        /* quantization switch */
                    /*   0  quantization off - double precision */
                    /*   1  quantization on */
 
    int quantType;    /* 0 Floating point         */
                    /* 1 Fixed point fractional    */
    int realType1;    /* applies to cascaded sections only
                    /* 0 Transposed Canonic Second Order Sections */
                    /* 1 Canonic Second Order Sections */
                    /* 2 Floating Point - 4 Multiplies */
                    /* 3 Floating Point - 5 Multiplies */
                    /* Valid Combinations  */
                    /* quantType realType   Description */
                    /*    0         0          fixed point    */
                    /*      0         1        fixed point    */
                    /*    1          0       block floating point */
                    /*    1         1        block floating point */
                    /*    1         2        floating point */
                    /*    1         3        floating point */
    int realType2;  /* applies to parallel sections only */
                    /* 0 Transposed Canonic Second Order Sections */
                    /* 1 Transposed Floating Sections */
    void  *gain;    /* pointer to initial gain - cascaded and parallel sections */
    void  *pars;    /* pointer to scaler for parallel form */
 
    void  *num;        /* pointer to array of numerator values   */
    void  *den;        /* pointer to array of denominator values */
    void  *m1;        /* pointer to intermediate storage        */
    void  *m2;        /* pointer to intermediate storage        */
 
    void (*filter) ();
/* void (*filter) (float *pInValues, float *pOutValues, int n, BiquadSections *F); */
                    /* address of filter routine */
} BiquadSections;    /* second order section structure name */
 
typedef struct {
    int quant;        /* quantization switch         */
                    /*   0  quantization off - double precision */
                    /*   1  quantization on        */
    int quantType;    /* 0 Floating point            */
                    /* 1 Fixed point fractional       */
    int realType4;  /* applies to FIR filters only */
                    /*   0 - No scaling of filter  */
                    /*   1 - Center tap scaled to be > 0.5 and < 1.0  
                             intended for right shift to restore 0dB gain 
                              shifts used in fixed point fractional 
                              implementational only                   
                             for floating point multiply by gain      */
                    /*   2 - Center tap scaled to be 1.0 - gain factor 
                               (essentially largest positive value)  
                         requires post multiplication of gain value   */
    int shift_cnt;  /* for fixed point fractional implementation only */
    int length;        /* filter length (filter order + 1)     */
    int delay;        /* delay index to delayed samples array */
    void  *gain;    /* initial gain value                   */
                    /*   applies to realType of 1 or 2      */
    void  *coef;    /* pointer to array of coefficients     */
    void  *smpl;    /* pointer to array of delayed samples  */
    void (*filter) ();
/* void (*filter) (float *pInValues, float *pOutValues, int n, FIR_filter *F); */
                    /* address of filter routine */
} FIR_filter;        /* fir filter structure name */
 
typedef struct {
    int length;        /* filter length (filter order + 1)     */
    void  *num;        /* pointer to numerator array    */
    void  *den;        /* pointer to denominator array */
    void  *buf;        /* buffer for intermediate data */
    void (*filter) ();
/* void (*filter) (float *pInValues, float *pOutValues, int n, RT2_filter *F); */
                    /* address of filter routine */
} RT2_filter;        /* ratio of two polynomials filter structure name */
 
typedef struct {
    int quant;        /* quantization switch  */
                    /*   0  quantization off - double precision */
                    /*   1  quantization on */
    int quantType;    /* 0 Floating point         */
                    /* 1 Fixed point fractional    */
    int order;        /* filter length (filter order + 1)    */
    void  *gain;    /* initial gain value */
    void  *kappa;    /* pointer to array of lattice coefficients (poles)*/
    void  *gamma;    /* pointer to array of ladder coefficients  (zeros)*/
    void  *f;        /* pointer to array of forward values  */
    void  *b;        /* pointer to array of backward values */
    void (*filter) ();
/* void (*filter) (float *pInValues, float *pOutValues, int n, FIR_filter *F); */
                    /* address of filter routine */
} LAT_filter;        /* fir filter structure name */
 
void init_biquad_float (BiquadSections *F);
void init_fir_float       (FIR_filter     *F);
void init_rt2_float    (RT2_filter     *F);
void init_lat_float    (LAT_filter     *F);
 
void cas_float_4mul         
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void cas_float_5mul
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void cas_blkfloat_fm1 
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void cas_blkfloat_fm2 
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void par_float_fm1 
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void par_blkfloat_fm1
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void fir_float_reg
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       FIR_filter *Filt);     /* pointer to filter structure  */
void rt2_float
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       RT2_filter *Filt);     /* pointer to filter structure  */
void lat_float
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       LAT_filter *Filt);     /* pointer to filter structure  */
 
void init_biquad_dbl  (BiquadSections *F);
void init_fir_dbl      (FIR_filter     *F);
void init_rt2_dbl     (RT2_filter     *F);
void init_lat_dbl     (LAT_filter     *F);
 
void cas_dbl_fm2 
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void par_dbl_fm1
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt); /* pointer to filter structure  */
void fir_dbl_reg
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       FIR_filter *Filt);     /* pointer to filter structure  */
void rt2_dbl
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       RT2_filter *Filt);     /* pointer to filter structure  */
void lat_dbl
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       LAT_filter *Filt);     /* pointer to filter structure  */
  /* _fir_H_ */
 
------
 /**************************************************************
***************************************************************
*  File firt.c         
*   2007 
*     FIR filter
*     Ratio of two polynomials
*
***************************************************************
**************************************************************/
 
#include "fir.h"
 
/**************************************************************
*  initialize biquad sections
*  clears delay lines to zero
*  must be called prior to calling filter routine
**************************************************************/
 
void init_biquad_float(BiquadSections *Filt) {
 
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
int i;
 
m1 = Filt->m1;
m2 = Filt->m2;
 
for (i = 0; i < Filt->nosect; i++) {
    m1[i] = (float) 0.0;
    m2[i] = (float) 0.0;
    }
}
 
/*  filter routine for 4 multiplier
 
*/
 
void cas_float_4mul
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
float *pGain; /* pointer to gain value of filter */
float gain;   /* gain value of filter            */
int nosect;   /* number of sections in the filter */
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
float *num;      /* pointer to numerator coefficients   */
float *den;      /* pointer to denominator coefficients */
float x;      /* gain * input sample */
float temp;   /* scratch variable */
float s;      /* scratch variable */
int i;        /* input sample counter */
int j;        /* section counter */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
 
pGain  = Filt->gain;
gain   = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x = pInValues[i] * gain;
    for (j = 0; j < nosect; j++) {
        temp = x - den[0] * m1[j] - den[1] * m2[j];
        s = temp + num[0] * m1[j] + num[1] * m2[j];
        m2[j] = m1[j];
        m1[j] = temp;
        x = s;
        num += 2;
        den += 2;
    }
    pOutValues[i] = s;
}
return;
}
 
/*  filter routine for 5 multiplier
 
*/
 
void cas_float_5mul
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
float *pGain; /* pointer to gain value of filter */
float  gain;  /* gain value of filter */
int nosect;   /* number of sections in the filter */
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
float *num;      /* pointer to numerator coefficients   */
float *den;      /* pointer to denominator coefficients */
float x;      /* gain * input sample */
float temp;   /* scratch variable */
float s;      /* scratch variable */
int i;        /* input sample counter */
int j;        /* section counter */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
pGain = Filt->gain;
gain  = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x = pInValues[i] * gain;
    for (j = 0; j < nosect; j++) {
        temp = x - den[0] * m1[j] - den[1] * m2[j];
        s = temp * num[0] + num[1] * m1[j] + num[2] * m2[j];
        m2[j] = m1[j];
        m1[j] = temp;
          x = s;
        num += 3;
        den += 2;
    }
    pOutValues[i] = s;
}
return;
}
 
/*  filter routine for 5 multiplier block floating point
     cascaded sections
 
void cas_blkfloat_fm1
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
float *pGain; /* pointer to gain value of filter */
float gain;      /* gain value of filter */
int nosect;   /* number of sections in the filter */
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
float *num;      /* pointer to numerator coefficients   */
float *den;      /* pointer to denominator coefficients */
float x;      /* gain * input sample */
float s;      /* scratch variable */
int i;        /* input sample counter */
int j;        /* section counter */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
pGain = Filt->gain;
gain  = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x = pInValues[i] * gain;
    for (j = 0; j < nosect; j++) {
             s     = (num[0] * x + m1[j]) / den[0];
          m1[j] =  num[1] * x - den[1] * s + m2[j];
          m2[j] =  num[2] * x - den[2] * s;
          x = s;
          num += 3;
          den += 3;
 
    }
    pOutValues[i] = s;
}
return;
}
 
/*  filter routine for 5 multiplier block floating point
     cascaded sections
 
*/
 
void cas_blkfloat_fm2
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
float *pGain; /* pointer to gain value of filter */
float gain;      /* gain value of filter */
int nosect;   /* number of sections in the filter */
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
float *num;      /* pointer to numerator coefficients   */
float *den;      /* pointer to denominator coefficients */
float x;      /* gain * input sample */
float temp;   /* scratch variable */
float s;      /* scratch variable */
int i;        /* input sample counter */
int j;        /* section counter */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
pGain = Filt->gain;
gain  = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x = pInValues[i] * gain;
    for (j = 0; j < nosect; j++) {
           temp = (den[0] * x    - den[1] * m1[j] - den[2] * m2[j]) / den[0];
        s    = (num[0] * temp + num[1] * m1[j] + num[2] * m2[j]) / den[0];
        m2[j] = m1[j];
        m1[j] = temp;
          x = s;
        num += 3;
        den += 3;
    }
    pOutValues[i] = s;
}
return;
}
 
/*  filter routine for 5 multiplier
    floating point sum of  sections
 
*/
 
void par_float_fm1
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
float *pGain; /* pointer to gain value of filter  */
float gain;   /* gain value for sum of sections   */
float *pPars; /* pointer to scale value for parallel sections */
float pars;      /* scale value of filter                        */
int nosect;   /* number of sections in the filter */
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
float *num;      /* pointer to numerator coefficients   */
float *den;      /* pointer to denominator coefficients */
float x;      /* input sample */
float sum;    /* scratch variable initialized to gain * sum */
float s;      /* scratch variable     */
int i;        /* input sample counter */
int j;        /* section counter      */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
pPars  = Filt->pars;
pars   = *pPars;
pGain  = Filt->gain;
gain   = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x   = pInValues[i];
    sum = gain * x;
    for (j = 0; j < nosect; j++) {
           s     =  num[0] * x + m1[j] ;
        m1[j] =  num[1] * x - den[0] * s + m2[j];
        m2[j] =  num[2] * x - den[1] * s;
        sum += s;
        num += 3;
        den += 2;
 
    }
    pOutValues[i] = sum * pars;
}
return;
}
 
/*  filter routine for 5 multiplier
    block floating point sum of  sections
 
    This uses form I i.e.
 
    Note: minus signs are used for the feedback loops
 
    If code is used for coefficients from an flt file,
      these signs must be changed to positive. All feedback
      coefficients in flt files have complemented signs.
*/
 
void par_blkfloat_fm1
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
float *pGain; /* pointer to gain value of filter */
float gain;   /* gain value for sum of sections  */
float *pPars; /* pointer to scale value for parallel sections */
float pars;      /* scale value of filter            */
int nosect;   /* number of sections in the filter */
float *m1;      /* pointer to delay line1 */
float *m2;      /* pointer to delay line2 */
float *num;      /* pointer to numerator coefficients   */
float *den;      /* pointer to denominator coefficients */
float x;      /* input sample */
float sum;    /* scratch variable initialized to gain * sum */
float s;      /* scratch variable     */
int i;        /* input sample counter */
int j;        /* section counter      */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
pPars = Filt->pars;
pars  = *pPars;
pGain = Filt->gain;
gain  = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x   = pInValues[i];
    sum = gain * x;
    for (j = 0; j < nosect; j++) {
           s     = (num[0] * x + m1[j]) / den[0];
        m1[j] =  num[1] * x - den[1] * s + m2[j];
        m2[j] =  num[2] * x - den[2] * s;
        sum += s;
        num += 3;
        den += 3;
 
    }
    pOutValues[i] = sum * pars;
}
return;
}
 
void fir_float_reg
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       FIR_filter *Filt)      /* pointer to filter structure  */
{
    int i;            /* counter of number of samples     */
    int j;            /* counter on filter values         */
    int length;        /* filter length                    */
    int delay;        /* index into delay line            */
    int rtype4;     /* realization type                 */
    float temp;        /* filter summation variable        */
    float *pGain;   /* pointer to gain value            */
    float gain;     /* gain value                       */
    float *smpl;    /* pointer to delay line of samples */
    float *coef;    /* pointer to filter coefficients   */
 
/**********************************************************************
*   Let x(n) = at time n and y(n) = output at time n
*   then y(n) = sum of h(j)*x(n-j) for j= 1...length
*
*   x(n) corresponds to pInValues[i]
*   y(n) corresponds to pOutValues[i]
*
*   In this program, h(j) is coef(j)
*     and x(n-j) is the array smpl x(n-j) is implemented using
*     the delay index and decrementing backward until delay = - 1
*     when delay = -1, it is reset to length - 1 for the next
*     iteration.
*     In effect the use of the variable delay and pointer smpl
*     is a circular buffer for the input samples
*
*   On each sample, the sample is stored in the smpl delay line
*      using the subscript value in Filt->delay. This value is then
*     incremented for the next sample. If the end of the array is
*     reached after incrementing, Filt->delay is set to zero. This
*     forces the next sample to be stored at the first entry of smpl
*************************************************************************/
 
    length = Filt->length;
    pGain  = Filt->gain;
    gain   = *pGain;
    rtype4 = Filt->realType4;
    smpl   = Filt->smpl;
    coef   = Filt->coef;
 
    for (i = 0; i < nValues; i++)  {
        delay = Filt->delay++;         /* get delay index and increment index value */
                                     /*   in filter structure                     */
        if (Filt->delay == length)   /* check for buffer address reset            */
            Filt->delay = 0;         /* reset buffer address in filter structure  */
        smpl[delay] = pInValues[i];  /* put sample into delay line of samples     */
        temp  = (float) 0.0;
        for (j = 0; j < length; j++) {
                temp += coef[j] * smpl[delay--]; /* form sum of products          */
                if (delay < 0)          /* check for buffer address reset           */
                    delay += length;  /* reset buffer address to get rest         */
                                      /*   of delayed samples                     */
            }
        pOutValues[i] = temp * gain;
    }
    return;
}
 
void init_fir_float (FIR_filter *Filt) {
    int i; float *smpl;
    Filt->delay = 0;                   /* set delay index to zero */
    smpl = Filt->smpl;
    for (i = 0; i < Filt->length; i++) /* zero out the delay line */
        smpl[i] = (float) 0.0;
}
 
void rt2_float
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       RT2_filter *Filt)      /* pointer to filter structure  */
{
    int i, j;
    int order;
    float x, y, *num, *den, *buf;
 
    buf   = Filt->buf;
    order = Filt->length - 1;
 
    for (i = 0; i < nValues; i++)  {
 
        num   = Filt->num;
        den   = Filt->den;
 
        x = pInValues[i];     /* get current sample           */
        y = (x * (*num++) + buf[0]) * (*den++);
 
        for (j = 0; j < order; j++)
            buf[j] = buf[j+1] + x * (*num++) - y * (*den++);
        buf[order] = x * (*num++) - y * (*den++);
        pOutValues[i] = y;
    }
}
 
void init_rt2_float (RT2_filter *F) {
    int i;
    float *buf; buf = F->buf;
    for (i = 0; i < F->length; i++)
        buf[i] = (float) 0.0;
}
 
/********************************************************************
*  double precision rourines
********************************************************************/
 
/********************************************************************
*  initialize biquad sections
*  clears delay lines to zero
*  must be called prior to calling filter routine
********************************************************************/
 
void init_biquad_dbl(BiquadSections *Filt) {
 
double *m1;      /* pointer to delay line1 */
double *m2;      /* pointer to delay line2 */
int i;
 
m1 = Filt->m1;
m2 = Filt->m2;
 
for (i = 0; i < Filt->nosect; i++) {
    m1[i] = (double) 0.0;
    m2[i] = (double) 0.0;
    }
}
 
/********************************************************************
*   filter routine for 4 multiplier
*   floating point cascaded sections
*
*   This uses form II i.e.
*   the incoming sample is added to the feedback loops
*    Note: minus signs are used for the feedback loops
*
*    If code is used for coefficients from an flt file,
*      these signs must be changed to positive. All feedback
*      coefficients in flt files have complemented signs.
********************************************************************/
 
void cas_dbl_fm2
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
double *pGain; /* pointer to gain value of filter */
double gain;   /* gain value of filter            */
int nosect;    /* number of sections in the filter */
double *m1;       /* pointer to delay line1 */
double *m2;       /* pointer to delay line2 */
double *num;   /* pointer to numerator coefficients   */
double *den;   /* pointer to denominator coefficients */
double x;       /* gain * input sample */
double temp;   /* scratch variable */
double s;      /* scratch variable */
int i;         /* input sample counter */
int j;         /* section counter */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
 
pGain  = Filt->gain;
gain   = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x = pInValues[i] * gain;
    for (j = 0; j < nosect; j++) {
        temp = x - den[0] * m1[j] - den[1] * m2[j];
        s = temp + num[0] * m1[j] + num[1] * m2[j];
        m2[j] = m1[j];
        m1[j] = temp;
        x = s;
        num += 2;
        den += 2;
    }
    pOutValues[i] = s;
}
return;
}
 
/********************************************************************
*   filter routine for 5 multiplier
*    floating point sum of  sections
*
*   This uses form I
*
*    Note: minus signs are used for the feedback loops
*
*    If code is used for coefficients from an flt file,
*      these signs must be changed to positive. All feedback
*      coefficients in flt files have complemented signs.
********************************************************************/
 
void par_dbl_fm1
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       BiquadSections *Filt)  /* pointer to filter structure  */
{
 
double *pGain; /* pointer to gain value of filter  */
double gain;   /* gain value for sum of sections   */
double *pPars; /* pointer to scale value for parallel sections */
double pars;   /* scale value of filter                        */
int nosect;    /* number of sections in the filter */
double *m1;       /* pointer to delay line1 */
double *m2;       /* pointer to delay line2 */
double *num;   /* pointer to numerator coefficients   */
double *den;   /* pointer to denominator coefficients */
double x;       /* input sample */
double sum;    /* scratch variable initialized to gain * sum */
double s;      /* scratch variable     */
int i;         /* input sample counter */
int j;         /* section counter      */
 
/* runtime initialization for filter routine */
 
m1 = Filt->m1;
m2 = Filt->m2;
pPars  = Filt->pars;
pars   = *pPars;
pGain  = Filt->gain;
gain   = *pGain;
nosect = Filt->nosect;
 
for (i = 0; i < nValues; i++)  {
    num = Filt->num;
    den = Filt->den;
    x   = pInValues[i];
    sum = gain * x;
    for (j = 0; j < nosect; j++) {
           s     =  num[0] * x + m1[j] ;
        m1[j] =  num[1] * x - den[0] * s + m2[j];
        m2[j] =  num[2] * x - den[1] * s;
        sum += s;
        num += 3;
        den += 2;
 
    }
    pOutValues[i] = sum * pars;
}
return;
}
 
void fir_dbl_reg
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       FIR_filter *Filt)      /* pointer to filter structure  */
{
    int i;            /* counter of number of samples */
    int j;            /* counter on filter length */
    int length;        /* filter length */
    int delay;        /* index into delay line */
    double temp;    /* filter summation variable */
    double *smpl;    /* pointer to delay line of samples */
    double *coef;    /* pointer to filter coefficients */
/**********************************************************************
*   Let x(n) = at time n and y(n) = output at time n
*   then y(n) = sum of h(j)*x(n-j) for j= 1...length
*
*   x(n) corresponds to pInValues[i]
*   y(n) corresponds to pOutValues[i]
*
*   In this program, h(j) is coef(j)
*     and x(n-j) is the array smpl x(n-j) is implemented using
*     the delay index and decrementing backward until delay = - 1
*     when delay = -1, it is reset to length - 1 for the next
*     iteration.
*     In effect the use of the variable delay and pointer smpl
*     is a circular buffer for the input samples
*
*   On each sample, the sample is stored in the smpl delay line
*      using the subscript value in Filt->delay. This value is then
*     incremented for the next sample. If the end of the array is
*     reached after incrementing, Filt->delay is set to zero. This
*     forces the next sample to be stored at the first entry of smpl
*************************************************************************/
 
    length = Filt->length;
    smpl   = Filt->smpl;
    coef   = Filt->coef;
 
    for (i = 0; i < nValues; i++)  {
        delay = Filt->delay++;         /* get delay index and increment index value */
                                     /*   in filter structure                     */
        if (Filt->delay == length)   /* check for buffer address reset            */
            Filt->delay = 0;         /* reset buffer address in filter structure  */
        smpl[delay] = pInValues[i];  /* put sample into delay line of samples     */
        temp  = (double) 0.0;
        for (j = 0; j < length; j++) {
                temp += coef[j] * smpl[delay--]; /* form sum of products          */
                if (delay < 0)          /* check for buffer address reset           */
                    delay += length;  /* reset buffer address to get rest         */
                                      /*   of delayed samples                     */
            }
        pOutValues[i] = temp;
    }
    return;
}
 
void init_fir_dbl (FIR_filter *Filt) {
    int i; double *smpl;
    Filt->delay = 0;                   /* set delay index to zero  */
    smpl = Filt->smpl;
    for (i = 0; i < Filt->length; i++) /* zero out the delay line  */
        smpl[i] = (double) 0.0;
}
 
void rt2_dbl
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       RT2_filter *Filt)      /* pointer to filter structure  */
{
    int i, j;
    int order;
    double x, y, *num, *den, *buf;
 
    buf   = Filt->buf;
    order = Filt->length - 1;
 
    for (i = 0; i < nValues; i++)  {
 
        num   = Filt->num;
        den   = Filt->den;
 
        x = pInValues[i];     /* get current sample  */
        y = (x * (*num++) + buf[0]) * (*den++);
 
        for (j = 0; j < order; j++)
            buf[j] = buf[j+1] + x * (*num++) - y * (*den++);
        buf[order] = x * (*num++) - y * (*den++);
        pOutValues[i] = y;
    }
}
 
void init_rt2_dbl (RT2_filter *F) {
    int i;
    double *buf; buf = F->buf;
    for (i = 0; i < F->length; i++)
        buf[i] = (double) 0.0;
}
 
void init_lat_float (LAT_filter *Filt) {
    int i;
    float *back, *forw;
 
    forw  = Filt->f;
    back  = Filt->b;
 
    for (i = 0; i <= Filt->order; i++)  /* zero out the delay line */
        back[i] = forw[i] = (float) 0.0;
}
 
void init_lat_dbl (LAT_filter *Filt) {
    int i;
    double *back, *forw;
 
    forw  = Filt->f;
    back  = Filt->b;
 
    for (i = 0; i <= Filt->order; i++)  /* zero out the delay line */
        back[i] = forw[i] = (double) 0.0;
}
 
void lat_float
      (float *pInValues,      /* pointer to input buffer      */
       float *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       LAT_filter *Filt)      /* pointer to filter structure  */
{
    int i, j;        /* loop control variables  */
    int order;        /* order of lattice filter */
    int index;        /* order - 1               */
    float x;        /* input variable          */
    float y;        /* output variable         */
    float *kappa;   /* pointer to lattice coeficients */
    float *gamma;    /* pointer to ladder coefficients */
    float *back;    /* pointer to backward lattice function values */
    float *forw;    /* pointer to forward  lattice function values */
    float *gain;    /* pointer to initial gain value  */
    float temp;        /* temporary variable */
 
    kappa  = Filt->kappa;
    gamma  = Filt->gamma;
    gain   = Filt->gain;
    order  = Filt->order;
    forw  = Filt->f;
    back  = Filt->b;
    index = order - 1;
 
    for (i = 0; i < nValues; i++)  {
 
        x = pInValues[i];  /* get current sample  */
        forw[0] = (*gain) * x;
 
        for (j = 0; j < order; j++) {
            temp = kappa [index - j];
            forw [j + 1] = forw[j]     - temp * back[j + 1];
            back[j]      = back[j + 1] + temp * forw[j + 1];
        }
        back[order] = forw[order];
        y = 0.0;
        for (j = 0; j <= order; j++) {
            y += back[j] * gamma[order - j];
        }
 
        pOutValues[i] = y;
    }
}
 
void lat_dbl
      (double *pInValues,     /* pointer to input buffer      */
       double *pOutValues,      /* pointer to output buffer     */
       int nValues,              /* number of samples to process */
       LAT_filter *Filt)      /* pointer to filter structure  */
{
    int i, j;        /* loop control variables  */
    int order;        /* order of lattice filter */
    int index;        /* order - 1               */
    double x;        /* input variable          */
    double y;        /* output variable         */
    double *kappa;  /* pointer to lattice coeficients */
    double *gamma;    /* pointer to ladder coefficients */
    double *back;    /* pointer to backward lattice function values */
    double *forw;    /* pointer to forward  lattice function values */
    double *gain;    /* pointer to initial gain value  */
    double temp;    /* temporary variable */
 
    kappa  = Filt->kappa;
    gamma  = Filt->gamma;
    gain   = Filt->gain;
    order  = Filt->order;
    forw  = Filt->f;
    back  = Filt->b;
    index = order - 1;
 
    for (i = 0; i < nValues; i++)  {
 
        x = pInValues[i];  /* get current sample */
        forw[0] = (*gain) * x;
 
        for (j = 0; j < order; j++) {
            temp = kappa [index - j];
            forw [j + 1] = forw[j]     - temp * back[j + 1];
            back[j]      = back[j + 1] + temp * forw[j + 1];
        }
        back[order] = forw[order];
        y = 0.0;
        for (j = 0; j <= order; j++) {
            y += back[j] * gamma[order - j];
        }
 
        pOutValues[i] = y;
    }
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License