Listing 2

#include "first_ord.h"
void cal_firstorder(struct fstord *filt_1, 
        double corner, double samplef, double fgain, double type)
{
    filt_1->fc = corner;
    filt_1->fs = samplef;
    filt_1->gain = fgain;
    filt_1->alpha = tan(M_PI*corner/samplef);
    filt_1->acoef = (1-filt_1->alpha)/(1+filt_1->alpha);
    filt_1->bcoef = (1+(type*filt_1->acoef))/2;
    filt_1->xn_1 = 0;
    filt_1->yn_1 = 0;
    filt_1->type = type;
}
double first_order(struct fstord *filt_1, double samplein)
{
    filt_1->yn_1 = filt_1->bcoef*samplein + 
        filt_1->type*(-filt_1->bcoef)*filt_1->xn_1+
            filt_1->acoef*filt_1->yn_1;
    filt_1->xn_1 = samplein;
    return(filt_1->yn_1*filt_1->gain);
}