From 797573301e63ea0628e8382fc38c7196d745b7c4 Mon Sep 17 00:00:00 2001 From: Dmitry Demin Date: Sun, 13 Sep 2015 22:54:21 +0300 Subject: [PATCH] more complex function as example --- filter_test.c | 20 +++++++++++++++----- makefile | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/filter_test.c b/filter_test.c index d3a5efa..fdf9a9a 100644 --- a/filter_test.c +++ b/filter_test.c @@ -1,15 +1,21 @@ #include +#include #include "filter.h" #include "dumper.h" +double f(const double t) +{ + return sin(t) * sin(t * 0.1); +} + int main() { double snum[] = { 1 }; - double sden[] = { 1, 1 }; + double sden[] = { 1 }; - double dT = 0.01; - int L = 1; + double dT = 0.1; + int L = 10; double tmax = 0.2; int nsnum = sizeof(snum) / sizeof(snum[0]); @@ -23,9 +29,13 @@ int main() print_polynom_nd(iir->b, iir->m + 1, iir->a, iir->n + 1, 'z', "IIR H(z)"); printf("t\tx\ty\n"); - double t, x, y; + double t, x = 0, y; + int l = 0; for (t = 0; t < tmax; t += dt) { - x = 1; + if (--l <= 0) { + x = f(t); + l = L; + } y = iir_filter_next(iir, x); printf("%f\t%f\t%f\n", t, x, y); } diff --git a/makefile b/makefile index f67f305..ec99af3 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,7 @@ EXE=filter_test CC=gcc CFLAGS=-Wall -O3 #LDFLAGS=-static-libgcc -static-libstdc++ -static -LDFLAGS= +LDFLAGS=-lm RM=rm all: $(EXE)