2

I want to plot the waveform of an audiosnippet. Since I am working in matlab I exported my audiofile as csv with two columns (n, in). Of course this produces a huge file of about 40MB for my 1 000 000 datapoints. When I now try to plot this using pgf latex will run into a memory error.

TeX capacity exceeded, sorry [main memory size=5000000]. ...=in,col sep=comma] {audio.csv};

Here is the code I am using to plot:

\begin{tikzpicture}
    \begin{axis}[width = 18cm, height=6cm,grid=both,xlabel={$n$},ylabel={$x(n)$},ymin=-1, ymax=1,minor y tick num=1,xmin=0, xmax=1000000]
    \addplot[color=niceblue] table[x=n,y=in,col sep=comma] {audio.csv};
    \end{axis}
\end{tikzpicture}

My first try was to reduce the filesize by only using every 128th datapoint. But this way I lose "interesting" datapoints, like the peaks. This makes my plot look incorrect.

Does anyone have an idea how to get a nice plot for my waveform?

  • Welcome to TeX.SX! – Heiko Oberdiek Aug 5 '15 at 11:09
  • This is a similar [post][1] I think [1]: tex.stackexchange.com/questions/75399/… – Joe H. Aug 5 '15 at 12:01
  • Thanks, but I think exceeding the memory limit will not help in my situation. Firstly the memory would have to be ridiculously high and secondly the time this would consume is extremely high. I rather thought about how to filter my data to only keep the points that contribute to the look of the actual waveform – Timm Aug 5 '15 at 12:27
  • You could average points together (low pass filter). – John Kormylo Aug 5 '15 at 12:55
  • We had this discussion before a few times. A plot with a million data points for a figure on A4 paper is just not possible. You can instead use every nth point key or similar data skipping or averaging with another tool until it is meaningful again. – percusse Oct 4 '15 at 17:02
1

Perhaps you can reduce the number of points by only plotting the envelope of the waveform. Im not certain if that would suffice for your waveform, but you can use Matlab to extract the envelope from the waveform; http://mathworks.com/help/signal/ug/envelope-extraction-using-the-analytic-signal.html

|improve this answer|||||
0

A bit late to the party, but I was looking to plot (quite a lot) of waveforms in my LaTeX document and came across this in the search. Unfortunately, this is not an exact answer to your question, but a way to accomplish what you want without using tikz / pgf.

  1. Use PythonTeX (You'll need Python install - I used Anaconda Python)
  2. Create \begin{pycode}\end{pycode}environment
  3. Within pycode environment, import the following:
    1. from scipy.io import wavfile
    2. from matplotlib import pyplot as plt
    3. import numpy as np
  4. samplerate, data = wavfile.read(FILENAME/PATH)
  5. times = np.arange(len(data))/float(samplerate)
  6. SET UP the plot/figure if desired
  7. plt.plot(times, data, color='k')
  8. plt.savefig('FILENAME/PATH')
  9. Compile .tex document
  10. Compile python code via `pythontex.exe "FILENAME.tex"
  11. Compile .tex document again (to incorporate image into document)

The memory limitation on tikz / pgf plotting waveforms is too limiting for my needs which is why I went the Python route. There are quite a lot of options in matplotlib.pyplot related to the plot.

Obviously, this is an alternative method. But hopefully it helps anyone who finds tikz/pgf is just not the right option for plotting waveforms in LaTeX.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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