Question: 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?

Answer: 
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>
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.