The index of the matrix problem occurs because your file doesn't have 2*Fs = 16000 samples in it (<2 seconds). I noticed other problems as well, like the error is divided with the number of samples, and the read wav file isn't necessarily sampled with 8kHz.
Uploaded a fixed implementation based on this one. After it has been reviewed you should be able to find it on this site.
11 Apr 2010
This file does the PCM thing for any voice signal.
I have the same problem. I want to apply this code on a wav file but it produces a mistake, related with the index of the matrix in line 72.
Please help me to get a PCM code applied on the wav, I need this code my project at the end of study