Error: Matrix dimensions must agree
I wrote the following MATLAB code to perform STFT. However I get an error
stating
Matrix dimensions must agree.
This is the code
[wave,fs]=wavread('40.wav'); % read file into memory */
wave = sum(wave,2); % making the signal one channel
w_length = 1024; % Number of samples per stft slice
L = length(wave);
windowing = hamming(w_length); %Windowing function
points_rem = L - floor(L/w_length)*w_length;
if points_rem >0
points_to_zero_pad = w_length - points_rem;
else
points_to_zero_pad = 0;
end
for i = L+1 : L+points_to_zero_pad
wave(i) = 0;
i = i+1;
end
No_of_windows = (length(wave)-w_length)/(w_length*0.5);
for i = 1:No_of_windows
starting = (i-1)*(512)+1;
ending = starting + No_of_windows-1 ;
data_sub = wave(starting:ending).*windowing;
sub_fft = fft(data_sub);
figure(1)
plot(sub_fft);
end
If I however try to plot only one data sub using the following code
instead of the 2nd for loop I don't get any errors.
starting = 1;
ending = starting+w_length-1;
data_sub = wave(starting:ending).*windowing;
sub_fft = fft(data_sub);
figure(1)
plot(sub_fft);
What can I do to solve this?
I also want to plot the FFT of all subsections... How can I do that using
plot?
Thank you
No comments:
Post a Comment