Home > rest_20090422 > rest_nextpow2_one35.m

rest_nextpow2_one35

PURPOSE ^

Compute the min length for FFT according to AFNI's algorithm, By Xiao-Wei Song

SYNOPSIS ^

function Result = rest_nextpow2_one35(n)

DESCRIPTION ^

Compute the min length for FFT according to AFNI's algorithm, By Xiao-Wei Song
------------------------------------------------------------------------------------------------------------------------------
    Copyright(c) 2007~2010
    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
    Written by Xiao-Wei Song 
    http://resting-fmri.sourceforge.net
     <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
    Version=1.0;
    Release=20070903;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rest_nextpow2_one35.m

SOURCE CODE ^

0001 function Result = rest_nextpow2_one35(n)
0002 %Compute the min length for FFT according to AFNI's algorithm, By Xiao-Wei Song
0003 %------------------------------------------------------------------------------------------------------------------------------
0004 %    Copyright(c) 2007~2010
0005 %    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
0006 %    Written by Xiao-Wei Song
0007 %    http://resting-fmri.sourceforge.net
0008 %     <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
0009 %    Version=1.0;
0010 %    Release=20070903;
0011 
0012     if length(n)>1
0013         n = cast(length(n),class(n));
0014     end
0015     if n<16
0016         Result =2^nextpow2(n);
0017         return;
0018     end 
0019     
0020     limit =nextpow2(n);             %n=134, limit=8
0021     tbl=[2^(limit-1):2^limit];      %tbl =128, 129, ... , 256
0022     tbl =tbl(find(tbl>=n));          %tbl =134, 135, ... , 256
0023     for x=1:length(tbl)
0024         Result =tbl(x);
0025         [f,p]=log2(Result);
0026         if ~isempty(f) & f == 0.5   %Copy from nextpow2.m
0027             return;
0028         end
0029         if mod(Result,3*5)==0        
0030             y= Result /(3*5);
0031             [f,p]=log2(y);
0032             if ~isempty(f) & f == 0.5   %Copy from nextpow2.m
0033                 return;
0034             end
0035         end
0036         if mod(Result,3)==0        
0037             y= Result /3;
0038             [f,p]=log2(y);
0039             if ~isempty(f) & f == 0.5   %Copy from nextpow2.m
0040                 return;
0041             end
0042         end
0043         if mod(Result,5)==0        
0044             y= Result /5;
0045             [f,p]=log2(y);
0046             if ~isempty(f) & f == 0.5   %Copy from nextpow2.m
0047                 return;
0048             end
0049         end
0050     end
0051     Result =NaN;    % Should not reach, except when n=1
0052 
0053 % csfft_nextup35 in AFNI list 1~1024, 20070516, dawnsong
0054 % 2
0055 % 4
0056 % 6
0057 % 8
0058 % 10
0059 % 12
0060 % 16
0061 % 20
0062 % 24
0063 % 30
0064 % 32
0065 % 40
0066 % 48
0067 % 60
0068 % 64
0069 % 80
0070 % 96
0071 % 120
0072 % 128
0073 % 160
0074 % 192
0075 % 240
0076 % 256
0077 % 320
0078 % 384
0079 % 480
0080 % 512
0081 % 640
0082 % 768
0083 % 960
0084 % 1024

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005