How to access the variables in the for loop?
Show older comments
I need to be able to plot the error from this LPC analysis filter but it doesn't let me access it because it is in the loop. Is there anyway to be able to access it?
sound = audiorecorder(8000,16,1);
disp('Start speaking.');
recordblocking(sound,5);
disp('End of Recording.');
M = 10;
seg = 240;
if (size(x,2) == 1)
x = x';
end
npts = length(x);
nseg = floor(npts/seg);
for each = 1:nseg
xx = x((each - 1)*seg + [1:seg]);
[a,G] = lpc(xx, M);
e = filter(a,1,xx);
G = sqrt(G);
e = e/G;
parameter(each,:) = a;
gain(each) = G;
error((each - 1)*seg + [1:seg]) = e;
end
Answers (1)
Walter Roberson
on 20 Apr 2022
It is not clear to me why you cannot plot e inside the loop?
Create an animatedline() object before the loop.
Inside the loop, create a time vector which is the indices that you used in the line
xx = x((each - 1)*seg + [1:seg]);
but subtract 1, and then divide by the sampling frequency (8000 in this case.) Now you can
addPoints(t, e)
Categories
Find more on Signal Modeling 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!