I'm coding an analysis/synthesis system on MATLAB. I was able to recover the original signal when the length of the window (winLen) is set equal to the length of the FFT (FFTLen). When they are not equal, the results becomes erroneous. What is the cause of this error?

The analysis side consists of a time-domain input which is windowed with a Bartlett window followed by a FFT. The window shift corresponds to half of the window length. The FFT-ed sequence is decomposed into log magnitude and phase components. (Since the sequence is real, only the first half of the magnitude is stored.)

The synthesis side consists of concatenating the magnitude with its flipped version multiplied by the phase, which gives the initial FFT results before decomposition. Then IFFT is performed where the length is equal to the length of the time-domain window. The result is obtained from OLA process (since the Bartlett window is used in the analysis stage, a simple OLA will yield the original sequence).

% load input
cc = cc(1,:);
[~,T] = size(cc);

% window parameters
winLen = 32; % perfect reconstruction when winLen=FFTLen
winShift = winLen/2;
FFTLen = 64;
N = ceil((T-winLen)/winShift) + 1; % number of frames

ms = zeros(1,(FFTLen/2)+1,N);
mp = zeros(1,FFTLen,N);
y = [cc(1,:) zeros(1,(winLen + winShift * N) - T)]; % zeropad sequence
for n = 1:N
    ibeg = 1 + (n-1) * winShift;
    iend = winLen + (n-1) * winShift;

    buffer = y(ibeg:iend) .* bartlett(winLen)';
    buffer = fft(buffer,FFTLen);

    ms(1,:,n) = log(abs(buffer(1:(end/2)+1)));
    mp(1,:,n) = unwrap(angle(buffer));

ccinv = zeros(1,winLen + (N-1) * winShift);
for n = 1:N
    ibeg = 1 + (n-1) * winShift;
    iend = winLen + (n-1) * winShift;

    msbuf = exp([ms(1,:,n) fliplr(ms(1,2:end-1,n))]) .* exp(1i * mp(1,:,n));
    buffer = ifft(msbuf,winLen);

    ccinv(1,ibeg:iend) = ccinv(1,ibeg:iend) + buffer;
ccinv = real(ccinv);

index = 50:100;

hold on
  • $\begingroup$ Do you know why you use the window? $\endgroup$ Commented Oct 10, 2016 at 5:33
  • $\begingroup$ @MarcusMüller Are you referring to the generic windowing process or the Bartlett window that I've used in this case? If it's the latter, using a Bartlett window in the analysis stage is easily compensated by performing the OLA in the synthesis stage. $\endgroup$ Commented Oct 10, 2016 at 5:35

2 Answers 2


MATLAB documentation says for element-wise operators + and .*:

Numeric or string inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector).

Further explanation:

Two inputs have compatible sizes if, for every dimension, the dimension sizes of the inputs are either the same or one of them is 1.

It looks to me like your code violates this if winLen < FFTLen.


The purpose of a window is being point-wise multiplied with the input data, in order to reduce leakage¹.

I don't know what you were expecting, but you're point-wise multiplying a window that doesn't have the length of the vector you put through the DFT. I really can't make much sense of that – it's plain wrong.

¹: Leakage happens due to the fact that just taking out finitely many samples and putting them through a DFT inherently means that you essentially take the full input (which might be longer), and just multiply it with a rectangular function, which is equivalent to convolution with the sinc function in frequency domain, hence it "smears" out the frequency analysis result

  • $\begingroup$ I think the purpose of having a different FFT length is to increase the frequency resolution for the analysis. Hence the sequence is zero-padded. And I believe this process is implicit in the MATLAB fft command. I'm transcribing part of a toolkit written in perl to MATLAB, and I think the analysis part is analogous to the ones given in the toolkit. $\endgroup$ Commented Oct 10, 2016 at 5:53
  • $\begingroup$ It does make sense to have different dft lengths -it's just necessary that the window length is identical $\endgroup$ Commented Oct 10, 2016 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.