/* SigLib Correlation Example */ #include #include #include "GraphFunctions.h" #define DATA_SET_1 0 /* Select '1' or '0' to choose between test sequences */ #if DATA_SET_1 #define INPUT_1_LENGTH 20L /* Input array #1 length */ #define INPUT_2_LENGTH 20L /* Input array #2 length */ #define PARTIAL_INPUT_2_LENGTH ((SLArrayIndex_t)10) /* Partial response array length */ SLData_t pSrc1[] = { /* Input data sequence 1 */ 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; SLData_t pSrc2[] = { /* Input data sequence 2 */ 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; #else #define INPUT_1_LENGTH 5L /* Input array #1 length */ #define INPUT_2_LENGTH 3L /* Input array #2 length */ #define PARTIAL_INPUT_2_LENGTH 3L /* Partial response array length */ SLData_t pSrc1[] = { /* Input data sequence 1 */ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; SLData_t pSrc2[] = { /* Input data sequence 2 */ 4.0, 5.0, 6.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; #endif /* Result array length */ #define RESULT_LENGTH ((SLArrayIndex_t)(INPUT_1_LENGTH + INPUT_2_LENGTH - 1)) SLData_t dest[RESULT_LENGTH]; void main(void) { GraphObject *h2DGraph; /* Declare graph object */ int ResultLength; h2DGraph = /* Initialize graph */ Create2DGraph ("Correlation", /* Graph title */ "Time", /* X-Axis label */ "Magnitude", /* Y-Axis label */ SV_AUTO_SCALE, /* Scaling mode */ SV_SIGNED, /* Sign mode */ SV_GRAPH_LINE, /* Graph type */ "localhost"); /* Graph server */ if (h2DGraph == NULL) /* Graph creation failed - e.g is server running ? */ { printf ("\nGraph creation failure. Please check that the server is running\n"); exit (1); } Display2DGraph (h2DGraph, /* Graph handle */ "Noisy Sine Wave A", /* Title of the dataset */ pSrc1, /* Array of Double dataset */ INPUT_1_LENGTH, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nNoisy Sine Wave A\nPlease hit to continue . . ."); getchar (); Display2DGraph (h2DGraph, /* Graph handle */ "Noisy Sine Wave B", /* Title of the dataset */ pSrc2, /* Array of Double dataset */ INPUT_2_LENGTH, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nNoisy Sine Wave B\nPlease hit to continue . . ."); getchar (); ResultLength = 2; SDA_CorrelateLinear (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH, /* Length of array #2 */ ResultLength); /* Number of correlations */ Display2DGraph (h2DGraph, /* Graph handle */ "Correlated Data - 2", /* Title of the dataset */ dest, /* Array of Double dataset */ ResultLength, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCorrelated Data - 2\nPlease hit to continue . . ."); getchar (); ResultLength = 3; SDA_CorrelateLinear (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH, /* Length of array #2 */ ResultLength); /* Number of correlations */ Display2DGraph (h2DGraph, /* Graph handle */ "Correlated Data - 3", /* Title of the dataset */ dest, /* Array of Double dataset */ ResultLength, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCorrelated Data - 3\nPlease hit to continue . . ."); getchar (); ResultLength = 4; SDA_CorrelateLinear (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH, /* Length of array #2 */ ResultLength); /* Number of correlations */ Display2DGraph (h2DGraph, /* Graph handle */ "Correlated Data - 4", /* Title of the dataset */ dest, /* Array of Double dataset */ ResultLength, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCorrelated Data - 4\nPlease hit to continue . . ."); getchar (); ResultLength = 5; SDA_CorrelateLinear (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH, /* Length of array #2 */ ResultLength); /* Number of correlations */ Display2DGraph (h2DGraph, /* Graph handle */ "Correlated Data - 5", /* Title of the dataset */ dest, /* Array of Double dataset */ ResultLength, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCorrelated Data - 5\nPlease hit to continue . . ."); getchar (); ResultLength = 6; SDA_CorrelateLinear (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH, /* Length of array #2 */ ResultLength); /* Number of correlations */ Display2DGraph (h2DGraph, /* Graph handle */ "Correlated Data - 6", /* Title of the dataset */ dest, /* Array of Double dataset */ ResultLength, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCorrelated Data - 6\nPlease hit to continue . . ."); getchar (); ResultLength = 7; SDA_CorrelateLinear (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH, /* Length of array #2 */ ResultLength); /* Number of correlations */ Display2DGraph (h2DGraph, /* Graph handle */ "Correlated Data - 7", /* Title of the dataset */ dest, /* Array of Double dataset */ ResultLength, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCorrelated Data - 7\nPlease hit to continue . . ."); getchar (); SDA_CorrelatePartial (pSrc1, /* Pointer to input array #1 */ pSrc2, /* Pointer to input array #2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH, /* Length of array #1 */ INPUT_2_LENGTH); /* Length of array #2 */ Display2DGraph (h2DGraph, /* Graph handle */ "Partially Correlated Data", /* Title of the dataset */ dest, /* Array of Double dataset */ INPUT_1_LENGTH-INPUT_2_LENGTH+1, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nPartially Correlated Data\nPlease hit to continue . . ."); getchar (); SDA_CorrelateCircular (pSrc1, /* Pointer to input array 1 */ pSrc2, /* Pointer to input array 2 */ dest, /* Pointer to destination array */ INPUT_1_LENGTH); /* Length of input arrays */ Display2DGraph (h2DGraph, /* Graph handle */ "Circularly Correlated Data", /* Title of the dataset */ dest, /* Array of Double dataset */ INPUT_1_LENGTH, /* Number of data points */ SV_GRAPH_LINE, /* Graph type */ SV_BLUE, /* Colour */ SV_HIDE_MARKERS, /* Marker enable / disable */ SV_GRAPH_NEW); /* New graph */ printf ("\nCircularly Correlated Data\n"); }