| 1279 | } |
| 1280 | |
| 1281 | int get_custom_band_powers (double *raw_data, int rows, int cols, double *start_freqs, |
| 1282 | double *stop_freqs, int num_bands, int sampling_rate, int apply_filters, |
| 1283 | double *avg_band_powers, double *stddev_band_powers) |
| 1284 | { |
| 1285 | if ((sampling_rate < 1) || (raw_data == NULL) || (rows < 1) || (cols < 1) || |
| 1286 | (avg_band_powers == NULL) || (stddev_band_powers == NULL) || (start_freqs == NULL) || |
| 1287 | (stop_freqs == NULL) || (num_bands < 1)) |
| 1288 | { |
| 1289 | data_logger->error ("Please review your arguments."); |
| 1290 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 1291 | } |
| 1292 | |
| 1293 | // rows - channels, cols - datapoints |
| 1294 | int *exit_codes = new int[rows]; |
| 1295 | for (int i = 0; i < rows; i++) |
| 1296 | { |
| 1297 | exit_codes[i] = (int)BrainFlowExitCodes::STATUS_OK; |
| 1298 | } |
| 1299 | int nfft = 0; |
| 1300 | get_nearest_power_of_two (sampling_rate, &nfft); |
| 1301 | nfft *= 2; // for resolution ~ 0.5 |
| 1302 | // handle the case if nfft > number of data points |
| 1303 | // its valid case but results will not be accurate |
| 1304 | while (nfft > cols) |
| 1305 | { |
| 1306 | nfft /= 2; |
| 1307 | } |
| 1308 | if (nfft < 8) |
| 1309 | { |
| 1310 | data_logger->error ("Not enough data for calculation."); |
| 1311 | delete[] exit_codes; |
| 1312 | return (int)BrainFlowExitCodes::INVALID_BUFFER_SIZE_ERROR; |
| 1313 | } |
| 1314 | double **bands = new double *[num_bands]; |
| 1315 | for (int i = 0; i < num_bands; i++) |
| 1316 | { |
| 1317 | bands[i] = new double[rows]; |
| 1318 | // to make valgrind happy |
| 1319 | for (int j = 0; j < rows; j++) |
| 1320 | { |
| 1321 | bands[i][j] = 0.0; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | #pragma omp parallel for |
| 1326 | for (int i = 0; i < rows; i++) |
| 1327 | { |
| 1328 | double *ampls = new double[nfft / 2 + 1]; |
| 1329 | double *freqs = new double[nfft / 2 + 1]; |
| 1330 | double *thread_data = new double[cols]; |
| 1331 | memcpy (thread_data, raw_data + i * cols, sizeof (double) * cols); |
| 1332 | |
| 1333 | if (apply_filters) |
| 1334 | { |
| 1335 | exit_codes[i] = detrend (thread_data, cols, (int)DetrendOperations::CONSTANT); |
| 1336 | if (exit_codes[i] == (int)BrainFlowExitCodes::STATUS_OK) |
| 1337 | { |
| 1338 | exit_codes[i] = perform_bandstop (thread_data, cols, sampling_rate, 48.0, 52.0, 4, |
no test coverage detected