Carlton Banks Carlton Banks - 4 months ago 14
Python Question

How do I properly plot data extracted from a scope as .csv file

I just extracted a .csv file from a scope, which shows how a signal changes in the time duration of 6 seconds. Problem is that I can't come up with a proper way of plotting this signal, without things getting mushed together.

Mushed together like this:

Matplot screen shoot

The .csv file is here.

The signal goes through four stages, which I want to show with the plot, without it being to mushed together? How do I plot it?

More info about the signal:

The signal is a PWM signal that changes frequency. Either plotting the PWM signal vs. time, or the frequency of the PWM signal vs time, would be plot representation I would be /seeking for.


As a rudimentary analysis, you could do the following using a deque to process a sliding window of values:

from collections import deque
import csv
import matplotlib
import matplotlib.pyplot as plt

maxlen = 20
window = deque(maxlen=maxlen)

with open('12a6-data_extracted_2.csv') as f_input:
    csv_input = csv.reader(f_input, skipinitialspace=True)
    header = next(csv_input)

    freq = []
    x = []

    for v1, v2 in csv_input:
        v1 = float(v1)

        if len(window) == maxlen:
            freq.append(maxlen / ((window[-1] - window[0])))

    plt.plot(x, freq)

This would give you an output looking like: