#include <signal.h>
#include <stdio.h>
#define SAMPLE_RATE 50
#define TIME_CONSTANT 2.0
#define DAMP 1.0
static int running = 0;
static void signal_handler(__attribute__ ((unused)) int dummy)
{
running=0;
return;
}
int main()
{
const double dt = 1.0/SAMPLE_RATE;
double lpf,hpf,lpt,hpt,u;
int counter = 0;
printf("\nSample Rate: %dhz\n", SAMPLE_RATE);
printf("Time Constant: %5.2f\n", TIME_CONSTANT);
printf("\nLow Pass:\n");
printf("\nHigh Pass:\n");
printf("\nLow Pass Third Order Complement:\n");
printf("\nHigh Pass Third Order Complement:\n");
printf("\n\n");
printf(" input u |");
printf(" lp_first |");
printf(" hp_first |");
printf(" sum |");
printf(" lp_third |");
printf(" hp_third |");
printf(" sum |");
printf("\n");
signal(SIGINT, signal_handler);
running = 1;
u=1.0;
while(running){
printf("\r");
printf("%8.3lf |", u);
printf("%8.3lf |", lpf);
printf("%8.3lf |", hpf);
printf("%8.3lf |", lpf+hpf);
printf("%8.3lf |", lpt);
printf("%8.3lf |", hpt);
printf("%8.3lf |", lpt+hpt);
fflush(stdout);
counter++;
if(counter >= SAMPLE_RATE*10){
counter = 0.0;
if(u>0.0) u = 0.0;
else u = 1.0;
}
}
printf("\n");
return 0;
}
int rc_filter_third_order_complement(rc_filter_t *lp, rc_filter_t *hp, double freq, double damp, double dt)
Creates a third order symmetric complementary pair of high/low pass filters.
double rc_filter_march(rc_filter_t *f, double new_input)
March a filter forward one step with new input provided as an argument.
int rc_filter_first_order_highpass(rc_filter_t *f, double dt, double tc)
Creates a first order high pass filter.
int rc_filter_first_order_lowpass(rc_filter_t *f, double dt, double tc)
Creates a first order low pass filter.
#define RC_FILTER_INITIALIZER
Definition: filter.h:82
int rc_filter_print(rc_filter_t f)
Prints the transfer function and other statistic of a filter to the screen.
int rc_filter_free(rc_filter_t *f)
Frees the memory allocated by a filter's buffers and coefficient vectors. Also resets all filter prop...
void rc_usleep(unsigned int us)
Sleep in microseconds.
Struct containing configuration and state of a SISO filter.
Definition: filter.h:43