Plotting a variable in a for loop

I am struggling to plot the error in the second for loop.
X = audiorecorder(8000,16,1);
disp('Start speaking.');
recordblocking(X,5);
disp('End of Recording.');
M = 10; % M: Order of LPC model
seg = 30; % Segment or frame size is 240
if (size(x,2) == 1) % Check if x is a column vector
x = x'; % If x is a column vector, convert it to a row vector
end
npts = length(x); % Find the number of samples
nseg = floor(npts/seg); % nseg: Number of segments in the signal
for each = 1:nseg
xx = x((each - 1)*seg + [1:seg]); % pick 240 samples for each segment
[a,G] = lpc(xx, M); % Compute lpc and variance
e = filter(a,1,xx); % Compute residual error signal
G = sqrt(G); % Calculate the standard deviation (gain) of the segment
e = e/G; % Normalize the error signal
parameter(each,:) = a;
gain(each) = G;
error((each - 1)*seg + [1:seg]) = e;
end

답변 (1개)

Voss
Voss 2022년 4월 24일

1 개 추천

I only see one for loop.
X is your audiorecorder object, and x is apparently the recorded audio data, but the relation between X and x is not given in the code, so here I'll create random data x, process it using your code and plot error:
% X = audiorecorder(8000,16,1);
%
% disp('Start speaking.');
% recordblocking(X,5);
% disp('End of Recording.');
x = randn(40000,1); % random data
M = 10; % M: Order of LPC model
seg = 30; % Segment or frame size is 240
if (size(x,2) == 1) % Check if x is a column vector
x = x'; % If x is a column vector, convert it to a row vector
end
npts = length(x); % Find the number of samples
nseg = floor(npts/seg); % nseg: Number of segments in the signal
for each = 1:nseg
xx = x((each - 1)*seg + [1:seg]); % pick 240 samples for each segment
[a,G] = lpc(xx, M); % Compute lpc and variance
e = filter(a,1,xx); % Compute residual error signal
G = sqrt(G); % Calculate the standard deviation (gain) of the segment
e = e/G; % Normalize the error signal
parameter(each,:) = a;
gain(each) = G;
error((each - 1)*seg + [1:seg]) = e;
end
plot(error)

댓글 수: 2

Daniela Trevino
Daniela Trevino 2022년 4월 24일
Thank you!
Voss
Voss 2022년 4월 24일
You're welcome! If anything is not clear, let me know. Otherwise, if that solves the problem, please mark my answer as Accepted by clicking 'Accept this Answer'. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

질문:

2022년 4월 24일

댓글:

2022년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by