home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff364.lzh / DPFFT / readme < prev    next >
Text File  |  1990-08-12  |  16KB  |  374 lines

  1.  
  2. This code is an extension of the program on FISH-disk 322(?) and is
  3. considered as freeware in the usual sense.
  4. The following has been added:
  5.  
  6.     -A serial correlation
  7.     -An EWK (=Einstein-Wiener-Khinchine) transform
  8.     -Normalised-linear and log-log spectra
  9.     -A 3-D display of various FFT-spectra
  10.  
  11. The 3-D display is on the basis of FFT. The EWK-transform is too slow.
  12. The main reason for the use of the latter is the window-closing principle
  13. described in Ch.7 of G.M.Jenkins and D.G.Watts, Spectral Analysis,
  14. Holden-Day, 1968. For more information, see below.
  15.  
  16. Any suggestions or information about scientific software on the Amiga
  17. is appreciated. I am particularly interested in a comfortable and
  18. interactive display of theoretical concepts and of experimental data.
  19. This program is used by me as a tool for a characterisation of animated
  20. sequences by means of topological invariants.
  21.  
  22.             A.A.Walma
  23.             Ziegelmattenstrasse 5
  24.             7800 FREIBURG
  25.             W-Germany
  26.  
  27.     --------------------------------------------------------------------
  28.  
  29.                                DPFFT 2.2
  30.  
  31.                           (c) 1990 Alle Anne Walma
  32.  
  33.  
  34. 1.DATA-DISPLAY
  35.   -----------
  36.  
  37.     The program is started either from CLI by invoking "DPFFT <cr>"
  38. or from the Workbench, where the icons are selfexplanatory. Double
  39. klicking in the main window allows you to change the screen to PAL height.
  40.  
  41.     DPFFT works within an integer-range of 0-10000. This
  42. suffices for the usual 8-Bit and 12-Bit AD converters.
  43. Negative binary values are accepted (sound-file for instance) and shown
  44. in a different color in the plotwindow (vertical scale).
  45. Two examples of experimental data are included:
  46.  
  47.     - eeg    = A sample of a 12-Bit brainwave digitalisation (1500
  48.                    data at a sampling rate of 250 Hz)
  49.     - sinus  = A sinusoid with 10 periods and 100 samples per period
  50.  
  51.     The filerequester asks you for the total number of data to be read in.
  52. With "starting index" is meant the first datum in the display (default
  53. is one). If you have lots of data and not so much RAM, you may want to start
  54. at 78000 for instance and put in 90000 for the "total number". RAM is only
  55. needed for 12000 then.
  56. With "redundancy" is meant the number of points you wish to ignore in case
  57. of a very high sampling rate. Two points means that every third point is
  58. taken into account.
  59.  
  60.     NOK (="Not OK") brings you back to the main menu and with OK the first
  61. datasamples are being displayed. The display is "pixeloriented". In
  62. other words, each horizontal pixel represents a sampled value and each
  63. vertical pixel an amplitude-unit. Reading in "eeg" shows what this
  64. means since this signal varies in real amplitude from ca 2000-7000, whereas
  65. the displayheight amounts to 200. You can measure this by rightklicking
  66. the mouse if the cursor is in the displayfield ("klick and move").
  67.  
  68.  
  69. The displayed number, in the title bar left, indicates the degree
  70. of horizontal expansion. One stands for one horizontal pixel per datapoint.
  71. The triangular gadgets at the right of it allow a modification of the
  72. number of pixels per point.
  73.  
  74. With the horizontal arrows you can "page" through the data. A leftklick
  75. on the next gadget changes the window allowing a faster "paging". More
  76. to that, see below. RST means a reset of the data. If they disappear,
  77. the horizontal and even more so the vertical potentiometer may bring
  78. them back. Keeping the left-mouse button pressed and moving the
  79. slider or just  single klicks in the proportional gadgets will make this
  80. clear to you.
  81.  
  82. Other gadgets appear by clicking twice the right mousebutton.
  83. The first two (triangular) gadgets can be used to compress the amplitude
  84. of the data. This  maybe useful for very large amplitudes. More useful
  85. is the next gadget. The data are now centered according to the largest
  86. and smallest available amplitude. All these actions are taken into
  87. account by the value in the titlebar ("klick left on OK and klick
  88. right in the window") indicating the vertical amplitude.
  89.  
  90. With PRT a rastportdump can be made if a printer is connected.
  91. A small requester is fired up. For printers with 8 needles
  92. RDC reduces the picture in size by about a half. NOK allows
  93. a retreat without action.
  94.  
  95. There are a number of ways to reduce the size of the printout.
  96. In the first place there is RDC of course. Going back to the main
  97. window, however, the size of the window can be custimized by
  98. doubleklicking the right mousebutton and changing the windowsize
  99. in the appearing requester. Finally, you may wish to use
  100. preferences (WorkBench 1.3).
  101.  
  102. With NOK you leave the plotwindow and return to the main window.
  103. OK lets the requester disappear.
  104.  
  105. The inactivated gadgets are used in the expanded window where a fast
  106. "paging" becomes possible. To that purpose the two horizontal
  107. bars in the titlebar are klicked with the left mouse-button. De
  108. abovementioned gadgets are now activated and using them, more data
  109. will be  displayed. The more data,the larger the "page" and the faster
  110. you will get an overall picture by means of the horizontal arrows in the
  111. titlebar. If you have 4 fields of data in the window for instance, one klick
  112. shows the next 4*600=2400 data. This can be checked by removing the
  113. gadget (klick on OK) and klicking once with the right mouse-button somewhere
  114. in the display field ("klick and move"). The display in the titlebar
  115. shows you where you are.
  116.  
  117. You can freeze the vertical line somewhere by klicking the
  118. right button one more time. Going back to the plotwindow (activate
  119. horizontal bars in titlebar) shows that the plotted data start at this
  120. chosen position. For an accurate datacut the freezing should be carried out
  121. carefully (no fast moving around and keep the button pressed for a second).
  122.  
  123.  
  124.                             ------------
  125.  
  126. 2.FOURIER (FFT)
  127.   -------------
  128. The general idea of the program is to read in arbitrary experimental
  129. data, visualize them and carry out a Fouriertransform of an interesting
  130. detail. The start of the transform is determined by the first datum in
  131. the plotwindow.
  132.  
  133. The defaultvalue of 6 in the FFT requester means that 2^6 points will be
  134. used for the transform. The reason behind the power of two is simply
  135. velocity. Clicking on OK ,using default, yields 2^(6-1)=32 harmonics.
  136. With redundancy you can skip a variable number of points for the
  137. transform in case of a long record. Typing in 1 means that every third
  138. point is taken into account for the transformation.
  139.  
  140. The appearing window shows in the upper half the amplitudes and
  141. below you see the appropriate phases.
  142. A double-klick with the right mousebutton brings up the requester.
  143. The arrows manipulate the Amplitudes of the Harmonics. OK brings you
  144. back into the main window and with NOK into the plotwindow. With PRT
  145. a little requester is fired up where RDC means a reduction of the
  146. printed picture (can be useful for 9 needles). The crosshair for the
  147. amplitudes (leftklick) can only be activated without the requester.
  148. IDCMP input of Intuition is blocked in case of a request. To that
  149. purpose the CRH gadget is activated which lets the requester
  150. dissappear.
  151.  
  152.  
  153. EXAMPLE
  154. -------
  155.  
  156. To see the full power of a fouriertransform as far as periodic signals
  157. is concerned (the interpretation is more involved for random signals),
  158. the following step by step procedure may be useful (for the usage of the
  159. program as well):
  160.  
  161. 1.
  162.  
  163. If you are on the workbench, double-klick with left on the dpfft icon.
  164. (If you are in CLI, type <dpfft> and return). It is possibly simplest to
  165. boot with the FISH-disk itself so you can use the default values of dpfft.
  166.  
  167. 2.
  168.  
  169. Activate with the right mousebutton the ASCII-file option in the menu
  170.  
  171. 3.
  172.  
  173. Search for and Klick on signals(dir) and after that on "eeg"
  174.  
  175. 4.
  176.  
  177. Read in, say, 1024 data (leftklick on the 'Number of data:' stringadget
  178. and type in 1024)
  179.  
  180. 6.
  181.  
  182. Left-klick with the mousebutton on OK and choose the 'plot' option in
  183. the menu
  184.  
  185. 7.
  186.  
  187. Double-klick the right mousebutton to fire up the requester for the options
  188. Center the data with the second gadget from the left. Observing the signal
  189. (expand it horizontally, for instance, by means of a leftklick on OK and
  190. using the small triangles in the titlebar) shows that it is not possible
  191. to detect hidden periodicities in the signal
  192.  
  193. 8.
  194.  
  195. Let the requester reappear by means of a double-klick with the right
  196. mousebutton and activate  FFT
  197.  
  198. 9.
  199.  
  200. Since we read in 1024 data, the maximum N that can be used is 10.
  201. (The program works with max 2^10=1024 points since the windowresolution
  202. amounts to 640 sothat 512 harmonics can be displayed maximally, if we want
  203. to retain a pixel to pixel resolution). Klick on the stringadget and
  204. type in 10.
  205.  
  206. 10.
  207.  
  208. With no window or prewhitening (=first difference filter), which are
  209. the WND and FLT gadgets, a direct transform is carried out by activating
  210. OK. This takes a few seconds. A transform with N<10 will be faster of course.
  211.  
  212. 11.
  213.  
  214. Double-klick with the right mousebutton for the requester. Use the
  215. arrow which is pointing downwards for reducing the amplitudes of the
  216. harmonics. Do this until all the harmonics are displayed. A pronounced
  217. peak should appear at right.
  218.  
  219. 12.
  220.  
  221. Let the requester dissappear by means of CRH and klick once with the
  222. right mousebutton in the harmonics area. A crosshair appears. Go to
  223. this peak and note the number of the harmonic (which should be 206).
  224.  
  225.  
  226.  
  227. DISCUSSION
  228. ----------
  229.  
  230. The pronounced peaks are the hidden periodicities in the signal.
  231. Remember that the recordlength of 1024 points with a 4 ms sampling period
  232. totals to ca 4 seconds. The question is as to whether the peak at right
  233. belongs to the signalsource itself or not. Placing the crosshair on that
  234. particular harmonic shows that it carries the number 206. It is now clear
  235. where it comes from, since 204/(4 seconds) represents the frequency of
  236. the linevoltage (50 Hz in Europe). The other peaks can be identified
  237. with the socalled alpha and beta waves of an electroencephalogram.
  238.  
  239.  
  240.                     ---------------------
  241.  
  242.  
  243. 3. THE EWK-TRANSFORM
  244.    -----------------
  245.  
  246. This one is based on a Fourier-transform of the autocorrelation function
  247. of the data. I prefer this one for smoothing reasons. The window-closing
  248. lets you choose yourself the degree of smoothing of the spectra. The
  249. socalled "window-carpentry" (Parzen, Welch, Bartlett, Hanning etc) is
  250. not so flexible.
  251.  
  252.  
  253. A SAMPLE SESSION
  254.  
  255. We know now how to FFT the eeg signal, so the final results can be
  256. compared.
  257.  
  258. 1.  Read in the eeg again (you can change the default path
  259.     by double klicking the right mousebutton in the main window)
  260.  
  261. 2.  Choose "plot" in the menu and double klick for the control gadgets
  262.  
  263. 3.  Use the FFT gadget and choose the correlation image
  264.  
  265. 4.  Fill in the number of points which should be at least 200 pts
  266.     if you want a Fourier transform afterwards, since it is worked
  267.     with 100 frequencies (why this is so, see further)
  268.  
  269. 5.  A serial correlation takes time (though it has been coded in assembler)
  270.     Since the calculation time goes up quadratically, a large number
  271.     of points should be avoided (not of course, if a long transform is needed).
  272.     The appearing window has been scaled to +/- 1000, sothat a value of
  273.     340, for instance, actually represents a correlation of 0.34. You can
  274.     check this by klicking once with the right mousebutton in order
  275.     to obtain the crosshair. The arrows of the controlgadgets (double klick)
  276.     allow a horizontal expansion.
  277.  
  278. 6.  Choose the FFT gadget. You are asked now for the number of lags. This
  279.     means that you force the autocorrelation to zero over that number
  280.     in a linear way. This is the Windowclosing idea (See Jenkins and Watts
  281.     Ch.7). The more points you choose ,the more detailed the spectrum
  282.     will be. Type in 50 for instance. Choose the LIN gadget.
  283.  
  284. 7.  Again you have to wait. A real cosinetransform is carried out (no FFT).
  285.     The spectrum is amplified by the proportional gadget at right with
  286.     automatic scaling. Compare the obtained form with a FFT spectrum
  287.     for N=8 (128 freq. vs. 100 freq. here) for instance.
  288.  
  289. 8.  Get the requester back by a doubleklick and choose LOG. If you want
  290.     to pull the spectrum down, go back to the linear window (double klick
  291.     again) and reduce the amplification. Note that the harmonic component
  292.     has now the dimension of a real frequency, in contrast to the FFT.
  293.  
  294.  
  295.  
  296. DISCUSSION
  297. ----------
  298.  
  299. If you are not only interested in a certain harmonic but also in the spectral
  300. power as such, the FFT should be used. The cosine transform is normalised.
  301. I did this because I wanted to compare different signals with different
  302. variances. The relative power (power/variance) is then more conclusive.
  303. For all sorts of signals, the area below the powerspectrum will then be
  304. the same (=0.5, if correct).
  305.  
  306. Since it takes a lot of time for a long correlation, the final result is put
  307. in a file on the root directory (double klick in main window for the
  308. path) named "corr.dat". If you want to have a look at this file
  309. (with ffp data), choose in the main menu the float option. Getting
  310. back to the main window is always possible by klicking on NOK-NOK-....
  311.  
  312. The choice of 100 freq for the display has a special reason. I am interested
  313. in relatively low frequencies ( < 100 Hz). For a 250 data record with a
  314. sampling rate of 4 ms, the recordlength is one second. The max. freq. of
  315. the transform is then the 125. harmonic, which means in this case 125 Hz.
  316. The 100. harmonic is then 100 Hz and the first harmonic 1 Hz.
  317. For a data record with 2500 points, this will be 10 Hz and 0.1 Hz respectively.
  318. The trick is therefore to modify the frequency-range with the length of
  319. the data record.
  320.  
  321.  
  322.                         ------------
  323.  
  324. 4. 3-D SPECTRA
  325.    -----------
  326.  
  327. This is a timeconsuming process. For a first look take the defaultvalue
  328. N=6. This means that 2^(N-1)=32 spectra wil be displayed. To achieve this,
  329. you have to klick on the "3-D" image of the FFT requester. In detail:
  330.    -Read in 1000 data of the EEG signal for instance
  331.    -Choose "plot" in the main menue
  332.    -Fire up the control gadgets (double klick with right)
  333.    -Choose FFT
  334.    -Now you have the FFT requester
  335. After choosing the "3-D" Image a small requester appears. "Step" represents
  336. the number of points between the subsequent FFT spectra. All spectra are
  337. smoothed with the Bartlett window. Alpha and beta are numbers between 0-360
  338. with which you are able to rotate the picture. Just use the defaultvalues for
  339. the moment and activate OK.
  340.     With a double-klick another requester comes up. Change first the
  341. value of alfa, for instance. This represents a rotation about the z-axis.
  342. With the  rdce gadget the rotation about the x-axis (which is beta) can
  343. be reduced. There are cases where a value of 1 for beta is already too large.
  344. The image is scaled in such a way, that the largest amplitude
  345. automatically covers all vertical available pixels. It therefore depends
  346. on the spectrum whether a full rotation about the x-axis is possible.
  347. Particularly with a large low power (such as is the case with the eeg),
  348. the rotation with beta is restricted.
  349.  
  350. EXAMPLE
  351. -------
  352.  
  353. 1. Read in the sinus signal
  354.  
  355. 2. Choose "plot" in the main menu
  356.  
  357. 3. Fire up the controlgadgets
  358.  
  359. 4. Choose "FFT"
  360.  
  361. 5. Activate the "3-D" image
  362.  
  363. 6. Use a "step" of ten and klick OK
  364.  
  365. Since the sinusoid has 100 samples per period, and the default value for
  366. the FFT is N=6, only part of the sinus is transformed, which explains
  367. the sidebands. The sinusoidal appearance of the 3-D picture is due to the
  368. fact that a running transform depends on the first and last data-point
  369. of the record and these evolve in a sinusoidal way.
  370.  
  371.                         -------------------
  372.  
  373.  
  374.