📄 log_psd.m
字号:
%file:log_psd.m
% this function takes n time domain samples(real or complex)
% and finds the psd by taking (fft/n)^2
% the two sided spectrum is produced by shifting the psd.
% the array freq provides the appropriate frequency values for plotting purposes
% by taking 10*log10(psd/max(psd)) the psd is normalized
% values below -60dB are set equal to -60dB
%n must be an even number,preferably a power of 2
function [logpsd,freq,ptotal,pmax]=log_psd(x,n,ts)
% n=1024;
y=zeros(1,n); %initialize y vector
h=waitbar(0,'for loop in psd calculation');
for k=1:n
freq(k)=(k-1-(n/2))/(n*ts);
y(k)=x(k)*((-1.0)^k);
waitbar(k/n)
end;
v=fft(y)/n;
psd=abs(v).^2;
pmax=max(psd);
ptotal=sum(psd);
logpsd=10*log10(psd/pmax);
%truncate negative values at -60dB
for k=1:n
if(logpsd(k)<-60.0)
logpsd(k)=-60.0;
end
end
close(h)
%end of function file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -