How to use the log-binning of the Fourier energy spectrum?

12 ビュー (過去 30 日間)
Ali Nouri
Ali Nouri 2020 年 3 月 15 日
コメント済み: Ali nouri 2020 年 6 月 26 日
Hi
Do anybody know, How to use the log-binning of the Fourier energy spectrum?

回答 (1 件)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 3 月 15 日
I'm not entirely sure what you mean by log-binning, but a regular interpretation for it is just to resample the fft in log-spaced bins instead of linear ones. A way to do it is to generate your log-frequency bins and then map all linear values to it's respective bins in the log scale. Something like this can do the trick, although it is not 100% optimized:
Fs = 8000;
t = 0:1/Fs:0.2;
a = sin(2*pi*1000*t)+randn(1,length(t));
A = fft(a);
A = A.*conj(A);
% Freq vectors
LinearFreq = linspace(0,Fs,length(A));
SizeLogFreq= round(length(A)/4); % Can be, theoretically, any integer
LogFreq = logspace(1,log10(Fs),SizeLogFreq);
% Mapping
Alog = zeros(1,SizeLogFreq);
for idx=1:length(A)
[~,idxLog]= min(abs(LinearFreq(idx)-LogFreq));
Alog(idxLog) = Alog(idxLog)+A(idx);
end
figure,
plot(LinearFreq,A)
hold on
plot(LogFreq,Alog)
  3 件のコメント
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 3 月 15 日
N = length(Del_mat); % Del_mat is matrix of 8760X30
fs = 1;
figure(1)
s=5;
for i=1:30
y(:,i)=Del_mat(:,i);
y1(:,i) = fft(y(:,i));
power(:,i)= abs(y1(:,i)).^2/N; % power of the DFT
X_mags(:,i)=power(:,i);
X_mags(:,i)=smooth(X_mags(:,i),s);
end
bin_vals = [0 : N-1];
fax_Hz = bin_vals*fs/N;
SizeLogFreq= round(N/4); % Can be, theoretically, any integer
LogFreq = logspace(1,log10(fs),SizeLogFreq);
% Mapping
Alog = zeros(SizeLogFreq,size(Del_mat,2));
for idx=1:N
[~,idxLog]= min(abs(fax_Hz(idx)-LogFreq));
Alog(idxLog,:) = Alog(idxLog,:)+X_mags(idx,:);
end
N_2 = ceil(N/2);
for j=1:7
loglog(fax_Hz(1:N_2),X_mags((1:N_2),j))
hold on
loglog(LogFreq(1:N_2),Alog((1:N_2),j)) % May need to go beyong N/2
end
Ali nouri
Ali nouri 2020 年 6 月 26 日
I get this errorm do you know why
Index exceeds the number of array elements (2190).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by