I\'m trying to perform STFT on an audio file. I need to get the fft of each window.
I used the follwing code.
[wave,fs] = wavread(\'40.wav\');
w_len
As the error message says, you are trying to access a position in wave
tat does not exist.
See this example:
a = rand(7,1);
step = 4;
1:step:7
ans =
1 5
when v = 5
, you will try to access position v:v+step
, i.e. 5 to 9, but a
is only defined up to 7 elements.
In your case, wave
is defined up to length(wave)
, but on the last iteration you will go out of bounds.
To avoid it, on approach would be to sample the end sequences and subtract the length of the sequence:
pos = (1+w_length:w_length:length(wave))-w_length
for v = pos
% do stuff
end
However, you will be left with some unprocessed part which you will have to do outside of the loop as last iteration.