Introduction

Throughout history, human society has sought to gain a profound understanding of biological signals, originating from the human body. These signals can be electrical or chemical in nature1. Monitoring brain activity and heart rate provides valuable insights into both physical and mental health2. It facilitates the early diagnosis of diseases3,4 and suggests interventions to improve cognitive processes4,5 and emotional states6. Different methods are available to measure brain activities, such as electroencephalogram (EEG), functional magnetic resonance imaging (fMRI)6, or functional near-infrared spectroscopy (FNIRS)7. Among them, using EEG is prevalent due to its high temporal resolution8, cost-effectiveness and non-invasiveness. On the other hand, to measure the electrical impulses generated by the heart, an electrocardiogram (ECG) is used.

Cognitive activities, such as mathematical computations, not only engage cognitive abilities but also elicit a range of emotions within the brain9,10. These emotions can impact perception, decision-making, and cognitive performance11. Numerous studies have indicated that EEG and ECG signals experience changes during cognitive activities12. In order to investigate activation patterns of brain regions while performing cognitive tasks spectral analysis utilizing the Fast Fourier Transform (FFT)13, and coherence analysis14 have been employed. Gärtneret al.15 perused the effect of mental calculations on the power spectrum of different EEG frequency bands. They found that in the theta sub-band as performing mental calculation work, the increase in the power spectrum can be observed. Thomeer et al.16 compared EEG signals in resting states and mental calculations. According to their results, in the calculation mode acceleration spectrum entropy of signals increased in different parts of the brain. Inouye et al.17 observed an increase in the brain’s frontal region by comparing the regional cerebral blood flow in resting states and arithmetic tasks. Al-Shargie et al.18 quantified mental stress levels while participants were solving arithmetic tasks with three levels of complexity. Their findings revealed the reduction of alpha band power besides the dominance of the right prefrontal cortex in response to stress.

Researchers have attempted to automatically classify cognitive tasks by employing deep learning19,20 and machine learning21 methods. Hag et al.22 designed a mental arithmetic task that included time pressure and negative feedback as stress-inducing factors. They used a fusion of functional connectivity networks to analyze EEG signals recorded during the execution of the task. The highest stress classification accuracy of 93.2% with optimal features was achieved by the Support vector machine (SVM) classifier. Bergil et al.2 differentiated mental cognitive performance using wavelet-based features and achieved the best classification accuracy of 97.22% with the K-nearest neighbor classifier. Their results improved slightly by combining ECG features.

In the field of neuroscience, studies have rarely discussed the multifaceted effect of mental calculations on the brain and the creation of different emotions and feelings. In most cases, they have processed and analyzed the specific issue or addressed one of the effects of cognitive tasks on the brain by highlighting it. But in reality, to understand the impact of mental calculations, a comprehensive investigation of the brain and emotions consisting of stress, worry, and concentration is essential. Hence, this study aimed to investigate the influence of math calculation on various brain areas and heart rates. First, behavioral features were extracted from the power spectrum and phase spectrum of EEG signals. Effective features and channels with the most significant differences between math calculation and the resting states were identified. Then, machine learning classifiers were used to assess their ability to distinguish between two classes. Moreover, ECG signals were analyzed to examine the difference in heart rates during math and rest states.

Materials and methods

Figure 1 demonstrates the proposed method of the current study, including two processing steps carried out on EEG and ECG signals of healthy subjects during math calculation and rest state. All steps of this method were simulated in the Spyder environment (python 3.8). Initially, the length of the filtered EEG signals was equalized. Next, the phase spectrum besides the power spectrum of signals in different frequency bands was acquired. From these, the Entropy of Entropy (EoE) feature and energy feature were extracted, respectively. Features were selected with statistical analysis and fed into MLP as well as SVM classifiers to separate binary classes. Moreover, using the statistical analysis brain changes of good and bad counters compared to the rest states were perused. Regarding the ECG signal, the heart rate numbers of subjects in resting and doing math calculations were obtained and scrutinized in different time intervals. Further information related to the dataset and method steps was mentioned in the following subsections.

Figure 1
figure 1

Block diagram of the proposed method.

Dataset

The current study used a publicly available dataset provided by the National Technical University of Ukraine23. This dataset comprises EEG signals and an ECG signal from 36 healthy college students (9 males and 27 females) aged between 18 and 28 years. EEGs were recorded based on the 10–20 international system, through electrodes placed over the cortical regions (Fp1, Fp2, F3, F4, Fz, F7, F8, C3, C4, Cz, P3, P4, Pz, T3, T4, T5, T6, O1, O2). During recording signals, the impedance of the electrodes was kept below 5 KΩ, and the sample rate was set at 500 Hz. The experiment was carried out under two distinct conditions. Initially, participants remained in a rest state with closed eyes for 182 s. Subsequently, they engaged in mental arithmetic tasks encompassing the sequential subtraction of two numbers for 62 s. According to task performance (quantity of subtractions and precision of results), subjects were categorized as either good counters or bad counters.

