⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 freqrsp.m

📁 matlab算法集 matlab算法集
💻 M
字号:
function [a,phi,f] = freqrsp (u,y,fs)
%-----------------------------------------------------------------------
% Usage:       [a,phi,f] = freqrsp (u,y,fs)
%
% Description: Compute the frequency response of a discrete-time
%              system from its input and output.
%
% Inputs:      u  = n by 1 vector containing the input signal
%              y  = n by 1 vector containing the output signal
%              fs = sampling frequency in Hz
%
% Outputs:     a   = n by 1 vector containing magnitude response
%              phi = n by 1 vector containing phase response
%                    in degrees. 
%              f   = n by 1 vector containing the evaluation
%                    frequencies: f(k) = (k-1)*fs/n 
%-----------------------------------------------------------------------
   
% Initialize

   chkvec (u,1,'freqrsp');
   chkvec (y,2,'freqrsp');
   n = length(u);
   if length(y) ~= n
      disp ('The inputs to freqrsp must be of the same length.')
      return
   end  
   c = zeros (n,1);
   d = zeros (n,1);

% Compute magnitude and phase 

   [c,d,f]   = spectra (u,fs);
   [a,phi,f] = spectra (y,fs);
   for i = 1 : n
      a(i) = a(i)/max([c(i),eps]);
      phi(i) = phi(i) - d(i);
      while phi(i) < -180
         phi(i) = phi(i) + 360;
      end
      while phi[i] > 180 
         phi(i) = phi(i) - 360;
      end
   end
%-----------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -