Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: error : "Matrix dimensions must agree" at STFT code
Replies: 7   Last Post: Jul 1, 2013 3:07 PM

 Messages: [ Previous | Next ]
 Tilemachos Posts: 3 Registered: 6/30/13
error : "Matrix dimensions must agree" at STFT code
Posted: Jun 30, 2013 8:05 AM

Dear friends,

I am very new to matlab so forgive my ignorance. I am trying to make a code for an STFT (Short Time Fourier Transform) and then apply it to a wav. file so that i can plot the spectogramm of this wav. file.

Here is the code:

function Xtwz = mystft(x, M, R, N, w)
nframes = floor(length(x)/R)-1;
Xtwz = zeros(N,nframes); % pre-allocate STFT output array
M = length(w); % M = window length, N = FFT length
zp = zeros(N-M,1); % zero padding (to be inserted)
xoff = 0; % current offset in input signal x
Mo2 = (M-1)/2; % Assume M odd for simplicity here
for m=1:nframes
xt = x(xoff+1:xoff+M); % extract frame of input data
xtw = w .* xt; % apply window to current frame
if (N-M)~=0
xtwz = [xtw(Mo2+1:M); zp; xtw(1:Mo2)]; % windowed, zero padded
else
xtwz = xtw;
end
Xtwz(:,m) = fft(xtwz); % STFT for frame m
xoff = xoff + R; % advance in-pointer by hop-size R
end
I input a small wav file, and I give values to M=100, R=50, N=1024, w=hamming(M), and x=data (from the input file). Then when i try to apply the function "mystft" I get the error : "Error using .* /Matrix dimensions must agree./ Error in mystft (line 16)/ xtw = w.*xt; % apply window to current frame"

First of all I am not sure whether the values that i have given to M,R,N are right, and secondly I dont know how can i get rid of this error.

Any help would be appreciated,

Date Subject Author
6/30/13 Tilemachos
6/30/13 dpb
7/1/13 asif khan
7/1/13 Barry Williams
7/1/13 asif khan
7/1/13 Tilemachos
7/1/13 Steven Lord
7/1/13 Barry Williams