0

我无法删除此错误。有人可以帮帮我吗。问题是它在生成 hdl 代码时在步骤 4 中显示了一些错误。

 function [Rxx]=autom(X)    % [Rxx]=autom(x)
Rxx=zeros(1,1024);
for m=1: 1025
for n=1: 1025-m
Rxx(m)=Rxx(m)+X(n)*X(n+m-1);

end
end

%试验台

N=1024;                            % Number of samples
f1=1;                              % Frequency of the sinewave
FS=200;                            % Sampling Frequency
n=0:1023;                           % Sample index numbers
X=zeros(1,1024);
% X=sin(2*pi*1*(0:1023)/200);
X=sin((2*pi*1.*n)./200);
t=[1:1024]*(1/200);
%ti=f1*n/FS;
%x=sin(2*pi*ti);                    % Generate the signal, x(n) 
%t1=[1:N]; 
%t=t1*(1/FS);                          % Prepare a time axis

subplot(2,1,1);                    % Prepare the figure
plot(t,X);        
title('Sinwave of frequency 1000Hz [FS=8000Hz]');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;

Rxx = autom(X(1:1024));                                % Calculate its autocorrelation
subplot(2,1,2);
plot(Rxx);
title('Autocorrelation function of the sinewave'); % Plot the autocorrelation 
xlabel('lags');
ylabel('Autocorrelation');

我得到的错误

4

1 回答 1

0

错误说:“[...] 不受支持的动态矩阵X[...]”

您的问题是,在您正在执行的函数中X(n)*X(n+m-1);,它似乎理解这是动态改变矩阵的大小。我怀疑实际上错误在于Rxx

请注意,您X的长度为 1024,但您的迭代n长度m为 1025。Rxx长度为 1024,但你这样做Rxx(m)m上升到 1025,从而动态改变它的大小(MATLAB 将动态地Rxx从 1024 增加到 1025的大小)

你确定你不想要

function [Rxx]=autom(X)    % [Rxx]=autom(x)
Rxx=zeros(1,1024);
for m=1: 1024
  for n=1: 1024-m
    Rxx(m)=Rxx(m)+X(n)*X(n+m-1);
  end
end
于 2018-07-03T08:55:53.433 回答