Preprocessing

The EEG dataset of this study was artifact-free in which any artifacts caused by eye blinks, heart rates and muscle moves had been removed by independent component analysis. Additionally, EEG signals were filtered using a high-pass filter with a cut-off frequency of 0.5 Hz and a low-pass filter with a cut-off frequency of 45 Hz. To ensure that the EEG signals were processed for an equal duration, the initial 62 s of both the resting state and mental arithmetic performance were isolated and investigated.

Feature extraction

In order to extract features, the phase spectrum and power spectrum of the signals in five frequency bands, namely delta (1–4 Hz), theta (4–8 Hz), alpha (8–13 Hz), beta (13–32 Hz) and gamma (32–45 Hz) was calculated using the Fast Fourier transform (FFT) method24. Energy is a general signal property that has been assessed in various studies, as signal energy in different brain regions changes in the presence of cognitive activation. Therefore, the energy feature was extracted from the power spectrum of signals in the mentioned frequency bands. Considering \(X[n]\) as the power spectrum of the signal, and N as the number of its samples, the signal energy was calculated from the following equation:

$$E = \sum\limits_{n = 1}^{N} {\left| {X\left[ n \right]} \right|}^{2}$$
(1)

Since calculating entropy value is useful for quantifying the complexity of nonlinear dynamical systems, the EoE feature25 was extracted from the phase spectrum of the signals in each frequency range. The commencing step of EoE involves dividing a series like \(\left\{ {x_{i} } \right\} = \left\{ {x_{1} ,...,x_{N} } \right\}\) into multiple consecutive non-overlapping windows \(w_{j}^{(\tau )} = \left\{ {x_{(j - 1)\tau + 1} ,...,x_{(j - 1)\tau + \tau } } \right\}\). Where \(\tau\) is the length of windows, and \(j\) is the window index which is from 1 to \({N \mathord{\left/ {\vphantom {N \tau }} \right. \kern-0pt} \tau }\). Supposing data interval range between \(x_{\min }\) and \(x_{\max }\), it is divided into \(S_{1}\) slices. The probability \(p_{jk}\) for a specific interval \(x_{i}\) occurring in state \(k\) within the window \(w_{j}^{(\tau )}\) is obtained as follows:

$$p_{jk} = \frac{{{\text{total number of }}x_{i} {\text{ over }}w_{j}^{(\tau )} {\text{ in state }}k}}{\tau }$$
(2)

where \(k\) is a state index ranges from 1 to \(S_{1}\). Then, the Shannon entropy of each window is calculated by

$$y_{j}^{(\tau )} = - \sum\limits_{k = 1}^{{S_{1} }} {p_{jk} \ln p_{jk} }$$
(3)

This process is repeated for each window to create the Shannon entropy sequence \(\left\{ {y_{j}^{(\tau )} } \right\}\) of length \({N \mathord{\left/ {\vphantom {N \tau }} \right. \kern-0pt} \tau }\) for each series. In the subsequent step, the EoE value of the \(\left\{ {x_{i} } \right\}\) series is defined by employing the Shannon entropy again to measure the changing of \(\left\{ {y_{j}^{(\tau )} } \right\}\). It is conceivable that all constituents of \(\left\{ {y_{j}^{(\tau )} } \right\}\) disperse across a set of finite levels, and the number of all possible levels, \(S_{2} (\tau )\), depends on the time scale \(\tau\). For a certain representative \(y_{j}^{(\tau )}\) state over the sequence \(\left\{ {y_{j}^{(\tau )} } \right\}\) to occur in level \(l\), the probability \(P_{l}\) is acquired in the following manner:

$$p_{l} = \frac{{{\text{total number of }}y_{j}^{(\tau )} {\text{ over }}\left\{ {y_{j}^{(\tau )} } \right\}{\text{ in state }}l}}{{{N \mathord{\left/ {\vphantom {N \tau }} \right. \kern-0pt} \tau }}}$$
(4)

where \(l\) determines the level index ranging from 1 to \(S_{2}\). Eventually, the EoE value of \(\left\{ {x_{i} } \right\}\), defining as the Shannon entropy of Shannon entropy sequence \(\left\{ {y_{j}^{(\tau )} } \right\}\) is given by

$$EoE = - \sum\limits_{l = 1}^{{S_{2} }} {p_{l} \ln p_{l} }$$
(5)

Feature selection

