2013-03-03 49 views
0

通常我計算用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

以下是錯誤:

Error using .* Matrix dimensions must agree.

Error in pmtm>mtm_spectrum (line 231) [Xx,w] = computeDFT(E(:,1:k).*x(:,ones(1,k)),nfft,Fs);

Error in pmtm (line 142) [S,k,w] = mtm_spectrum(x,params);

這使我懷疑,沒有一個量化的方式來達到我想要的。我希望在這裏有人會知道如何做到這一點。

+0

'mtm_spectrum'強制'x'作爲x = x(:)行中的向量。 '如果'x'是矩陣,它會有n_col更大的維數,這就是爲什麼你會得到矩陣維數的錯誤。你嘗試過arrayfun嗎?它是僞向量化的解決方案,但可能會加快執行時間, arrayfun(@(x)pmtm(signal(:,x),NW,Fr,Fs),1:size(signal,2))',但你只能得到一個輸出變量 – yuk 2013-03-03 23:27:58

+0

看起來像'E ''和'x'的尺寸不完全相同...... – 2013-03-04 00:04:44

+1

您可能無法避免在這裏使用for循環,這是非常昂貴的,因爲pmtm很慢如果性能是您的擔心,那麼您可以通過用'dpss'預先計算睡眠序列並將它們傳遞給'pmtm'。 – 2016-09-17 13:30:01

回答

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循環的情況下處理二維數組,但是這將意味着更多的代碼爲你確保:-(