| 1236 | } |
| 1237 | |
| 1238 | int get_psd_welch (double *data, int data_len, int nfft, int overlap, int sampling_rate, |
| 1239 | int window_function, double *output_ampl, double *output_freq) |
| 1240 | { |
| 1241 | if ((data == NULL) || (data_len < 1) || (nfft & (nfft - 1)) || (output_ampl == NULL) || |
| 1242 | (output_freq == NULL) || (sampling_rate < 1) || (overlap < 0) || (overlap > nfft)) |
| 1243 | { |
| 1244 | data_logger->error ("Please review your arguments."); |
| 1245 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 1246 | } |
| 1247 | double *ampls = new double[nfft / 2 + 1]; |
| 1248 | int counter = 0; |
| 1249 | for (int i = 0; i < nfft / 2 + 1; i++) |
| 1250 | { |
| 1251 | output_ampl[i] = 0.0; |
| 1252 | } |
| 1253 | for (int pos = 0; (pos + nfft) <= data_len; pos += (nfft - overlap), counter++) |
| 1254 | { |
| 1255 | int res = get_psd (data + pos, nfft, sampling_rate, window_function, ampls, output_freq); |
| 1256 | if (res != (int)BrainFlowExitCodes::STATUS_OK) |
| 1257 | { |
| 1258 | delete[] ampls; |
| 1259 | return res; |
| 1260 | } |
| 1261 | for (int i = 0; i < nfft / 2 + 1; i++) |
| 1262 | { |
| 1263 | output_ampl[i] += ampls[i]; |
| 1264 | } |
| 1265 | } |
| 1266 | delete[] ampls; |
| 1267 | if (counter == 0) |
| 1268 | { |
| 1269 | data_logger->error ("Nfft must be less than data_len."); |
| 1270 | return (int)BrainFlowExitCodes::INVALID_ARGUMENTS_ERROR; |
| 1271 | } |
| 1272 | // average data |
| 1273 | for (int i = 0; i < nfft / 2; i++) |
| 1274 | { |
| 1275 | output_ampl[i] /= counter; |
| 1276 | } |
| 1277 | |
| 1278 | return (int)BrainFlowExitCodes::STATUS_OK; |
| 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, |
no test coverage detected