📄 spectra.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -