我在MATLAB上编写了以下代码:
N = [64 128 256 512];
NumOfRuns = 50;
PerLength = 2048;
freq = 0:2/(PerLength-1):2;
for m=1:length(N)
Px = zeros(NumOfRuns,PerLength);
for i=1:NumOfRuns
x = randn(1,N(m));
Px(:,i) = periodogram(x);
end
end
当我在MATLAB上运行此代码时,它会给出错误:
订阅的分配维度不匹配。 例子13中的错误(第10行)Px(:,I)=周期图(x)。
答案 0 :(得分:0)
代码备注:
N = [64 128 256 512];
NumOfRuns = 50;
PerLength = 2048;
% freq = 0:2/(PerLength-1):2; % you are not using freq
% You are looping from 1:4, defining Px each time, not storing Px outside of the loop.
% After this loop, Px will just be in its 4th state.
for m = 1:length(N)
Px = zeros(NumOfRuns,PerLength);
for i = 1:NumOfRuns
x = randn(1,N(m));
Px(:,i) = periodogram(x);
end
end
<强>周期图:强>
您假设periodogram
返回与输入相同数量的元素。一个简单的测试会告诉你这不是真的!
a = periodogram([1, 2]);
numel(a)
% >> ans = 129
阅读此处的文档:
https://uk.mathworks.com/help/signal/ref/periodogram.html
离散傅里叶变换(DFT)中的点数nfft是最大值256或者下一个2的幂大于信号长度
如上所述,129
与2^7 = 128
尝试使用pxx = periodogram(x,window,nfft)