signal processing(EEG) - improving the software

is this software improved enough?

//Realizzato da Daniel Rossi - Made by Daniel Rossi
//5C Blaise Pascal - informatico (IT school)
//Reggio Emilia 06-04-2017
#include <ads1292r.h>
#include <SPI.h>
#include <arduinoFFT.h>

ads1292r ADS1292 ;
arduinoFFT FFT = arduinoFFT();

const uint16_t samples = 32;//This value MUST ALWAYS be a power of 2
const int I_SottoCamp = 32, I_Camp = 128;

//imposta pacchetto da inviare via seriale
uint8_t DataPacketHeader[18], *PACKET;
volatile char DataPacketFooter[2];
volatile int datalen = 135;
uint8_t data_len = 8;

//Packet format
#define CES_CMDIF_PKT_START_1 0x0A
#define CES_CMDIF_PKT_START_2 0xFA
#define CES_CMDIF_TYPE_DATA 0x02
#define CES_CMDIF_PKT_STOP 0x0B

volatile char *SPI_RX_Buff_Ptr;
volatile byte Campioni_Rosso[I_Camp], Campioni_Blu[I_Camp], SPI_RX_Buff[9];
volatile double *DATA, *IMAG, *ALPHA;
volatile double SottoCamp_Rosso[I_SottoCamp], SottoCamp_Blu[I_SottoCamp], filtrato[I_SottoCamp], vImag[I_SottoCamp], Alpha[11];
volatile int i, k;

unsigned long utemp;
signed long stemp;

void ResetImag() {
for (i = 0; i < I_SottoCamp; i++) {
vImag = 0;

  • }*
    }
    void setup() {
  • // initalize the data ready and chip select pins:*
  • pinMode(ADS1292_DRDY_PIN, INPUT); //6*
  • pinMode(ADS1292_CS_PIN, OUTPUT); //7*
  • pinMode(ADS1292_START_PIN, OUTPUT); //5*
  • pinMode(ADS1292_PWDN_PIN, OUTPUT); //4*
  • Serial.begin(57600); // Baudrate for serial communica*
  • //initalize ADS1292 slave*
  • ADS1292.ads1292_Init();*
  • //ADS1292.ads1292_Reset();*
  • DataPacketHeader[0] = CES_CMDIF_PKT_START_1;*
  • DataPacketHeader[1] = CES_CMDIF_PKT_START_2;*
  • DataPacketHeader[2] = (datalen);*
  • DataPacketHeader[3] = (datalen >> 8);*
  • DataPacketHeader[4] = CES_CMDIF_TYPE_DATA;*
  • DataPacketFooter[0] = 0x00;*
  • DataPacketFooter[1] = CES_CMDIF_PKT_STOP;*
  • ResetImag();*
    }
    //questa funzione permette di shiftare i byte dei canali per ricomporre il segnale completo
    //this function allows to shift the bytes of each channel for recomposing the complete signal
    signed long shifting(volatile byte val1, volatile byte val2, volatile byte val3) {
  • utemp = (unsigned long) ((val1 << 16) | (val2 << 8) | val3);*
  • utemp = (unsigned long) (utemp << 8);*
  • stemp = (signed long) (utemp);*
  • stemp = (signed long) (stemp >> 8);*
  • return stemp;*
    }
    //questa funzione viene utilizzata per popolare la parte di pacchetto contenente ogni dato che compone le frequenze EEG
    //this function is used for populating the part of the packet which will contain each data which is a part of EEG frequency
    void feedBodyPacchetto(uint8_t pacchetto[18], volatile double dato[11]) {
  • for (i = 5; i <= 16; i++) {*
    _ pacchetto = dato[i - 5];_
    * }*
    }
    void loop() {
    _ /* creo 2 vettori contenenti 32 campioni ognuno_
    * Campioni_Rosso è il vettore che contiene i valori del sensore rosso(segnale EEG)
    Campioni_Blu è il vettore che contiene i valori del sensore blu(segnale di riferimento)*

* here're populated 2 vectors which contain 32 samples each*
* Campioni_Rosso is the vector related to the red sensor(EEG signal)
Campioni_Blu is the vector which related to the blue sensor(reference signal)
_ /_
for (i = 0; i < I_Camp; i++) {

* if ((digitalRead(ADS1292_DRDY_PIN)) == LOW)
_
{_
SPI_RX_Buff_Ptr = ADS1292.ads1292_Read_Data();
_
for (k = 0; k < 9; k++) {_
SPI_RX_Buff[k] = (SPI_RX_Buff_Ptr + k);
_
}
_
* }*
* //blu*
Campioni_Blu = shifting(SPI_RX_Buff[3], SPI_RX_Buff[4], SPI_RX_Buff[5]);
* //rosso*
Campioni_Rosso = shifting(SPI_RX_Buff[6], SPI_RX_Buff[7] , SPI_RX_Buff[8]);
* }*
* //il segnale viene sottocampionato, viene effettuato un casting a double e infine viene filtrato*
* //the signal is downsampled, it is casted to double and it is filtered*
* k = 0;*
* for (i = 0; i < I_Camp; i += 4) {
SottoCamp_Rosso[k] = ((double)(Campioni_Rosso )) * 1.0;
SottoCamp_Blu[k] = ((double)(Campioni_Blu )) * 1.0;
filtrato[k] = SottoCamp_Rosso[k] - SottoCamp_Blu[k];
_ k++;
}
//2 puntatori punteranno rispettivamente al vettore del segnale e al vettore immaginario*

//2 pointers will point rispectively to the signal vector and the imaginary vector
* DATA = filtrato;
IMAG = vImag;
/

* viene creata una finestra del segnale e viene svolta la trasformata di fourier per il vettore finale ottenuto*
* in modo da passare il segnale dal dominio del tempo al dominio delle frequenze*
* here's called the windowing of the signal and then the FFT for crossing from the*
* time domain to the frequency domain*
/_
FFT.Windowing(DATA, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(DATA, IMAG, samples, FFT_FORWARD);
_ k = 0;
for (i = 0; i < 32; i++) {
if ((vImag > 150) || (vImag < -150)) ResetImag();
if ((i >= 16) && (i <= 26)) {
Alpha[k] = filtrato;
k++;
}
}
for (i = 0; i < 10; i++) {
Serial.println(Alpha);
}
PACKET = DataPacketHeader;
ALPHA = Alpha;
DataPacketHeader[0] = 0x0A;
DataPacketHeader[1] = 0xFA;_

DataPacketHeader[2] = (uint8_t) (data_len);
DataPacketHeader[3] = (uint8_t) (data_len >> 8);
_ DataPacketHeader[4] = 0x02;
feedBodyPacchetto(PACKET, ALPHA);
DataPacketHeader[17] = 0x00;
DataPacketHeader[18] = 0x0b;
for (i = 0; i <= 18; i++) // transmit the data*

* {
Serial.write(DataPacketHeader);
}
} //chiusura void loop*_

is this software improved enough?

Compared to what?

It is badly posted and in the wrong place, so on the whole, I'd say "no".

  for (i = 0; i <= 18; i++) // transmit the dataOops.

Read How to post code properly and then edit your original post so that it has code tags around your code. That will get rid of the italics and the smileys.

Pete