what is the dist function's mean? [message #43549] |
Fri, 22 April 2005 10:31  |
lixiaoyao
Messages: 49 Registered: April 2005
|
Member |
|
|
Is there anybody who can explain the dist for me?
I know dist(100) generate a 100X100 matrix,but what is the value for
it
come from? In the help file,they said it is the frequency,but I do not
understand.
also,what is the purpose for this function?
Thanks a lot
|
|
|
Re: what is the dist function's mean? [message #43708 is a reply to message #43549] |
Sat, 23 April 2005 11:55   |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
lixiaoyao wrote:
> yes,this is what I wanted,thank you! I am in the process to study IDL,I
> want to be an expert in IDL. I have order David Fanning's book,but it
> still does not reach! Thank you for youe help!
> except the book,any suggestions about the how to study IDL?
www.dfanning.com
Look at the "tips and tricks" page. Download his full program library.
Skim through it, plus the "tips" page, every once in a while. As you
learn IDL, each time you'll understand more and find another useful
helper program. Other IDL websites with tips and more program libraries
are linked from David's.
Go to the help directory of your IDL installation, open each of the PDF
files and skim the table of contents. And remember, the first place to
look at is the help index. Type in a few keywords which are related to
your problem.
If you ask questions on this newsgroup, people are happy to help if they
see you showed some effort to read the available documentation and if
the problem is described well. Remember, they all do it voluntarily in
their free time!
Benjamin
|
|
|
|
Re: what is the dist function's mean? [message #43710 is a reply to message #43549] |
Sat, 23 April 2005 10:16   |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
lixiaoyao wrote:
> I still a little bit confusing about the use of it.I will read the
> manual again.thank you.
>
Chapter 21, "Signal Processing", in the "Using IDL" manual is quite
helpful. It sais that if you use the FFT() function on some sampled
data, the actual frequency associated with a frequency index m is
f(m) = m / (N delta)
where N is the number of data points (in that dimension) and delta is
the sampling interval. The online help to FFT() explains which array
index corresponds to which frequency index:
0, 1, 2, ..., N/2-1, N/2, -(N/2-1), ..., -1
if you have an even number of data points. So, if you do a 2-dimensional
F.T. (say, of an N x N array), DIST() will give you the frequency
indices. Then you can create an array with spatial frequencies by
freq = dist(N, N) / (N * delta)
where delta is your real space sampling interval.
If this is what you have to work on, you should fully understand
discrete Fourier transforms before you try to do calculations in IDL. I
can recommend the book "The Fast Fourier Transform" by E. Oran Brigham.
Benjamin
|
|
|
|
|
|
|
|
|
Re: what is the dist function's mean? [message #43744 is a reply to message #43549] |
Fri, 22 April 2005 12:36   |
Dick Jackson
Messages: 347 Registered: August 1998
|
Senior Member |
|
|
You know, I never quite understood that explanation from the manual either
(does it really make sense to anyone?), so I think of it this way:
In the array resulting from Dist(), each element is the straight-line
"distance" from either element [0, 0] or the element just *beyond* each
other corner, whichever is closest.
In these examples I add "*******" for the other hypothetical corner
elements:
IDL> print,dist(4)
0.000000 1.00000 2.00000 1.00000 *******
1.00000 1.41421 2.23607 1.41421
2.00000 2.23607 2.82843 2.23607
1.00000 1.41421 2.23607 1.41421
******* *******
IDL> print,dist(5)
0.000000 1.00000 2.00000 2.00000 1.00000 *******
1.00000 1.41421 2.23607 2.23607 1.41421
2.00000 2.23607 2.82843 2.82843 2.23607
2.00000 2.23607 2.82843 2.82843 2.23607
1.00000 1.41421 2.23607 2.23607 1.41421
******* *******
What's nice is that you can roll the rows and columns around and get a nice
array with distances from the centre point:
IDL> print,Shift(dist(5),2,2)
2.82843 2.23607 2.00000 2.23607 2.82843
2.23607 1.41421 1.00000 1.41421 2.23607
2.00000 1.00000 0.000000 1.00000 2.00000
2.23607 1.41421 1.00000 1.41421 2.23607
2.82843 2.23607 2.00000 2.23607 2.82843
Peace,
--
-Dick
Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
"Haje Korth" <haje.korth@jhuapl.edu> wrote in message
news:d4bgld$il0$1@aplcore.jhuapl.edu...
> Maybe we should start copying from the manual. So here we go:
>
> The DIST function creates an array in which each array element value is
> proportional to its frequency. This array may be used for a variety of
> purposes, including frequency-domain filtering.
>
> This routine is written in the IDL language. Its source code can be found
> in the file dist.pro in the lib subdirectory of the IDL distribution.
>
> (I would post the code too, but it is copyrighted, so you will have to
> look at RSI\IDLxx\lib\dist.pro yourself. Sorry for the inconvenience)
>
> H.
>
>
> "lixiaoyao" <lixiaoyao5880@yahoo.com> wrote in message
> news:1114191092.478578.9120@g14g2000cwa.googlegroups.com...
>> Is there anybody who can explain the dist for me?
>> I know dist(100) generate a 100X100 matrix,but what is the value for
>> it
>> come from? In the help file,they said it is the frequency,but I do not
>> understand.
>> also,what is the purpose for this function?
>> Thanks a lot
>>
>
>
|
|
|
|
|
Re: what is the dist function's mean? [message #44133 is a reply to message #43710] |
Wed, 18 May 2005 11:57  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
Benjamin Hornberger wrote:
>
> if you do a 2-dimensional
> F.T. (say, of an N x N array), DIST() will give you the frequency
> indices. Then you can create an array with spatial frequencies by
>
> freq = dist(N, N) / (N * delta)
>
> where delta is your real space sampling interval.
>
As a side note, I realized now that the IDL-provided DIST function has a
limitation in that it can't handle cases which are not symmetric in X
and Y. Even though you can specify N and M separately, if you want to
create an array of frequencies by scaling DIST's result by a factor, you
can't do it unless the real-space field of view is a square. In other
words, N * dx = M * dy is required (dx, dy are the real-space sampling
intervals).
I wrote a replacement which can do this. It can also return the
frequencies (rather than frequency indices) directly if you pass
sampling intervals or the Nyquist frequency in X and Y. In case
somebody's interested ...
Benjamin
;+
; NAME:
;
; BH_DIST
;
;
; PURPOSE:
;
; This function is a more versatile replacement for the
; IDL-provided DIST() function. If a real-space sampling interval
; or a maximum (Nyquist) frequency is given, it can calculate the
; frequency array directly. The number of pixels and the sampling
; intervals can be different in the x and y directions.
;
; Note: If you only specify nx, and possibly ny, this function
; does exactly the same as the IDL-provided DIST() function.
;
;
; AUTHOR:
;
; Benjamin Hornberger
; benjamin.hornberger@stonybrook.edu
;
;
; CATEGORY:
;
; General programming, frequency analysis
;
;
; CALLING SEQUENCE:
;
; Result = BH_DIST(nx, ny, dx, dy)
;
;
; RETURN VALUE:
;
; Returns a rectangular array in which the value of each element is
; equal to its frequency index. If dx, and optionally dy, are
; passed, the array will contain frequencies rather than frequency
; indices.
;
;
; INPUT PARAMETERS:
;
; nx: Number of pixels in the X direction.
;
;
; OPTIONAL INPUT PARAMETERS:
;
; ny: Number of pixels in the Y direction. If not passed, it will
; be set equal to nx.
;
; dx: Real-space sampling interval in the X direction. If this
; parameter is passed, the function will return an array of
; frequencies rather than frequency indices. If additionally the
; keyword FMAX is set, dx is interpreted as maximum frequency in
; the X direction (Nyquist frequency).
;
; dy: Real-space sampling interval in the Y direction. If dy is not
; passed, but dx is, it is assumed to be equal to dx. If
; additionally the keyword FMAX is set, dy is interpreted as
; maximum frequency in the Y direction (Nyquist frequency).
;
;
; INPUT KEYWORDS:
;
; CENTER: If this keyword is set, the result will be shifted so
; that the zero frequency is at nx/2, ny/2 (which means right in
; the center for odd numbers of pixels).
;
; FMAX: If this keyword is set, dx and dy are interpreted as
; maximum (Nyquist) frequencies in the X or Y direction, rather
; than real space sampling intervals. This keyword has no effect
; if neither dx nor dy are given.
;
;
; OUTPUTS KEYWORDS:
;
; FX, FY: Set these keywords to named variables which will contain
; one-dimensional arrays of frequencies in the X and Y
; directions.
;
;
; EXAMPLE:
;
; To calculate a 100 x 120 array of spatial frequencies, with
; real-space sampling intervals of 1.2 and 1.4 (arbitrary units --
; the units for the frequencies will just be the inverse):
;
; Freq = BH_DIST(100, 120, 1.2, 1.4)
;
;
; MODIFICATION HISTORY:
; Written: BH 2005-05-16
;-
FUNCTION bh_dist, nx, ny, dx, dy, $
fx=fx, fy=fy, $
fmax=fmax, $
center=center
compile_opt idl2
on_error, 2
IF n_elements(nx) EQ 0 THEN message, 'must specify at least nx'
IF n_elements(ny) EQ 0 THEN ny = nx
nx1 = long(nx)
ny1 = long(ny)
;; shift parameters
sx = keyword_set(center) ? 0 : -nx1/2
sy = keyword_set(center) ? 0 : -ny1/2
;; 1d frequency arrays
fx = shift(findgen(nx1)-nx1/2, sx)
fy = shift(findgen(ny1)-ny1/2, sy)
;; If sampling intervals are passed, we calculate frequencies rather
;; than frequency indices. If only dx has been passed, dy is assumed
;; to be the same. If the keyword FMAX is set, we take dx and dy as
;; maximum (Nyquist) frequencies.
IF n_elements(dx) GT 0 THEN BEGIN
IF n_elements(dy) EQ 0 THEN dy = dx
fx *= (keyword_set(fmax) ? (1.*dx/(nx/2)) : (1./(nx1*dx)))
fy *= (keyword_set(fmax) ? (1.*dy/(ny/2)) : (1./(ny1*dy)))
ENDIF
;; 2d frequency arrays
fx2d = rebin(fx, nx1, ny1)
fy2d = rebin(reform(fy, 1, ny1), nx1, ny1)
return, sqrt(fx2d^2.+fy2d^2.)
END
|
|
|