log_psd.m
来自「很多MATLAB的无线系统仿真实例。强烈推荐!」· M 代码 · 共 40 行
M
40 行
function [logpsd,freq,ptotal,pmax] = log_psd(x,n,ts)
% Software given here is to accompany the textbook: W.H. Tranter,
% K.S. Shanmugan, T.S. Rappaport, and K.S. Kosbar, Principles of
% Communication Systems Simulation with Wireless Applications,
% Prentice Hall PTR, 2004.
%
% This function takes the 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 beow 60db
% are set equal to -60db
%
% n must be an even number, preferably a power of 2
%
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 -60 dB
%
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 + =
减小字号Ctrl + -
显示快捷键?