
Re: error : "Matrix dimensions must agree" at STFT code
Posted:
Jul 1, 2013 2:38 AM


On Sunday, June 30, 2013 5:35:11 PM UTC+5:30, Tilemachos wrote: > 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); % preallocate STFT output array > > M = length(w); % M = window length, N = FFT length > > zp = zeros(NM,1); % zero padding (to be inserted) > > xoff = 0; % current offset in input signal x > > Mo2 = (M1)/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 (NM)~=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 inpointer by hopsize 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, > > > > Thanks in advance
check this.... x = rand(1,100); M = 100; R = 50; N = 1024; w = hamming(M); nframes = floor(length(x)/R)1; Xtwz = zeros(N,nframes); % preallocate STFT output array M = length(w); % M = window length, N = FFT length zp = zeros(NM,1); % zero padding (to be inserted) xoff = 0; % current offset in input signal x Mo2 = (M1)/2; % Assume M odd for simplicity here for m=1:nframes xt = x(xoff+1:xoff+M);% extract frame of input data xt = xt'; xtw = w .* xt; % apply window to current frame if (NM)~=0 Xtwz = [xtw(Mo2+1:M); zp; xtw(1:Mo2)]; % windowed, zero padded else Xtwz = xtw; end Xtwz(:,1) = fft(xtwz); % STFT for frame m xoff = xoff + R; % advance inpointer by hopsize R end

