Finding frequency and amplitude of serial plotter data

Hi there,

I am pretty new to Arduino and using it for the first time. I am not much aware of Arduino IDE. I am working with MPU 6050 for my project. MPU is mounted on an object with oscillatory motion. The output of the serial plotter is shown in the image below. I want to find the frequency of the oscillations and amplitude of the waveform as shown in the image. Can anyone please suggest how to find frequency and amplitude from that serial plotter graph? The serial plotter is showing roll pitch and yaw changing with time and I am only interested in roll data. So in nuts, I am interested in roll amplitude and frequency.

Thanks in Advance.

#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

unsigned long timer = 0;
float timeStep = 0.01;

float pitch = 0;
float roll = 0;
float yaw = 0;

void setup() 
{
  Serial.begin(115200);

  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }
  
  mpu.calibrateGyro();

  mpu.setThreshold(3);
}

void loop()
{
  timer = millis();

  // Read normalized values
  Vector norm = mpu.readNormalizeGyro();

  // Calculate Pitch, Roll and Yaw
  pitch = pitch + norm.YAxis * timeStep;
  roll = roll + norm.XAxis * timeStep;
  yaw = yaw + norm.ZAxis * timeStep;

  // Output raw
  Serial.print(" Pitch = ");
  Serial.print(pitch);
  Serial.print(" Roll = ");
  Serial.print(roll);  
  Serial.print(" Yaw = ");
  Serial.println(yaw);

  delay((timeStep*1000) - (millis() - timer));
}

1 Like

In order to determine the frequency of oscillation, you need the time interval between the plotted points.

1 Like

If you insist on finding the...

...then you'll need a ruler and good eyeballs. :crazy_face:

Another way would be to put the data[*] into Excel or other app with math tools[**]. Once in Excel, or whatever other program, you can analyze it to your heart's content.

Yet another way would be to write code for your Arduino to do that sort of processing.

[*] Of course each data point needs to include a time stamp.

[**] IMHO, the simplest way to get numbers into Excel is to cut from the serial monitor (NOT the plotter) and paste into Excel; then use Excel's text->columns feature. Another is to use PLX-DAQ (see link below). Or save to an SD card, or save to SPIFFS/littleFS if on an ESP.

https://forum.arduino.cc/t/plx-daq-version-2-now-with-64-bit-support-and-further-new-features

1 Like

What I would do is use Serial Monitor rather than Serial Plotter. The data can then be copied from Serial Monitor and pasted into a text file or a spreadsheet for analysis. The amplitude shouldn't be a problem (max - min) but I don't know how to get frequency data from a spreadsheet. You may need time data, so print millis() on each line.

For a spreadsheet it is usually best to separate the data columns with commas or tabs:

  Serial.print(millis();
  Serial.print('\t');
  Serial.print(pitch);
  Serial.print('\t');
  Serial.print(roll);  
  Serial.print('\t');
  Serial.println(yaw);
1 Like

You can try https://www.arduino.cc/reference/en/libraries/arduinofft/

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.