Filter library test

Hello, I changed the code now as recommended:

 // Arduino Signal Filtering an time measurement for Analog Read and Filter


// Arduino Signal Filtering Library
// Copyright 2012-2013 Jeroen Doggen (jeroendoggen@gmail.com)
//http://jeroendoggen.github.io/Arduino-signal-filtering-library/
//http://www.schwietering.com/jayduino/filtuino/


/*
SimPlot Demo
 
Samples Analog Input and sends them over serial port to be plotted in SimPlot.
This Demo software uses the default serial port "Serial".
Upto to 4 channels of data can be plotted.

For details of SimPlot go to
www.negtronics.com/simplot
http://www.negtronics.com/simplot/simplot-code-samples/plot-analog-input-data
 */



#include <SignalFilter.h>

SignalFilter Filter;


unsigned long time_start;
unsigned long time_sampl;
unsigned long time_plot;

int buffer[20]; //Buffer needed to store data packet for transmission
int data1;
int data2;
//int data3;
//int data4;

int incomingByte = 0;




void setup()
{
  Serial.begin(57600);
  Filter.begin();
  Filter.setFilter('c');
  Filter.setOrder(2);
}


void loop()
{


  
   time_start = micros();              //time measurement 
   data1 = analogRead(0);              //for analog 0
   data2 = Filter.run(data1);          // for filter calculation
   time_sampl = micros() - time_start; //time measurement 
  
  
  // time_start = micros();              //time measurement 
  // plot(data1,data2);                   //Plots 2 channels of data
 //  time_plot = micros() - time_start; //time measurement 
  
  
  
  //Read Analog channels. You can connect accelerometer, gyro, temperature sensor etc to these channels
  //I delete the second analogRead and substitute them with the filtered signal 
  data1 = analogRead(0);
  data2= Filter.run(data1);
  // data3 = analogRead(2);
 // data4 = analogRead(3);
 
  //You can plot upto 4 channels of data. Uncomment only one of the options below
 
//   plot(data1,data2,data3,data4);   //Plots 4 channels of data
 // plot(data1,data2,data3);      //Plots 3 channels of data
// plot(data1,data2);            //Plots 2 channels of data
  // plot(data1);                  //Plots 1 channel of data
 
  //delay(1); //Read and plot analog inputs every 1ms. 
  
  

  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 'm') {             // press m and read time in microsec for Filter.run(data1)
      Serial.println(time_sampl, DEC);
        }
      }
   /*   
    if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 'n') {             // press n and read time in microsec for plot(data1,data2)
      Serial.println(time_plot, DEC);
        }
      }*/
   
}




 /*
//Function that takes 4 integer values and generates a packet to be sent to SimPlot.
void plot(int data1, int data2, int data3, int data4) 
{
  int pktSize;
 
  buffer[0] = 0xCDAB;             //SimPlot packet header. Indicates start of data packet
  buffer[1] = 4*sizeof(int);      //Size of data in bytes. Does not include the header and size fields
  buffer[2] = data1;
  buffer[3] = data2;
  buffer[4] = data3;
  buffer[5] = data4;
   
  pktSize = 2 + 2 + (4*sizeof(int)); //Header bytes + size field bytes + data
 
  //IMPORTANT: Change to serial port that is connected to PC
  Serial.write((uint8_t * )buffer, pktSize);
}

//Function that takes 3 integer values and generates a packet to be sent to SimPlot.
void plot(int data1, int data2, int data3)
{
  int pktSize;
 
  buffer[0] = 0xCDAB;             //SimPlot packet header. Indicates start of data packet
  buffer[1] = 3*sizeof(int);      //Size of data in bytes. Does not include the header and size fields
  buffer[2] = data1;
  buffer[3] = data2;
  buffer[4] = data3;
   
  pktSize = 2 + 2 + (3*sizeof(int)); //Header bytes + size field bytes + data
 
  //IMPORTANT: Change to serial port that is connected to PC
  Serial.write((uint8_t * )buffer, pktSize);
}  */
/*
//Function that takes 2 integer values and generates a packet to be sent to SimPlot.
void plot(int data1, int data2)
 
 {
  int pktSize;
 
  buffer[0] = 0xCDAB;             //SimPlot packet header. Indicates start of data packet
  buffer[1] = 2*sizeof(int);      //Size of data in bytes. Does not include the header and size fields
  buffer[2] = data1;
  buffer[3] = data2;
   
  pktSize = 2 + 2 + (2*sizeof(int)); //Header bytes + size field bytes + data
 
  //IMPORTANT: Change to serial port that is connected to PC
  Serial.write((uint8_t * )buffer, pktSize);
}   */


 /*
//Function that takes 1 integer value and generates a packet to be sent to SimPlot.
void plot(int data1)
{
  int pktSize;
 
  buffer[0] = 0xCDAB;             //SimPlot packet header. Indicates start of data packet
  buffer[1] = 1*sizeof(int);      //Size of data in bytes. Does not include the header and size fields
  buffer[2] = data1;
   
  pktSize = 2 + 2 + (1*sizeof(int)); //Header bytes + size field bytes + data
 
  //IMPORTANT: Change to serial port that is connected to PC
  Serial.write((uint8_t * )buffer, pktSize);
}   */

I hope I didnt make big errors! Explanation: Only when I enter and send “m” (in serial monitor window) I get time measurement for “AnalogIn0” and “Filter.run(data1);”. It gives me 172usec (attachment: Time_mes_plotoff). So theoretically I have a sample rate of 5.814Hz. I tried also to measure the time for „plot(data1,data2)“, but its unreadable, because of all other symbols in the serial monitor window, read from real time plotting orders (attachment: Time_mes_ploton).
The thing is that I used the real-time-plot only to check if the filter works accurately. Maybe the right description of the problem I have now is the Heisenbug. Wikipedia: “Heisenbugs occur because common attempts to debug a program, such as inserting output statements or running it in a debugger, usually modify the code, change the memory addresses of variables and the timing of its execution.”
In my end project I wouldn`t need the real-time-plot anymore. I want only that a LED switches on when a tone with a certain threshold (amplitude) passes the bandpassfilter. Maybe does it be also a good way to check if the filter library works fine? So with my lowpassfilter (cutoff frequency 300Hz) the LED should be shine until 300Hz and switched off with all frequencies above 300Hz.
Or do you know other, maybe more accurate methods to test the filters?