Real cepstrum in loop

5 views (last 30 days)
Dawid
Dawid on 26 Dec 2011
Hi
I have to compute a real cepstrum of .wav signal taking 20ms parts of signal, skip 5ms. Next I have to plot this in 3D using imagesc and mesh. My problem is in loop when I run rceps function.
My code is
[x,fp]=wavread('name_of_file.wav');
dr=4; %decimation level
fd=fp/dr;
y=decimate(x,dr);
Nd=length(y); %length of decimated signal
t=0:1/fd:(Nd-1)/fd;
next
d=floor(( ( ( ( (Nd-1) /fd) *1000) -20) /5)); %number of 20ms parts with skip
5ms
for i=0:1:d
g=y( ( ( ( ((i*5) +1) /1000) *fd):( ( ( ((i*5) +21) /1000) *fd) );
%g=y(((i*60)+1):((i*60)+240)); %another method of cutting signal
tab(i+1)=rceps(g);
end
After running this code I see an error
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> my_file at 38
tab(i)=rceps(g);
rceps function return real cepstrum of signal. Length of returning signal is the same as argument signal (in my case 20ms, 240 points).
I don't have enough experience to solve this problem, because this is my first time when I use loop in MATLAB and I don't know how to do this correctly.
Thank you for your time
Dawid

Accepted Answer

Dawid
Dawid on 30 Dec 2011
Solution
tab=[];
for i=0:1:d-1
g=y(((i*60)+1):((i*60)+241));
c=rceps(g);
p=c';
tab=[tab; p];
end
Dawid

More Answers (1)

David Young
David Young on 26 Dec 2011
Your receps function returns a vector with 240 elements, and you are trying to assign these to a single element of tab. The error message is telling you that you can't put 240 numbers into a slot that only holds one.
Try assigning the vector to a row of tab rather than to a single element, like this:
tab(i+1, :) = rceps(g);
  2 Comments
Dawid
Dawid on 26 Dec 2011
Thank for your response. I modified code and now it looks like below
for i=0:1:d
g=y(floor( ( ( ( ((i*5) +1) /1000) *fd))):(floor( ( ( ((i*5) +21) /1000) *fd) )));
%g=y(((i*60)+1):((i*60)+241));
tab(i+1, :)=rceps(g);
end
but now I've got an error
??? Subscripted assignment dimension mismatch.
Error in ==> my_file at 34
tab(i+1, :)=rceps(g);
I've tried to declare tab
tab=zeros(143,240); %I've got 143 pieces
but it didn't change anything.
David Young
David Young on 27 Dec 2011
Could you have a look at the size of the result returned by receps:
r = receps(g);
disp(size(r));

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!