[nu amp] = calcnaff(Y, Yp, Win) INPUTS 1. Y - position vector 2. Yp - 3. WindowType - Window type - 0 {Default} no windowing 1 Window of Hann 2 etc 4. nfreq - Maximum number of fundamental frequencies to search for 10 {Default} 5. debug - 1 means debug flag turned on 0 {Default} Optional Flags 'Debug' - turn on deubbing flag 'Display' - print ou results 'Hanning' - select Window of Hann, WindowType = 1 'Raw' or 'NoWindow' - select Window of Hann, WindowType = 0 OUTPUTS 1. frequency - frequency vector with sorted amplitude by default the algorithm try to compute the 10 first fundamental frequencies of the system. 2. amplitude - amplitudes associated with fundamental frequencies 3. phase - phases assocaited with fundamental frequencies NOTES 1. Mimimum number of turn is 64 (66) 2. Number of turn has to be a multiple of 6 for internal optimization reason and just above a power of 2. Example 1026 is divied by 6 and above 1024 = pow2(10) Examples NT = 9996; % divided by 6 simple quasiperiodic (even period) motion y =2+0.1*cos(pi*(0:NT-1))+0.00125*cos(pi/3*(0:NT-1)); yp=2+0.1*sin(pi*(0:NT-1))+0.00125*sin(pi/3*(0:NT-1)); [nu ampl phase] = calcnaff(y,yp,1); % with windowing
0001 function [frequency amplitude phase] = calcnaff(Y, Yp, varargin) 0002 % [nu amp] = calcnaff(Y, Yp, Win) 0003 % 0004 % INPUTS 0005 % 1. Y - position vector 0006 % 2. Yp - 0007 % 3. WindowType - Window type - 0 {Default} no windowing 0008 % 1 Window of Hann 0009 % 2 etc 0010 % 4. nfreq - Maximum number of fundamental frequencies to search for 0011 % 10 {Default} 0012 % 5. debug - 1 means debug flag turned on 0013 % 0 {Default} 0014 % 0015 % Optional Flags 0016 % 'Debug' - turn on deubbing flag 0017 % 'Display' - print ou results 0018 % 'Hanning' - select Window of Hann, WindowType = 1 0019 % 'Raw' or 'NoWindow' - select Window of Hann, WindowType = 0 0020 % 0021 % OUTPUTS 0022 % 1. frequency - frequency vector with sorted amplitude 0023 % by default the algorithm try to compute the 10 first fundamental 0024 % frequencies of the system. 0025 % 2. amplitude - amplitudes associated with fundamental frequencies 0026 % 3. phase - phases assocaited with fundamental frequencies 0027 % 0028 % NOTES 0029 % 1. Mimimum number of turn is 64 (66) 0030 % 2. Number of turn has to be a multiple of 6 for internal optimization 0031 % reason and just above a power of 2. Example 1026 is divied by 6 and 0032 % above 1024 = pow2(10) 0033 % 0034 % Examples 0035 % NT = 9996; % divided by 6 0036 % simple quasiperiodic (even period) motion 0037 % y =2+0.1*cos(pi*(0:NT-1))+0.00125*cos(pi/3*(0:NT-1)); 0038 % yp=2+0.1*sin(pi*(0:NT-1))+0.00125*sin(pi/3*(0:NT-1)); 0039 % 0040 % [nu ampl phase] = calcnaff(y,yp,1); % with windowing 0041 0042 0043 % Written by Laurent S. Nadolski 0044 % April 6th, 2007 0045 0046 DebugFlag = 0; 0047 WindowType = 0; 0048 nfreq = 10; 0049 DisplayFlag = 0; 0050 0051 for ik = length(varargin):-1:1 0052 if strcmpi(varargin{ik},'Debug') 0053 DebugFlag = 1; 0054 varargin(ik) = []; 0055 elseif strcmpi(varargin{ik},'NoDebug') 0056 DebugFlag = 0; 0057 varargin(ik) = []; 0058 elseif strcmpi(varargin{ik},'Display') 0059 DisplayFlag = 1; 0060 varargin(ik) = []; 0061 elseif strcmpi(varargin{ik},'NoDisplay') 0062 DisplayFlag = O; 0063 varargin(ik) = []; 0064 elseif strcmpi(varargin{ik},'Hanning') 0065 WindowType = 1; 0066 varargin(ik) = []; 0067 elseif strcmpi(varargin{ik},'NoWindow') || strcmpi(varargin{ik},'Raw') 0068 WindowType = 1; 0069 varargin(ik) = []; 0070 end 0071 end 0072 0073 if length(varargin) >= 1 0074 WindowType = varargin{1}; 0075 end 0076 0077 if length(varargin) >= 2 0078 nfreq = varargin{2}; 0079 end 0080 0081 if length(varargin) >= 3 0082 DebugFlag = varargin{3}; 0083 end 0084 0085 if length(varargin) >= 4 0086 error('Too many argument'); 0087 end 0088 0089 [frequency amplitude phase] = nafflib(Y, Yp, WindowType,nfreq,DebugFlag); 0090 0091 if DisplayFlag 0092 fprintf('*** Naff run on %s\n', datestr(clock)) 0093 for k = 1:length(frequency) 0094 fprintf('nu(%d) =% .15f amplitude = % .15f phase = % .15f \n', ... 0095 k,frequency(k), amplitude(k),phase(k)); 0096 end 0097 end