sir i tried one code for framing and windowing but the code showing error like this Error in lpcoefficient (line 21) wind(i,:)=fr_ws(i,:).*r(i,:); how i rectify the error
Show older comments
the code is given below,
[x,fs]=audioread('1calf.wav');
s = x(1:93098,:);
N=length(s);
frameduration=0.00475;
framelength=frameduration*fs;
num_frames=floor(N/framelength);
count=0;
for k= 1: num_frames
frames(k,:)=s((k-1)*framelength +1 : framelength*k);
count=count +1;
end
m_amp = abs(max(frames,[],2)); % find maximum of each frame
id = find(m_amp > 0.06); % finding ID of frames with max amp > 0.03
fr_ws = frames(id,:); % frames without silence
for i=1:num_frames
v=length(fr_ws);
r=hamming(v);
wind(i,:)=fr_ws(i,:).*r(i,:);
end
2 Comments
KSSV
on 9 May 2019
What error? Without specifying error and without input data, how you think you will get help?
Suchithra K S
on 9 May 2019
Answers (1)
One hint: In
for i=1:num_frames
v=length(fr_ws);
r=hamming(v);
wind(i,:)=fr_ws(i,:).*r(i,:);
end
v and r are constant. Then move the definition out of the loop to avoid a repeated computation. Maybe wind has the wrong size, because it is not pre-allocated - postinmg the error message would reveal this detail, so share this important message with the readers. Then:
v = length(fr_ws);
r = hamming(v);
wind = zeros(num_frames, v);
for i = 1:num_frames
wind(i,:) = fr_ws(i,:) .* r(i,:);
end
Now r(i, :) is a scalar. Is this wanted, or do you mean:
for i = 1:num_frames
wind(i,:) = fr_ws(i,:) .* r.';
end
I guess, you can omit the loop completely using the modern auto-expanding:
wind = fr_ws .* r.';
7 Comments
Suchithra K S
on 9 May 2019
You tried exactly what? Please post the code, because otherwise the readers do not know, which code produces this error.
Please use the debugger to inspect your problem: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
You can e.g. type this in the command window:
dbstop if error
Afterwards run the code again until Matlab stops at the error. Then check the sizes of the arrays:
size(wind)
size(fr_ws)
size(r)
This shows the sizes of the arrays. You should be able to draw the conclusions how the code must be modified to compute, what you want.
Please note, that you did not mention, what you want to calculate. There are no comments, which explain this for each line. So if I see the failing code only, I cannot guess reliably, how it must be fixed.
I assume, that the code contains more problems, e.g.:
id = find(m_amp > 0.06);
fr_ws = frames(id,:); % Now fr_ws contains less than num_frames rows
for i = 1:num_frames
wind(i,:) = fr_ws(i,:); % But i can exceed the 1st dim of fr_ws?!
end
Suchithra K S
on 9 May 2019
Jan
on 9 May 2019
@Suchithra K S: Please consider my suggestion to use the debugger. This let you find out easily which sizes fr_ws and r have. I cannot run your code due to the missing input data.
Which Matlab version are you using? I've mentioned that my suggested code uses auto-expanding, so it runs in R2016b and higher.
This can be simplified also:
count=0;
for k= 1: num_frames
frames(k,:) = s((k-1)*framelength +1 : framelength*k);
count=count +1;
end
This is a simple reshape command only and count is not used aynwhere else. But even if it is needed later, your can determine the result easily without a loop: count = num_frames.
Suchithra K S
on 9 May 2019
Jan
on 10 May 2019
@Suchithra K S: As soon as you use the debugger and post, what
size(wind)
size(fr_ws)
size(r)
replies, I could post a working solution. Maybe you need:
% R2016a - no auto-expanding:
wind = bsxfun(@times, fr_ws, r.');
Suchithra K S
on 14 May 2019
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!