Statistical analysis was used to determine brain regions that are mostly activated during the execution of a cognitive task. In this way, meaningful channels of good counters and bad counters in the comparison with rest condition were obtained. After the feature extraction step, the Kolmogorov–Smirnov algorithm specified the normal distribution of channels’ features. Then, the t-test and Kruskal–Wallis techniques were applied if the features exhibited normal or non-normal distributions, respectively. Channels with p-values less than 0.05 were selected, exhibiting significant differences between the two states26,27. By comparing math counters and rest states, 71 features were chosen. However, for good and bad counters, 76 features and 27 features respectively were selected, in comparison with the rest conditions.

Classification

To evaluate the effectiveness of selected features containing meaningful differences, features were standardized and fed into the Multilayer Perceptron (MLP) and Support Vector Machine (SVM) classifiers as inputs. MLP is a feedforward neural network commonly used to classify biological data. Generally, this network has multiple layers of neurons (the input layer, at least one hidden layer, and the output layer) in which all neurons are connected to the previous and subsequent layers28. In addition, SVM is a supervised machine learning method that aims to find an optimal hyperplane to separate features into different classes, by maximizing the margin between them29. This method employs support vectors and kernel functions to effectively handle both linear and non-linear data. The current study applied the MLP and SVM classifiers to distinguish binary classes, including rest vs math counters, rest vs good counters, and rest vs bad counters. The tuning hyper-parameters of classifiers were considered according to Table 1. Using nested cross-validation (nCV), the best model and hyper-parameters for evaluating the performance of test sets were chosen.

Table 1 Hyper-parameter tuning for MLP and SVM models.

The nCV is a convenient method for tuning hyper-parameters of the model. Additionally, it can lead to achieving reliable classification accuracy by preventing overfitting30. The beginning step of nCV is dividing the data into k outer folds. In each outer fold, the k-th fold is designated for testing and the remaining k-1 folds for training. Then, the training set is split into k inner folds, one fold for validation and k-1 folds for training. In the inner k-folds, the best collection of hyper-parameters is determined by evaluating the model’s performance on validation sets. The model with these hyper-parameters is trained by the outer training set and evaluated on the outer test set31. The nCV structure of this study involves eight outer folds, with five inner folds per outer fold, as demonstrated in Fig. 2.

Figure 2
figure 2

Nested K-fold cross-validation visualization.

ECG processing

To pre-process the ECG signals, a low-pass filter with a cut-off frequency of 18 Hz, followed by a high-pass filter with a cut-off frequency of 5 Hz was applied to eliminate artifacts and noise. The initial 62 s of ECG signals were considered to detect heart rates using the R peak determination method in PQRS as follows:

$$Threshold = 2*(rms(ECG)),\;Rwave = Pks > Threshold$$
(6)

where \(Pks\) is the peak of signals. If the amplitudes of these peaks were greater than the predefined threshold, they would be identified as R-waves. The number of R-waves was obtained not only for the overall length of ECG signals in different conditions, but also for the first, middle, and last 10-s intervals for further processing.

Ethics approval and consent to participate

This study utilized publicly available dataset and did not require ethical approval.

Results

The binary classification results using MLP and SVM methods for each outer fold, and the mean accuracy of eight outer folds were reported in Table 2. Overall, it can be seen that these classifiers could successfully classify rest and mental arithmetic tasks by utilizing EoE and energy features derived from all frequency bands. Regarding the classification results of math versus rest, the MLP classifier achieved a considerable mean accuracy of 94.4%, as same as the SVM classifier. In addition, with the MLP classifier, good counters and bad counters were separated from the rest state with mean accuracies of 98.4% and 97.9%, respectively. However, these figures were 90.0% and 95.4% using the SVM classifier.

Table 2 Binary classification results using MLP and SVM algorithms for each outer fold of nested cross validation.

To understand the brain activities of good and bad counters, discriminative brain areas identified through statistical analysis were reported in Table 3. According to the table, the number of channels showing significant EoE as well as energy differences (p-value < 0.05) between rest and good counters is more prevalent than the rest versus bad counters.

Table 3 Discriminative EEG channels of bad counters and good counters based on EoE and energy values in different frequency bands.

After calculating the EoE and energy features for the EEG channels, Fig. 3 shows the number of features with remarkable differences between the brains of good and bad math counters compared to the resting state. These differences were represented using a color scale ranging from white to red. The most change in the brain of bad counters compared to rest state was identified in the occipital lobe. But in the brain of good counters, several areas approach to F4, C4, T4, T5, P3, and O2 experienced prominent changes in comparison with the resting state.

Figure 3
figure 3

EEG channels with significant differences in comparative states: good counters versus rest state and bad counters versus rest state.

