Exemplo n.º 1
0
        /// <summary>
        /// calculate PSD
        /// </summary>
        /// <param name="data">data for PSD</param>
        /// <param name="start_pos">start pos</param>
        /// <param name="end_pos">end pos, end_pos - start_pos must be a power of 2</param>
        /// <param name="sampling_rate">sampling rate</param>
        /// <param name="window">window function</param>
        /// <returns>Tuple of ampls and freqs arrays of size N / 2 + 1</returns>
        public static Tuple <double[], double[]> get_psd(double[] data, int start_pos, int end_pos, int sampling_rate, int window)
        {
            if ((start_pos < 0) || (end_pos > data.Length) || (start_pos >= end_pos))
            {
                throw new BrainFlowException((int)CustomExitCodes.INVALID_ARGUMENTS_ERROR);
            }
            int len = end_pos - start_pos;

            if ((len & (len - 1)) != 0)
            {
                throw new BrainFlowException((int)CustomExitCodes.INVALID_ARGUMENTS_ERROR);
            }
            double[] data_to_process = new double[len];
            Array.Copy(data, start_pos, data_to_process, 0, len);
            double[] temp_ampls = new double[len / 2 + 1];
            double[] temp_freqs = new double[len / 2 + 1];

            int res = DataHandlerLibrary.get_psd(data_to_process, len, sampling_rate, window, temp_ampls, temp_freqs);

            if (res != (int)CustomExitCodes.STATUS_OK)
            {
                throw new BrainFlowException(res);
            }
            Tuple <double[], double[]> return_data = new Tuple <double[], double[]>(temp_ampls, temp_freqs);

            return(return_data);
        }