1
$\begingroup$

I'm aware of this question here that uses MatrixPlot to plot the spectrogram of a sound file, but it's too complicated for me to understand, unfortunately.

My file consists of 1000 lines and several thousand columns of data that represent the intensity of a signal, taken at identical time ticks after a trigger signal has occurred. As an example, the first few columns and lines look like this:

0, -0.028346,   -0.028346,  -0.028346
1, -0.028346,   -0.028346,  -0.028346
2, -0.028346,   -0.028346,  -0.028346
3, -0.028346,   -0.028346,  -0.028346
4, -0.027056,   -0.027056,  -0.028346

My idea was to:

  • Import my file with mydata = Import["myfile.csv", "CSV"]
  • determine the minimum and maximum of this data to have reference values with min = Min[Abs[data]]; and max=Max[Abs[data]]
  • make a plot as follows: every column should be represented by a line of dots/pixels, color-coded to represent the intensity of the signal (What function would I use here?)
  • stack all these lines, aligned with each other, on top of each other, such that the time/columns from mydata basically goes from bottom to top

Am I on the right track or should I use something else instead?

EDIT: found an easy answer myself that I will post below.

$\endgroup$
  • 2
    $\begingroup$ Are you sure your time would not be better spent trying to understand the existing solution, rather than trying to reinvent the wheel? Also, you will want to include a complete data set if you can. $\endgroup$ – MarcoB Dec 9 '19 at 16:37
  • $\begingroup$ Does this answer your question? Computing and plotting a spectrogram in Mathematica $\endgroup$ – bbgodfrey Dec 15 '19 at 17:07
1
$\begingroup$

So, here's a solution that I found myself that is rather easy to implement and can be adapted to your needs.

Import your data with

data = Import["myfile.csv"];

Then, simply use ArrayPlot or MatrixPlot

ArrayPlot[data,
ColorFunction -> (ColorData["SunsetColors"]),
ColorFunctionScaling -> True]

One can certainly play around with color parameters, graphic scaling etc., but that is quite individually different, so I'll omit it here and just share the image that I got out of my dataset. The two artifact lines are due to some empty columns in my dataset.

Mode behaviour of a free-running laser over approx. 30 min

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.