How to use the log-binning of the Fourier energy spectrum?
6 views (last 30 days)
Show older comments
Hi
Do anybody know, How to use the log-binning of the Fourier energy spectrum?
0 Comments
Answers (1)
Thiago Henrique Gomes Lobato
on 15 Mar 2020
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 Comments
Thiago Henrique Gomes Lobato
on 15 Mar 2020
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
on 26 Jun 2020
I get this errorm do you know why
Index exceeds the number of array elements (2190).
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!