spectra.m
来自「matlab算法集 matlab算法集」· M 代码 · 共 34 行
M
34 行
function [a,phi,f] = spectra (x,fs)
%-----------------------------------------------------------------------
% Usage: [a,phi,f] = spectra (x,fs)
%
% Description: Compute the amplitude and phase spectra of a
% discrete-time signal.
%
% Inputs: x = n by 1 vector containing the discrete-time signal
% f = sampling frequency in Hz
%
% Outputs: a = n by 1 vector containing magnitude spectrum of x
% phi = n by 1 vector containing phase spectrum of x in
% degrees
% f = n by 1 vector containing evaluation frequencies
% f(k) = (k-1)*fs/n
%-----------------------------------------------------------------------
chkvec (x,1,'spectra');
y = dft (x,1);
a = abs (y);
n = length(x);
phi = zeros (n,1);
f = (fs/n)*[0 : n-1]';
for i = 1 : n
if a(i) > eps
phi(i) = (180/pi)*atan2(imag(y(i)),real(y(i)));
else
phi(i) = 0;
end
end
%-----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?