Skip to content

Commit

Permalink
fft (FFT), fftn (n-dimensional FFT), fftshift
Browse files Browse the repository at this point in the history
Including Octave compatibility for fftn whtn the second input contains
zeros
  • Loading branch information
lmendo committed Oct 15, 2017
1 parent b4b7e75 commit dbb4bdc
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 8 deletions.
10 changes: 10 additions & 0 deletions compatibility/fftn_comp.m
@@ -0,0 +1,10 @@
function y = fftn(varargin)
% For two inputs, if second input has a zero it gives an empty result with the
% size specified by the second input, like Matlab does, instead of giving
% an error
if nargin==2 && any(varargin{2}==0)
y = ones(varargin{2});
else
y = builtin('fftn', varargin{:});
end
end
Binary file modified funDef.mat
Binary file not shown.
18 changes: 16 additions & 2 deletions funDef.txt
Expand Up @@ -738,7 +738,14 @@ YF 1 1 1 1 2 1 2 true true true true trim = (any(in{1}<0) && (nout==1)) || (~an
end
if trim, out = cellfun(@(c) c(:, any(y>0, 1)), out, 'UniformOutput', false); end
clear f p y k trim
ZF
ZF 1 3 1 2 1 1 1 true true true true if numel(in)<=2 N-dimensional discrete Fourier transform (FFT) (i) With $1$ or $2$ inputs: \matlab+nfft+. If first input is a vector and second input is a scalar, a $1$ is prepended or appended to the second input according to the vector orientation (so the result is the same as that of \matlab+fft+). (ii) With $3$ inputs: \matlab+fft+
if numel(in)==2 && isvector(in{1}) && isscalar(in{2}), if size(in{1},1)==1, in{2} = [1 in{2}]; else in{2} = [in{2} 1]; end, end
out{1} = fftn(in{:});
elseif numel(in)==3
out{1} = fft(in{:});
else
error('MATL:runtime', 'MATL run-time error: incorrect number of inputs')
end
G 0 1 double(numel(CB_G)>1) 0 0 inf 1+(max(numel(CB_G),1)-1)*(numel(in)==0) true true false true if numel(CB_G)==0 paste from user-input clipboard G paste from user-input clipboard G. If $0$ input arguments: addresses all levels. If $1$ input argument: addresses specified level. In either of those cases, if clipboard G has no levels one user-input is implicitly taken to fill the first level
implInput = input(implicitInputPrompt,'s');
valid = isempty(regexp(implInput, '^[^'']*(''[^'']*''[^'']*)*[a-df-hk-zA-EG-MOQ-SU-XZ]', 'once')) && isempty(regexp(implInput, '^[^'']*(''[^'']*''[^'']*)*[a-zA-Z]{2}', 'once'));
Expand Down Expand Up @@ -963,7 +970,14 @@ YS 2 3 2 3 1 1 1 true true true true if numel(in)==3 && numel(in{2})>1 && ndims
end
out{1} = y; clear d y
end
ZS 1 1 1 1 1 1 true true true true out{1} = sign(in{:}); sign function \matlab+sign+
ZS 1 2 1 2 1 1 1 true true true true if numel(in)==1 sign function / FFT shift (i) With $1$ input: \matlab+sign+. (ii) With $2$ inputs: \matlab+fftshift+. Second input equal to $0$ corresponds to \matlab+fftshift+ with $1$ input
out{1} = sign(in{:});
elseif numel(in)==2
if in{2}==0, in(2) = []; end
out{1} = fftshift(in{:});
else
error('MATL:runtime', 'MATL run-time error: incorrect number of inputs')
end
T
XT
YT 1 2 1 2 1 1 1 true true true true c = any(cellfun(@ischar, in)); Toeplitz matrix \matlab+toeplitz+. Output is char if any input is
Expand Down
Binary file modified help.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion matl_compile.m
Expand Up @@ -361,7 +361,7 @@
'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean' 'diff' 'mod' 'repelem' 'dec2bin' 'dec2base' ...
'hypergeom' 'disp' 'str2func' 'logical' 'circshift' 'pdist2' 'strsplit' 'max' 'min' 'strncmp' 'round'...
'datestr' 'regexp' 'regexprep' 'imshow' 'mat2str' 'blkdiag' 'strcat' 'str2num' 'str2double' 'cconv' ...
'gcd' 'lcm'};
'gcd' 'lcm' 'fftn'};
verNumTh = [4 0 0]; % first version in which a modified function is not needed:
if (verNum(1)<verNumTh(1)) || ((verNum(1)==verNumTh(1)) && (verNum(2)<verNumTh(2))) || ((verNum(1)==verNumTh(1)) && (verNum(2)==verNumTh(2)) && (verNum(3)<verNumTh(3)))
fnames = [fnames {'colon'}];
Expand Down
Binary file modified spec/MATL_spec.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion spec/funDefTable/funDefTable.tex
Expand Up @@ -100,6 +100,7 @@
\matl{E} & 1 & 1 & \matlab|(...)*2| \\
\matl{XE} & 3 & 1 & With numeric or char inputs, replace in first input all occurrences of each element of the second input by the corresponding element of the third input. The third input may be longer than the second, and then the extra elements are ignored. Or it may have a single element, and then it is implicitly replicated. Output has the same class and size as the first input. If the three inputs are cell arrays of strings (the second may also be a string instead of a cell array of strings), each string of the first input is considered atomic, that is, replacing is based on whole strings. If the first input is a cell array and the others are numeric or char, replacing is done on each cell's contents as if the cell's contents were the first input \\
\matl{YF} & 1 & 1--2 (1 / 2) & (i) With $1$ output: exponents of prime factor decomposition, without skipping primes. If the input is a numeric array it is linearized, and each result is in an output row. If any entry in the input is negative, the absolute value is taken, and the output contains only non-zero exponents. (ii) With $2$ outputs: first output gives the prime factors, second gives the exponents. Primes that are not factors are skipped, as are their zero exponents. If any entry in the input is negative, the absolute value is taken, and all intermediate primes are included, possibly with zero exponents. \sa \matl{Yf} \\
\matl{ZF} & 1--3 (1 / 2) & 1 & (i) With $1$ or $2$ inputs: \matlab+nfft+. If first input is a vector and second input is a scalar, a $1$ is prepended or appended to the second input according to the vector orientation (so the result is the same as that of \matlab+fft+). (ii) With $3$ inputs: \matlab+fft+ \\
\matl{G} & 0--1 ($^\sqcup$ / 0) & 0-- ($^\sqcap$) & paste from user-input clipboard G. If $0$ input arguments: addresses all levels. If $1$ input argument: addresses specified level. In either of those cases, if clipboard G has no levels one user-input is implicitly taken to fill the first level \\
\matl{XG} & 1-- (1 / 2) & 0 & \matlab+plot+. Calls \matlab+drawnow+ to update figure immediately. With one input, or with several inputs the second of which is a string: if the first input is complex (even with zero imaginary part), \matlab+axis equal+ is also called. \\
\matl{YG} & 2-- (2 / 3) & 0 & \matlab+imwrite+, \matlab+imagesc+, \matlab+image+ or \matlab+imshow+. (i) If last input is a scalar: \matlab+0+ corresponds to \matlab+imwrite+, \matlab+1+ to \matlab+imagesc+, \matlab+2+ to \matlab+image+ and \matlab+3+ to \matlab+imshow+. The corresponding function is called with the remaining inputs. (ii) If last input is numeric or logical and not a scalar: \matlab+imshow+ is called with all inputs. (iii) If last input is char: \matlab+imwrite+ is called with all inputs. (i, iii) For \matlab+imwrite+, the first input of type char is interpreted as file name. If it has no extension '.png' is added; if it's empty it is replaced by 'image.png'; and if non existent 'image.png' is used as final input. (i, ii, iii) For \matl{imshow} and \matl{imwrite}, if the second input is logical it is converted to \matlab+double+. If it is numeric, has the shape of a colormap, and has some entry greater than $1$, it is normalized by converting to \matlab+uint8+, then to \matlab+double+, and then dividing by $255$. For \matlab+imagesc+ and \matlab+image+, the function call is followed by \matlab+axis ij, axis image+. For \matlab+imagesc+, \matlab+image+ and \matlab+imshow+, \matlab+drawnow+ is called to update figure immediately \\
Expand Down Expand Up @@ -142,7 +143,7 @@
\matl{S} & 1--3 (1) & 1--2 (1 / 2nd) & sort an array (\matlab+sort+) / sort an array based on another. (i) Single-array mode works like Matlab's \matlab+sort+. If $2$ inputs, a negative value of the second input corresponds to descending order. If first input is a cell array and the first cell contains a char array, the rest of the cells' contents are converted to char. (ii) If the first input is a cell array and the first cell contains a numeric array, single-array numeric mode is used. The first input is linearized if it's not a vector, and its contents are linearized for the purposes of sorting. The first input is then sorted in lexicographic order, ignoring other inputs. (iii) In two-array mode, this function takes as first $2$ inputs an array and a vector array which is not char. If the first array is not a vector it is linearized. The second vector is sorted and its order is applied to the first. An optional third input specifies direction as a string, or as a negative number in the non-singleton dimension of the second vector. The outputs are the two sorted arrays. (In two-array mode, if the two input arrays are scalar the result is the same as if the second input is interpreted as dimension, corresponding to single array mode). \sa \matl{XS} \\
\matl{XS} & 1--2 (1) & 1--2 (1 / 2nd) & \matlab+sortrows+. \sa \matl{S} \\
\matl{YS} & 2--3 (2 / 3) & 1 & \matlab+circshift+. If second input is a scalar and there's no third input, the shift is applied along the first non-singleton dimension. This function also allows first input a 2D array; third input a scalar specifying dimension; and second input a vector or array specifying the shift for each position in the other dimension \\
\matl{ZS} & 1 & 1 & \matlab+sign+ \\
\matl{ZS} & 1--2 (1 / 2) & 1 & (i) With $1$ input: \matlab+sign+. (ii) With $2$ inputs: \matlab+fftshift+. Second input equal to $0$ corresponds to \matlab+fftshift+ with $1$ input \\
\matl{YT} & 1--2 (1 / 2) & 1 & \matlab+toeplitz+. Output is char if any input is \\
\matl{U} & 1 & 1--2 (1) & (i) For char input: \matlab+str2num+ with content checking. Most characters below 32 are replaced by space (as in \matl{D}). The input content is then checked. If it fails, \matlab+[]+ is returned. Else \matlab+str2num+ is applied. If that fails, the input string is evaluated. If that also fails, \matlab+[]+ is returned. The second output is supported in all cases. (ii) For numeric input: \matlab+(...).^2+ \\
\matl{XU} & 1 & 1 & \matlab+str2double+ \\
Expand Down
Binary file modified spec/functionTable/MATL.xlsx
Binary file not shown.
10 changes: 6 additions & 4 deletions spec/functionTable/function_table.eps

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified spec/functionTable/function_table.pdf
Binary file not shown.
Binary file added spec/functionTable/tmp.ps
Binary file not shown.

0 comments on commit dbb4bdc

Please sign in to comment.