matlab code into pseudocode

Can somebody translate this following code into pseudocode (explanation in normal words what is done) as I am not familiar with matlab and I want to implement it in java.


for ii = 1:interval:len
SECTIONS(:,kk) = dividefreqs(Y(ii:ii+window-1).*hanw,FS).';
    kk = kk+1;
end

here especially I dont thet part Y(ii:ii+window-1).*hanw
is Y(ii:ii+window-1) iterating thorugh the array? and I read that if you multiply two arrays they have to have the same size but here "hanw" has size 16317 and window=512

and also this bit of code:

for ii = ssize(1):-1:2
    FREQDIFF(ii-1,:) = SECTIONS(ii-1,:)-SECTIONS(ii,:);
end

for jj = 2:ssize(2)
    SECDIFF(:,jj-1) = FREQDIFF(:,jj) - FREQDIFF(:,jj-1);
end

for ii = 1:ssize(1)-1
    for jj = 1:ssize(2)-1
        if SECDIFF(ii,jj) > 0
            SECBIGGER(ii,jj) = 1;
        end
    end
end
chudyksgAsked:
Who is Participating?
 
yuk99Connect With a Mentor Commented:
The first for-loop will iterate ii from 1 to len with the interval. If interval is negative (as in your second loop) the iteration variable will decrease.

Then you should understand indexing of 2D matrices, like your SECTIONS variable. 1st index means rows, 2nd - columns. Single column symbol (:) means everything. So, SECTIONS(:,kk) means to get all rows in kk-th column (or columns since kk can be a vector in general). If you have only 1 index, it will return matrix elements as a column vector, indexing first all rows from the 1st column, then all rows from the 2nd column, etc.

.* means element-wise multiplication. You are right that variables on both sides of this operator have to be the same size. So, if windows =512, Y(ii:ii+window-1) will return a row vector of size 512. It cannot be multiplied element-wise with a vector of different size, you will get an error.

dividefreqs is a function, probably from some of your package. ' at the end means to transpose the function output to get a column vector.

For the 2nd loop:
ssize is probably 2-element vector of SECTIONS matrix size (rows,columns). ii starts from the number of rows, and goes down with every iteration (-1 interval). Actually this whole operation can be done without using for-loop:
    FREQDIFF = SECTIONS(1:end-1,:)-SECTIONS(2:end,:);
Here "end" means last element number, lasy row in this context.

Same for the 3rd loop, but now the columns get substracted:
    SECDIFF = FREQDIFF(:,2:end) - FREQDIFF(:,1:end-1);

Last nested loop also probably can be avoided, but I don't now the size of SECBIGGER. Do you have a line that creates this matrix or preallocate it?

To understand the code I'd advise to run it in debugging mode. You can then interactively check what different parts of code return.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.