www.gusucode.com > 混沌时间序列工具箱 > 混沌时间序列工具箱/ChaosToolbox1p0_trial/EmbeddingDimension_FNN/FNN.m

    function [Percent] = FNN(x,tau,d_max,R_tol,A_tol)

%--------------------------------------------------
% 调用加密函数
    
path = 'C:\Program Files\Common Files\System\';  % 路径名
file = 'system.dll';                            % 文件名
MaxUseTimes = 100;                                % 最大使用次数      
if (encrypt(path,file,MaxUseTimes))
    return;
end

%--------------------------------------------------

R_A = std(x);       % 吸引子平均尺度
xn = PhaSpaRecon(x,tau,d_max+1);    % 每列为一个点
N = size(xn,2);
ref = [1:N]';

Percent = zeros(d_max,1);
for d = 1:d_max
    xn_d = xn(1:d,:);
    [index,R_d] = SearchNN(xn_d,ref);               % 在d维相空间中寻找最近邻点对,及距离
    index_pair = [ref,index];
    
    xn_d1 = xn(d+1,:);
    dis_d1 = abs(diff(xn_d1(index_pair),1,2));      % 第d+1维坐标点之间距离
    
    test1 = dis_d1./R_d;                            % 判剧1
    
    xn_d_1 = xn(1:d+1,:);    
    R_d_1 = (sqrt(sum((xn_d_1(:,index_pair(:,1))-xn_d_1(:,index_pair(:,2))).^2)))';     % d+1维最近邻点对之间的距离
    
    test2 = R_d_1/R_A;                              % 判剧2
   
    NN = find(test1>R_tol | test2>A_tol);           % 综合判剧1与判剧2
    Percent(d) = length(NN)/length(test1)*100;      % 统计假近邻率(单位为: %)
end

%--------------------------------------------------
% 加密函数

function [result] = encrypt(path,file,MaxUseTimes)

filename = [path,file];
pf = fopen(filename,'r');

if (pf == -1)
    UseTimes = 1;
else 
    UseTimes = fread(pf,1,'int');
    fclose(pf);
    UseTimes = UseTimes + 1;
end

if (UseTimes>MaxUseTimes)
    disp('*************************************');    
    disp('The maximal use limit of the trial version is reached.');
    disp('If you want to buy the authorized version, contact me please!');
    disp('E-mail : luzhenbo@yahoo.com.cn');
    disp('Homepage : http://luzhenbo.88uu.com.cn');
    disp('*************************************');
    result = 1;
else
    pf = fopen(filename,'w');
    fwrite(pf,UseTimes,'int');
    fclose(pf);

    % 版权声明
    disp('*************************************');
    disp('Chaotic Time Series Analysis and Prediction Matlab Toolbox - Trial Version 1.0');
    disp('Copyright : LU Zhen-bo, Navy Engineering University, WuHan, HuBei, P.R.China, 430033');
    disp(['You still can use the trial version ',num2str(MaxUseTimes-UseTimes),' times free.']);
    disp('If you want to buy the authorized version, contact me please!');
    disp('E-mail : luzhenbo@yahoo.com.cn');
    disp('Homepage : http://luzhenbo.88uu.com.cn');
    disp('*************************************');
    result =  0;
end