/* ***************************************************************************** * * Copyright (c) 2009 - 2024 Teunis van Beelen * All rights reserved. * * Email: teuniz@protonmail.com * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ***************************************************************************** */ /* this program generates an EDFplus or BDFplus testfile with the following signals: signal label/waveform amplitude f sf ------------------------------------------------------ 1 squarewave 100 uV 0.1Hz 200 Hz 2 ramp 100 uV 1 Hz 200 Hz 3 pulse 1 100 uV 1 Hz 200 Hz 4 pulse 2 100 uV 1 Hz 256 Hz 5 pulse 3 100 uV 1 Hz 217 Hz 6 noise 100 uV - Hz 200 Hz 7 sine 1 Hz 100 uV 1 Hz 200 Hz 8 sine 8 Hz + DC 100 uV 8 Hz 200 Hz 9 sine 8.1777 Hz + DC 100 uV 8.25 Hz 200 Hz 10 sine 8.5 Hz 100 uV 8.5Hz 200 Hz 11 sine 15 Hz 100 uV 15 Hz 200 Hz 12 sine 17 Hz 100 uV 17 Hz 200 Hz 13 sine 50 Hz 100 uV 50 Hz 200 Hz 14 DC event 8-bits code 1 V 100 mS/bit 200 Hz */ #include #include #include #include "edflib.h" #define SMP_FREQ (200) #define SMP_FREQ_2 (256) #define SMP_FREQ_3 (217) #define FILE_DURATION (600) #ifndef M_PI #define M_PI (3.14159265358979323846264338327) #endif // Uncomment the next line to create a BDF+ file instead of EDF+: // #define BDF_FORMAT int main(void) { int i, j, hdl, chns; double buf[1000], q, sine_1, sine_8, sine_81777, sine_85, sine_15, sine_17, sine_50; struct{ long long samples; long long triggers[512]; int index; int code; int bitposition; int smp_in_bit; } dc_event_stat; memset(&dc_event_stat, 0, sizeof(dc_event_stat)); dc_event_stat.code = 0; dc_event_stat.triggers[0] = 1951; for(i=1; i<512; i++) { dc_event_stat.triggers[i] = (i * 1667) + 1951; } chns = 14; #ifdef BDF_FORMAT hdl = edfopen_file_writeonly("test_generator.bdf", EDFLIB_FILETYPE_BDFPLUS, chns); #else hdl = edfopen_file_writeonly("test_generator.edf", EDFLIB_FILETYPE_EDFPLUS, chns); #endif if(hdl<0) { printf("error: edfopen_file_writeonly()\n"); return(1); } for(i=0; i= 10) { dc_event_stat.smp_in_bit = 0; dc_event_stat.bitposition++; } if(dc_event_stat.bitposition > 10) { dc_event_stat.bitposition = 0; dc_event_stat.smp_in_bit = 0; dc_event_stat.code++; dc_event_stat.code &= 255; if(++dc_event_stat.index >= 512) { dc_event_stat.index = 0; dc_event_stat.code = 0; } } } else { if(dc_event_stat.samples == dc_event_stat.triggers[dc_event_stat.index]) { /* edfwrite_annotation_latin1(hdl, dc_event_stat.samples * 10LL, -1LL, "Trigger"); */ dc_event_stat.bitposition = 1; dc_event_stat.smp_in_bit = 1; buf[i] = 1.0; } else { buf[i] = 0.0; } } dc_event_stat.samples++; } if(edfwrite_physical_samples(hdl, buf)) { printf("error: edfwrite_physical_samples()\n"); return(1); } } edfwrite_annotation_latin1_hr(hdl, 0LL, -1LL, "Recording starts"); edfwrite_annotation_latin1_hr(hdl, 298000000LL, -1LL, "Test 1"); edfwrite_annotation_latin1_hr(hdl, 294000000LL + (long long)((1000000.0 / SMP_FREQ) * (SMP_FREQ - 2)), -1LL, "pulse 1"); edfwrite_annotation_latin1_hr(hdl, 295000000LL + (long long)((1000000.0 / SMP_FREQ_2) * (SMP_FREQ_2 - 2)), -1LL, "pulse 2"); edfwrite_annotation_latin1_hr(hdl, 296000000LL + (long long)((1000000.0 / SMP_FREQ_3) * (SMP_FREQ_3 - 2)), -1LL, "pulse 3"); edfwrite_annotation_latin1_hr(hdl, FILE_DURATION * 1000000LL, -1LL, "Recording ends"); edfclose_file(hdl); return(0); }