apocalypse
apocalypse

Reputation: 5884

Can anyone make me understand this MATLAB code?

Here is a file: http://www.ee.columbia.edu/~dpwe/e6820/matlab/stft.m

and the lines:

else
  win = w;
  w = length(w);
end

Why w has assigned length(w) if w is not used anymore in code?

Upvotes: 1

Views: 96

Answers (1)

Jonas
Jonas

Reputation: 74930

The third input to stft.m can either be a scalar containing the window size, or the window itself. Internally, the window is represented as win, the window size as w.

Consequently, if the window itself has been passed to the function, win can be read directly from the input, and w has to be replaced by its length in order to be consistent.

Replacing w by its length is not necessary, since w is no longer used in the code. However, it facilitates debugging, because variables are assigned consistent values, and it facilitates extension of the code, if, in the future, the algorithm is improved in a way that involves the window size w.

In short: the line is currently not needed, but improves maintainability of the code in the long run.

Upvotes: 3

Related Questions