?? 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 + -