After obtaining the number of heartbeats of individuals throughout 62 s, a box plot was created for all circumstances, as shown in Fig. 4. It is evident from the plot that engagement in a cognitive activity elevates heart rates. Also, the spread and median of heartbeats for good counters surpassed bad counters during the execution of the cognitive task.

Figure 4
figure 4

The box plot demonstrating the spread, locality and skewness of subjects’ heartbeats.

Figure 5 is an illustration of the ECG signal after applying a low pass filter prior to a high pass filter for the state of rest and performing mental calculations. The red spots on the signals are R-waves.

Figure 5
figure 5

Detected R-waves after using filters, (a) the state of rest (b) the state of performing mental calculations.

Discussion

Different body behaviors, such as stress, concentration, and fear possess the capability to affect biological signals. It seems that certain phenomena can have multiple influences on the body’s vital signals. However, previous studies have mostly scrutinized the impact of a single behavior like concentration or stress. In this work, a publicly available dataset comprising 36 healthy subjects was used to assess the multiple effects of mental calculations on their EEG and ECG signals. Accordingly, the biological signals of three groups, including rest state, good counters and bad counters were investigated.

In order to evaluate brain activities, the FFT method was applied to EEG signals to calculate the energy of different frequency bands. Even though the remarkable emphasis of the past research was on acquiring energy from the power spectrum, the phase spectrum of signal can also give useful information to find out whether people’s minds are scattered or focused. Hence, along with energy, the EoE of the phase spectrum was also extracted across five frequency bands. Using statistical analysis, discriminative channels were selected in each frequency band based on the type of features. To confirm these results, binary classes (math counters vs rest, good counters vs rest, and bad counters vs rest) were separated using SVM and MLP classifiers. The classification results of more than 94.4% with MLP and 90% with SVM indicated the reliability of the proposed method.

The brain regions that underwent changes during the execution of arithmetic tasks were specified by applying statistical analysis. Based on the energy of meaningful channels, good counters exhibited conspicuous differences in various regions of their brain notably within the alpha and gamma frequency bands. The energy of alpha frequency decremented upon calculation, while the energy in the gamma frequency band increased. Since high-level thoughts are associated with high frequencies, it can be concluded that more processing is done in their brains. It is worth noting that no significant change was found in high-frequency bands among individuals with poor math performance.

To carry out an arithmetic task, it is essential to have adequate concentration. The results indicated a decrease of EoE in brain signals of math counters, especially at high frequencies. At rest state, when a person is not focused on a specific topic or task, his mind may wander and reflect upon different topics and memories, which can lead to an increase in EoE. Supposedly, bad counters entered the decision and concentration stage, but these abilities were inadequate for effective processing. On the other hand, in people who gave more accurate answers, most features had meaningful changes compared to the resting state, due to having better decision-making and concentration aptitude. The results indicate that the brain activity of subjects with incorrect calculations partially overlaps with the other two groups (subjects in the rest condition and subjects with good calculations), suggesting that their neural activity can be classified as an intermediary state.

The comparison between the rest state with both good counters and bad counters showed changes in the areas under the O1 and O2 channels, which can be attributed to visual attention for remembering and answering questions. By observing significant differences in the central and frontal parts of the brain, it is possible to distinguish individuals with good and bad performance. The central regions can be related to motor functions and deep brain processes such as memory, which are highly activated in the brain of good counters. When subtracting a 2-digit number from a 4-digit number, participants mentally wrote down each digit to remember it and finally reported the answer with their fingers. Furthermore, a significant discrepancy was seen in the F4 and F8 channels, which are associated with calculation, emotion processing and working memory. It can be inferred that math calculations can create multiple effects of stress and concentration in the brain.

Regarding heart rates, it was discovered that the heart rates of math counters increased in comparison to the resting state. Moreover, the heart rate variability of good counters who calculated well was more than that of individuals with poor performance. By examining the heart rates in three 10s intervals, in the first 10s, the heart rate enhanced owing to the commencing of a processing action that the heart supplies blood to the organs. While, within the middle 10 s, heart rates reached a steady state, and heart rate growth was not perceptible. As time passed, the questions became difficult, which caused a slight increase in heart rate during the last 10s. Because of this processing, the overall heart rate experienced enhancement by performing arithmetic tasks.

The limitation of this study is the small number of subjects. In future work, EEG signals of more subjects will be recorded to improve the results. Moreover, several aspects will be considered, including performing complex computations, adding skin conductance signals, measuring respiratory volumes during computations, and using FMRI for a more detailed analysis of brain areas. Since individuals with incorrect calculations demonstrated lower energy levels in the central and frontal part of the brain than those with accurate calculations, it may be possible to direct individuals’ brains towards the correct calculation cycle by applying neurofeedback.