Pages: [1] 2   Go Down
Author Topic: kurtosis calculations on an analog signal  (Read 986 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey! I am very new to arduino, so please bear with me. I am working on a project where I am taking a sine wave (1V amplitude, 100 Hz) from a function generator, sending it through to my arduino uno by using the ReadAnalogVoltage example, performing kurtosis on a 30 second interval of these samples, and then wirelessly transmitting this information to a nearby laptop using XBee protocol.

What I am struggling with is programming the Arduino. After getting the input voltages from the ReadAnalogVoltage, I have no idea how to program the board so it calculates the kurtosis over a 30sec interval and then how to send those values. Any help or links would greatly help. I appreciate it.

Logged

Offline Offline
Edison Member
*
Karma: 49
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What formula would you use to measure kurtosis, why are you measuring it and how does it apply to sampling a sine wave?

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The overall project will involve taking a chin EMG signal and extracting the Kurtosis, RMS, and Zero Crossings from the analog signal and sending these values wirelessly to a laptop using XBee. Right now, I am focusing on just finding out how to extract Kurtosis from a sine wave because this is an easy way to test if the kurtosis program on the Arduino Uno is working. The formula I want to use for Kurtosis is
[the sum of deviation scores raised to the fourth power divided by the number of scores] / [the sum of squared deviation scores divided by the number of scores]^2
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The formula I want to use for Kurtosis is
How have you computed "the sum of deviation scores". How have you even gotten one "deviation score"?

The blink without delay example will show you how to do something for any desired interval.

Logged

0
Offline Offline
Shannon Member
****
Karma: 215
Posts: 12489
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've learnt a new word today, thanks!

So the question is kurtosis applies to a distribution, so what distribution are you sampling,
simply the voltage samples, or something else like phase or amplitude?

What code do you have now - always post your code if you want someone to suggest
improvements or changes!

Is your problem simply how to translate maths into C code?
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I am very new to programming so I am having difficulty translating the math into code. I also can't figure out what code to use to set it so that it takes 30 seconds of sampled data of the analog signal and then performs the math on that 30 sec set.

Ideally, what the output of the system would be is the kurtosis value of every 30 second interval of the analog signal.

I would post my code, but it still needs a lot of work before it can even be critiqued!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is what I have so far but I know it needs work

unsigned long interval=micros();

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  float voltage= sensorValue * (5.0 / 1024.0);
  delay(1);       
}

if micros()-interval=30000;
{ ???I NEED TO WRITE THE FUNCTION TO FIND KURTOSIS HERE???
interval=micros()
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

micros() is for microseconds. There are 30,000,000 microseconds in 30 seconds. There are 30,000 milliseconds, as counted by millis(), in 30 seconds. Since timing to the nearest millionth of a second seems unnecessary, you should be using millis().

Quote
if micros()-interval=30000;
{ ???I NEED TO WRITE THE FUNCTION TO FIND KURTOSIS HERE???
interval=micros()
}  
No. All code needs to be inside a function. The first thing that you need to define is when the 30 second interval starts. Typically, that would involve reading a "Start" switch. When the switch is pressed, you note the time, and the fact that readings are important.

When readings are important, you read the sensor and store the data:
Code:
bool takeReadings = false;
unsigned long startedReading = 0;
void loop()
{
   // see if switch is pressed now but wasn't before
   // if so, record the time, and set the flag takeReadings to true.
   if(somethingGoesHere)
   {
       takeReadings = true;
       startedReading = millis();
   }

   if(takeReadings)
   {
      if(millis() - startedReading < 30000)
      {
          // read and store...
      }
      else
      {
          startedReading = 0;
          takeReadings = false;
      }
   }
}

You'd deal with the stored data in the else block.

The state change detection example would be useful for reading the switch.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much PaulS. That is very insightful. The only problem I have is I want to continuously take 30 second intervals. For example, I want to output the kurtosis from the start of the recording to 30s, the kurtosis from 30sec-60secs, the kurtosis from 60-90s, etc.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 640
Posts: 50335
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The only problem I have is I want to continuously take 30 second intervals.
So, simple remove the part about reading the switch. Set takeReadings to true, initially. Take readings for 30 seconds. Then, set takeReadings to false, so you can process the data you gathered. When you are done processing the data, set takeReadings back to true.

Now, the next thing to consider is how often you take a reading, and how many readings that translates into, and how much data you need to store for 30 seconds with of readings. Then, consider which Arduino(s) can store that much data. A 328-based Arduino can store less than 1000 readings.
Logged

Offline Offline
Edison Member
*
Karma: 49
Posts: 1670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It still doesn't make any sense that you want the kurtosis of a 30 second sample of a sine wave.
What does that tell you?

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is just for testing of the arduino to make sure the kurtosis program works. Eventually this program will be implemented into a system that will read an EMG and extract the kurtosis and send it to a nearby laptop in order to analyze REM sleep.

PaulS you make a good point of how much data the Arduino could store. Therefore, I have revised my plans on the project. Is there a way where I could use a program similar to that of a running averager and take a certain amount of terms and have it calculate the kurtosis at each moment? How could you write the code for this? Especially with the kurtosis, I don't know how to change the formula into code for the arduino sketch.
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have a collection of samples,   the kurtosis calculation is simple.

The problem here is that you want to collect way too many samples for the memory capacity of the arduino.

In fact,   your whole project seems to be misconceived.   What are you actually trying to measure ?   Some kind of deviation from a proper sine wave,   where the peaks of the sinusoidal waveform are "too peaky" ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you write the code for a simple kurtosis calculation then?

I understand that my first method of analyzing thirty seconds of samples would use too much memory for the arduino. Thats why I am hoping to program the arduino to take the kurtosis of lets say 10 samples and function as a moving averager where as it intakes another sample from the front, it gets rid of the sample at the back.

I need to figure out how to write a program that obtains the kurtosis, because in the final project these kurtosis values are valuable to score REM sleep. The kurtosis of the sine wave is simply a test to make sure the kurtosis program is working due to the fact sine waves have a know kurtosis value.

Thank you for your help and comments. I greatly appreciate it.
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you even know what kurtosis is ?
Logged

Pages: [1] 2   Go Up
Jump to: