Skip to content

Commit

Permalink
Comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
dmidem authored and Dmitry Demin committed Mar 7, 2016
1 parent 281fe5d commit 57c3403
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
IIR filter using Laplace transform
Implementation of IIR-filter for given Laplace transform.
4 changes: 4 additions & 0 deletions dumper.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
Routines to print polynoms and filter transform functions (used for testing purposes).
*/

#ifndef DUMPER_H
#define DUMPER_H

Expand Down
12 changes: 9 additions & 3 deletions filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "filter.h"

#ifdef DEBUG_DUMP
#include "dumper.h"
#endif


void bilinear_transform_n(const double *s, const int ns, const double t, double *znum, double *zden)
{
Expand Down Expand Up @@ -60,10 +64,10 @@ int bilinear_transform_nd(const double *snum, const int nsnum, const double *sde
bilinear_transform_n(snum, nsnum, t, znumnum, znumden);
bilinear_transform_n(sden, nsden, t, zdennum, zdenden);

/*
#ifdef DEBUG_DUMP
print_polynom_nd(znumnum, nsnum, znumden, nsnum, 'z', "zn");
print_polynom_nd(zdennum, nsden, zdenden, nsden, 'z', "zd");
*/
#endif // DEBUG_DUMP

clear_polynom(znumden, nsnum);
clear_polynom(zdenden, nsden);
Expand Down Expand Up @@ -216,7 +220,9 @@ IIR_FILTER *laplace_zp_filter(const complex *zlc, const int nzlc,
expand_zerolist_c(plc, nplc, pkc, den_c);
copy_polynom_cr(den_c, nden, den);

//print_polynom_nd(num, nnum, den, nden, 's', "zp nd");
#ifdef DEBUG_DUMP
print_polynom_nd(num, nnum, den, nden, 's', "zp nd");
#endif // DEBUG_DUMP

return laplace_nd_filter(num, nnum, den, nden, dt, L);
}
18 changes: 18 additions & 0 deletions filter.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
/*
IIR filter-related functions.
*/

#ifndef FILTER_H
#define FILTER_H

#include "polynom.h"

// IIR-filter
typedef struct {
// Feedforward filter coefficients
double *b;
int m;

// Feedback filter coefficients
double *a;
int n;

// Filter state (input and output signal values history)
double *x;
double *y;
} IIR_FILTER;

// Bilinear transform implementations (https://en.wikipedia.org/wiki/Bilinear_transform)
void bilinear_transform_n(const double *s, const int ns, const double t, double *znum, double *zden);
int bilinear_transform_nd(const double *snum, const int nsnum, const double *sden, const int nsden,
const double t, double *znum, double *zden);

// Create IIR-filter based on given difference equation
IIR_FILTER *iir_filter_init(const double *b, const int m, const double *a, const int n);

// Free (destroy) IIR-filter
void iir_filter_free(IIR_FILTER *iir);

// Get next output value of IIR-filter
double iir_filter_next(IIR_FILTER *iir, const double x);

// Zero-Denominator Laplace transform IIR-filter
IIR_FILTER *laplace_nd_filter(const double *num, const int nnum,
const double *den, const int nden,
const double dt, const int L);

// Zero-Pole Laplace transform IIR-filter
IIR_FILTER *laplace_zp_filter(const complex *zlc, const int nzlc,
const complex *plc, const int nplc,
const complex zkc, const double dt, const int L);
Expand Down
4 changes: 4 additions & 0 deletions filter_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
Main module for filter testing.
*/

#include <stdio.h>
#include <math.h>

Expand Down
4 changes: 4 additions & 0 deletions polynom.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
Mini-library of functions to operate polynoms.
*/

#ifndef POLYNOM_H
#define POLYNOM_H

Expand Down
4 changes: 4 additions & 0 deletions polynom_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
Main module for polynom operations testing.
*/

#include <stdio.h>

#include "polynom.h"
Expand Down

0 comments on commit 57c3403

Please sign in to comment.