#include <signal.h>
#include <stdio.h>
#define SAMPLE_RATE 50
#define TIME_CONSTANT 2.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 lp,hp,i,u,lpb,hpb;
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("\nIntegrator:\n");
printf("\nLow Pass Butterworth:\n");
printf("\nHigh Pass Butterworth:\n");
printf("\n\n");
printf(" input u |");
printf(" lowpass |");
printf(" highpass |");
printf("complement|");
printf("integrator|");
printf(" lp_butter|");
printf("hp_butter |");
printf("\n");
signal(SIGINT, __signal_handler);
running = 1;
u=1.0;
while(running){
printf("\r");
printf("%8.3f |", u);
printf("%8.3f |", lp);
printf("%8.3f |", hp);
printf("%8.3f |", lp+hp);
printf("%8.3f |", i);
printf("%8.3f |", lpb);
printf("%8.3f |", hpb);
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;
}
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_integrator(rc_filter_t *f, double dt)
Creates a first order integrator.
int rc_filter_print(rc_filter_t f)
Prints the transfer function and other statistic of a filter to the screen.
int rc_filter_butterworth_lowpass(rc_filter_t *f, int order, double dt, double wc)
Creates a Butterworth low pass filter of specified order and cutoff frequency.
int rc_filter_butterworth_highpass(rc_filter_t *f, int order, double dt, double wc)
Creates a Butterworth high pass filter of specified order and cutoff frequency.
void rc_usleep(unsigned int us)
Sleep in microseconds.
Struct containing configuration and state of a SISO filter.
Definition: filter.h:43