private double[] DFT1DRealToComplex() { /* Real-to-complex 1D transform * for double precision data * not inplace with pack format * Configuration parameters for MKL DFTI * DFTI.FORWARD_DOMAIN = DFTI.REAL * DFTI.PRECISION = DFTI.DOUBLE * DFTI.DIMENSION = 1 * DFTI.LENGTHS = INPUT_SIZE (n) * DFTI.PLACEMENT = DFTI.NOT_INPLACE * DFTI.BACKWARD_SCALE = (1.0 / n) (backwardScale) * Default values: * DFTI.PACKED_FORMAT = DFTI.PACK_FORMAT * DFTI.FORWARD_SCALE = 1.0 */ IntPtr descriptor = new IntPtr(); int precision = DFTI.DOUBLE; int forwardDomain = DFTI.REAL; int dimension = 1; int n = INPUT_SIZE; // The input data to be transformed double[] input = Generate1DInput(); // Create a new DFTI descriptor DFTI.DftiCreateDescriptor(ref descriptor, precision, forwardDomain, dimension, n); // Configure DFTI.BACKWARD_SCALE double backwardScale = 1.0 / n; DFTI.DftiSetValue(descriptor, DFTI.BACKWARD_SCALE, backwardScale); // Configure DFTI.PLACEMENT DFTI.DftiSetValue(descriptor, DFTI.PLACEMENT, DFTI.NOT_INPLACE); // Configure DFTI.PACKET_FORMAT DFTI.DftiSetValue(descriptor, DFTI.PACKED_FORMAT, DFTI.PACK_FORMAT); // Commit the descriptor with the configuration DFTI.DftiCommitDescriptor(descriptor); // This is the output array double[] output = new double[n]; // Compute the forward transform var err = DFTI.DftiComputeForward(descriptor, input, output); // Free the descriptor DFTI.DftiFreeDescriptor(ref descriptor); if (err == DFTI.NO_ERROR) { return(output); } else { throw new MKLException( String.Format("DFTI returned error code {0}", err)); } }
public static void Test() { IntPtr desc = new IntPtr(); int precision = DFTI.DOUBLE; int forward_domain = DFTI.REAL; int dimension = 1, length = 6; /* The data to be transformed */ double[] x_normal = new double[length]; double[] x_transformed = new double[length]; /* Create new DFTI descriptor */ int ret = DFTI.DftiCreateDescriptor(ref desc, precision, forward_domain, dimension, length); Debug.WriteLine("ret = " + ret); /* Setup the scale factor */ long transform_size = length; double scale_factor = 1.0 / transform_size; ret = DFTI.DftiSetValue(desc, DFTI.BACKWARD_SCALE, scale_factor); Debug.WriteLine("ret = " + ret); /* Try floating-point and GetValue function */ double backward_scale = 0; ret = DFTI.DftiGetValue(desc, DFTI.BACKWARD_SCALE, ref backward_scale); Debug.WriteLine("ret = " + ret); Debug.WriteLine("Backward transform scale: " + backward_scale); /* Setup the transform parameters */ ret = DFTI.DftiSetValue(desc, DFTI.PLACEMENT, DFTI.NOT_INPLACE); Debug.WriteLine("ret = " + ret); ret = DFTI.DftiSetValue(desc, DFTI.PACKED_FORMAT, DFTI.PACK_FORMAT); Debug.WriteLine("ret = " + ret); /* Commit the descriptor */ ret = DFTI.DftiCommitDescriptor(desc); Debug.WriteLine("ret = " + ret); /* Initialize the data array */ Debug.WriteLine("Initial data:"); for (int i = 0; i < length; i++) { x_normal[i] = i; Debug.Write("\t" + i); } Debug.WriteLine(""); /* Forward, then backward transform */ ret = DFTI.DftiComputeForward(desc, x_normal, x_transformed); Debug.WriteLine("ret = " + ret); ret = DFTI.DftiComputeBackward(desc, x_transformed, x_normal); Debug.WriteLine("ret = " + ret); DFTI.DftiFreeDescriptor(ref desc); /* Check the data array */ Debug.WriteLine("Resulting data:"); for (int i = 0; i < length; i++) { Debug.Write("\t" + x_normal[i]); } Debug.WriteLine(""); Debug.WriteLine("TEST PASSED"); Debug.WriteLine(""); }