changeset 146:931ebae87964

Tweaks to FakeDataProvider Make generated counter data more realistic. Add the possibility to add noise to the generated data. Make the sampling period easier to change.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 14:45:24 +0100
parents ceac0c01661f
children 1d135f8a1c0b
files fake-data-provider.c
diffstat 1 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/fake-data-provider.c	Wed Jan 22 14:45:24 2014 +0100
+++ b/fake-data-provider.c	Wed Jan 22 14:45:24 2014 +0100
@@ -1,19 +1,24 @@
 /* FXAnalise fake data provider */
 
+#include <analysis.h>
 #include <userint.h>
 #include <utility.h>
 #include <future.h>
 
 #include "data-provider.h"
 
+#define PERIOD 1.0
+#define INCREMENT 0.1
+#define NOISE 0.25
+
+
 int CVICALLBACK FakeDataProvider (void *functionData)
 {
-	int mainThreadId;
+	int i, mainThreadId;
 	double mark;
-	struct event event = {
-		.time = { 0, }, 
-		.data = { 55000000.0, 2.0, 3.0, 4.0 }
-	};
+	struct event event = { 0, };
+	double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 };
+	double noise[NCHAN];
 	
 	/* get main thread id to post messages to it */
 	mainThreadId = CmtGetMainThreadID();
@@ -23,13 +28,22 @@
 		
 		/* update data */
 		gettimeofday(&event.time, NULL);
-		event.data[0] += 0.1;
+		f[0] += INCREMENT;
+		for (i = 0; i < NCHAN; i++) 
+			event.data[i] = f[i];
+		
+#ifdef NOISE
+		/* add noise */
+		GaussNoise(NCHAN, NOISE, -1, noise);
+		for (i = 0; i < NCHAN; i++) 
+			event.data[i] += noise[i];
+#endif
 		
 		/* push data into the data queue */
 		CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
 		
 		/* wait till next second */
-   		SyncWait(mark, 1.00);
+   		SyncWait(mark, PERIOD);
 	}
 	
 	return 0;