In Matlab we can write,
[u, v] = freqspace(size(I),'meshgrid');
What is Octave's equivalent of "freqspace" function of Matlab?
As you have found out, freqspace
is not implemented in Octave:
>> help freqspace
error: help: the 'freqspace' function is not yet implemented in Octave
Please read <http://www.octave.org/missing.html> to learn how you can
contribute missing functionality.
Looking at the documentation page for the MATLAB function, you get:
Syntax
[f1,f2] = freqspace(n) [f1,f2] = freqspace([mn]) [x1,y1] = freqspace(...,'meshgrid') f = freqspace(N) f = freqspace(N,'whole')
Description
freqspace
returns the implied frequency range for equally spaced frequency responses. freqspace is useful when creating desired frequency responses for various one- and two-dimensional applications.
[f1,f2] = freqspace(n)
returns the two-dimensional frequency vectorsf1
andf2
for an n-by-n matrix.For
n
odd, bothf1
andf2
are[-n+1:2:n-1]/n
.For
n
even, bothf1
andf2
are[-n:2:n-2]/n
.
[f1,f2] = freqspace([mn])
returns the two-dimensional frequency vectorsf1
andf2
for anm
-by-n
matrix.
[x1,y1] = freqspace(...,'meshgrid')
is equivalent to[f1,f2] = freqspace(...); [x1,y1] = meshgrid(f1,f2);
f = freqspace(N)
returns the one-dimensional frequency vectorf
assumingN
evenly spaced points around the unit circle. ForN
even or odd,f
is(0:2/N:1)
. ForN
even, freqspace therefore returns(N+2)/2
points. ForN
odd, it returns(N+1)/2
points.
f = freqspace(N,'whole')
returnsN
evenly spaced points around the whole unit circle. In this case,f
is0:2/N:2*(N-1)/N
.
Based on this, I put together the following function. It was done very quickly though and doesn't cover all the cases, but the cases implemented appear to work fine in Octave. Hopefully this should give you an idea to get started:
function varargout = freqspace(varargin)
if nargin==1 && nargout==2 % [f1,f2] = freqspace(n)
n = varargin{1};
if mod(n,2)==0 % n is even
varargout{1} = [-n:2:n-2]/n;
varargout{2} = [-n:2:n-2]/n;
else % n is odd
varargout{1} = [-n+1:2:n-1]/n;
varargout{2} = [-n+1:2:n-1]/n;
end
elseif nargin==1 && nargout==1 % f = freqspace(N)
N = varargin{1};
varargout{1} = (0:2/N:1);
elseif nargin==2 && nargout==1 % f = freqspace(N,'whole')
N = varargin{1};
if ~ischar(varargin{2}) || ~strcmpi(varargin{2},'whole')
error('The correct syntax is f = freqspace(N,''whole'')');
else
varargout{1} = 0:2/N:2*(N-1)/N;
end
else
disp('Case not yet implemented.')
return
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.