通常我使用pmtm来计算信号的频谱:
signal = rand(1000,1);
NW = 4;
Fr = 1:50;
Fs = 200;
[p, fr] = pmtm( signal, NW, Fr, Fs);
然而,我正在寻找一种矢量化方法,以便我可以同时计算多个光谱。我试过了:
signal = rand(1000,10); %<--- notice I have 10 columns instead of 1
NW = 4;
Fr = 1:50;
Fs = 200;
[p, fr] = pmtm( signal, NW, Fr, Fs);
但它产生的错误并没有真正告诉我我做错了什么。我知道我可以在循环中将调用包装到pmtm
。
这是错误:
使用时出错。*矩阵尺寸必须一致。
pmtm中的错误&gt; mtm_spectrum(第231行) [Xx,w] = computeDFT(E(:,1:k)。* x(:,(1,k)),nfft,Fs);
pmtm出错(第142行)[S,k,w] = mtm_spectrum(x,params);
这让我怀疑没有一种矢量化的方式来实现我想要的东西。我希望这里的某个人知道如何做到这一点。
答案 0 :(得分:0)
是什么让你认为pmtm旨在处理矩阵?帮助菜单特别需要一个向量:
>> help pmtm
pmtm Power Spectral Density (PSD) estimate via the Thomson multitaper
method (MTM).
Pxx = pmtm(X) returns the PSD of a discrete-time signal vector X in
the vector Pxx. Pxx is the distribution of power per unit frequency.
The frequency is expressed in units of radians/sample. pmtm uses a
default FFT length equal to the greater of 256 and the next power of
2 greater than the length of X. The FFT length determines the length
of Pxx.
...
如果您在演奏后,您可能希望以2D fft(fft2)获得信号的频谱表示,然后自行计算功率分布。这将允许您在没有任何for循环的情况下处理2D数组,但这将意味着更多编码为您确保: - (