home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / spect10.zip / SPECT.TXT < prev   
Text File  |  1993-08-12  |  14KB  |  283 lines

  1. Spect version 1.0                                               
  2. AUG  93
  3. by Kevin C. Fandre
  4.  
  5.  
  6. ***************
  7. About:
  8.  
  9. Spect is a sampling and spectral analysis program written for the Gravis
  10. Ultrasound. It utilizes i386 32 bit instructions for speed but since no
  11. protected mode instructions are used it should run in 8086 virtual mode, ie it
  12. won't interfere with memory managers and other such protected mode programs. 
  13. It will not, however, run under windows but who needs to since this program
  14. was written for speed, speed, speed and that precludes windows.
  15.  
  16. So, at minimum, you must have a 386 or better computer, a VGA compatible
  17. video card, and a Gravis Ultrasound.  A math coprocessor is NOT required
  18. and the presence of one will not affect the speed of the program since spect
  19. uses only integer instructions.
  20.  
  21. ***************
  22. Disclaimer:
  23.  
  24. I am not responsible for any damages whatsoever whether it be eye strain, 
  25. migraines, tidal waves, heart failure, or otherwise caused by prolonged 
  26. viewing of this program.  Loss of data, hardware failures, stock crashes, 
  27. and everything else caused by this program are solely the responsibility of 
  28. the user. (I always wanted to write one of those.)
  29.  
  30. ***************
  31. Public Domain:
  32.  
  33. Use of this program is free and I will not try to make you feel guilty for 
  34. using it and not paying for it.  It may be distributed freely for non-profit
  35. only and I reserve all rights to this program.  However, if you use this 
  36. program very frequently, use it for *non-private* purposes, or would like to 
  37. spur me on to further develop this program and others based on FFT analysis, 
  38. you may show your interest by sending a donation commensurate with your level 
  39. of usage of this program to:
  40.  
  41.   Kevin C. Fandre
  42.   1726 Leonard Dr.
  43.   Jacksonville, AR 72706
  44.  
  45. Such donations are strictly non-obligatory but I would strongly encourage
  46. those who use this program for professional purposes, such as in education  
  47. or as a demo in a commercial store for instance, to send in a donation.  
  48. Donations in the range of ten to fifteen dollars per copy are quite 
  49. acceptable.  Please include any comments or suggestions you might have and, 
  50. most especially, please describe to what use you are putting this program.  
  51. This will help me to better gauge your needs and improve upon this program.  
  52. In the future I was planning on adding:
  53.  
  54. -Window smoothing to clear up spectrums and improve definition
  55. -Adding various kinds of digital filters
  56. -Support for other sound cards or a home built ADC kit
  57. -Support for Gravis' own 16bit daughter card
  58. -Adding mouse and window support and other user niceties
  59. -Adding oscilliscopes
  60. -Adding wavelet analysis
  61. -?(Whatever you want) 
  62.  
  63.  
  64.  
  65. ***************
  66. Comments:
  67.  
  68. Please tell me what you think! I would love to hear from you.  Send your
  69. comments to either the above address or my email address: 
  70.   <kfandre@uafhp.uark.edu>  good till May of 94 
  71.   
  72.  
  73.   
  74. ***************
  75. To test:
  76.  
  77. Spect is configurable from the command line but for a quick test try 
  78. running spect without any command line arguments.  This will set up
  79. spect to sample from both the line in and microphone channels in stereo
  80. at 8000 Hz.  These parameters should give adequate results and fast screen
  81. updates even on a slow computer but aliasing caused by too low a sampling 
  82. rate will cause artifacts(unwanted lines) to appear if there is an abundance
  83. of frequencies higher than 4000 Hz.  This means that if you are analyzing
  84. rock music for instance, cymbal crashes will look like static superimposed  
  85. on the lower frequencies.  The only way to avoid this is to switch to a 
  86. higher sampling rate( up to 44100 Hz on the Ultrasound) but this has its
  87. negative side-effects also.  But more on this later.  First I will briefly
  88. describe what the Fast Fourier Transform(FFT) does and how it does it and 
  89. this will give you a better understanding of how to configure spect to give 
  90. you optimum performance.
  91.  
  92.  
  93. ***************
  94. The FFT:
  95.  
  96.  
  97. The FFT is based on the Discrete Fourier Transform which is a discrete
  98. extension of the Fourier integral, an integral which can be interpreted as  
  99. the continuous representation of the spectral components of any given 
  100. function.  The Fourier integral itself derives from the Fourier series which 
  101. is capable of describing any function over an interval in terms of a
  102. *unique* infinite summation of sines and cosines whose periods are integer 
  103. multiples of each other.  Well, that was a mouthful but basically it is 
  104. possible to describe a function, and sampled data over a range constitutes
  105. a function, as a summation of sine waves.  The mathematics of all this was
  106. worked out by the mega-geniuses of the past(Fourier,Laplace, and Euler) 
  107. and boils down to this: 
  108.         1  N-1       jk
  109. X(j) =  -  SUM  x(k)W
  110.         N  k=0
  111.  
  112. where,  
  113. N = number of points
  114.  
  115. W = exp(2*pi*i)/N
  116.  
  117. X(j) - N complex transformed points
  118.  
  119. x(k) - N complex samples
  120.  
  121.  
  122. The points which are graphed on the screen are merely |X(j)| which come
  123. from the sample points x(k).  Since we are dealing with real data the 
  124. complex parts of the samples are just set to zero.
  125.  
  126. Now, as you can see the number of operations that must be gone through 
  127. is proportional to N^2, N summations by N multiply-adds.  Up until 1963
  128. this is the way spectrums were done until Cooley-Tukey came up with a faster
  129. alternative that better utilizes intermediate results.  Their original 
  130. paper described a method which worked with any number of samples so long 
  131. as N was not prime and came to be know as the Fast Fourier Transform.  A 
  132. special case arises when the number of samples is a power of 2(or a power of
  133. 5 or any number for that matter). Spect uses just such an algorithm 
  134. and runs in a time proportional to N*log<base 2>(N).  The time savings over 
  135. N^2 is enormous. 
  136.  
  137. Its difficult to describe in words how the FFT algorithm utilizes 
  138. intermediate results to reduce computation time.  Basically, it amounts
  139. to splitting up the set of samples into two odd and even sets, applying 
  140. the summation detailed above except that exponents are all multiplied by two. 
  141. With the resulting two sets any desired X(j) can be computed by adding an 
  142. element from the even results with an appropriate element from the set of odd 
  143. results multiplied by W raised to a fractional power depending on which X(j) 
  144. is being computed.  The neat part is that this procedure can be applied 
  145. recursively up to log2(N) times if N is a power of 2 until we produce N sets 
  146. of one element each which are nothing more than the sample data themselves.  
  147. Then the recursion stops and we can work our way backwards using the simple 
  148. combining rules to produce an X(j) using only big O log2(n) operations to 
  149. do so.  Over N X(j), this is proportional to N*log2(n) total compute time. 
  150.  
  151. The algorithm used by Spect I owe to who knows who but it dispenses with
  152. the stack pushing overhead involved in recursion and utilizes the patterns
  153. evident in doing all the substitutions of the combining rules into themselves
  154. that was affected by the recursion anyway.  The only draw back is that the 
  155. results are in a scrambled order but a simple table lookup alleviates the 
  156. headache of unscrambling them.  The code was written using 32bit integer  
  157. instructions, utilizes table lookups wherever possible, and squeezes every
  158. last CPU cycle out of the i386.
  159.  
  160.  
  161. **************
  162. Command line Arguments:
  163.  
  164. -? or -h :  list options
  165.  
  166.  
  167. -l :turn on the UltraSound line in
  168. -q :put in quite mode, turn of output
  169. -m :enable microphone input
  170. -L :turn on the logarithmic scale
  171. -f#:allows you to specify the frequency
  172. -s :tell spect to sample stereo data
  173.  
  174. Currently file playing is not supported but will be in future versions.
  175. Typing a filename will work though, but there will be no sound, only
  176. graphics. It was there for diagnostic purposes and I decided to leave it.
  177.  
  178.  
  179. **************
  180. How to Use:
  181.  
  182. From within the program, typing F1 will print the help screen.
  183.  
  184.  
  185. Here's an example of typical command line parameters: 
  186.  
  187.    spect -f16000 -lsL
  188.  
  189. This tells spect to use a logarithmic scale and sample in stereo from the 
  190. line in at 16000 Hz.  If you dont use either the l switch or the m switch you
  191. will be recording dead silence so you must use at minimum one of these 
  192. switches.  The frequency defaults to 8000Hz but can be specified as desired. 
  193.  
  194. Now press the "+" key once. Notice that this screen is identical
  195. to the screen that results when spect is run without any command line  
  196. arguments only that is will be a little bit cleaner because aliasing effects
  197. are reduced.  Also you can press the PgUp key to see the other half of the 
  198. transformed samples since pressing the "+" key doubles the number of 
  199. samples to 512.
  200.  
  201. Doing an FFT transform on real data produces only N/2 relevant points.  The 
  202. other points are just a mirror image and so are discarded by spect.  The 
  203. number of bars displayed by spect is 128 so the minimum number of samples
  204. required to produce 128 significant transform points is 256.  This is the 
  205. minimum.  Spect is capable of utilizing up to 2048 points but at the cost
  206. of execution speed.  However, what you do get is increased resolution.
  207. It is possible to dynamically increase and decrease the number of samples
  208. computed from within the program by pressing the + key to increase the 
  209. number of samples and the - key to decrease the number of samples. 
  210. Fortunately, increasing the number of samples to 2048 dosent slow the 
  211. computer to a crawl for the reasons described above.  A fast 486 helps 
  212. when using a lot of samples and you will need them when sampling at higher
  213. frequencies unless you are willing to sacrifice a lot of detail.
  214.  
  215. Since the display is limited to 128 bars, when zoomed in it is possible to
  216. shift the display left and right one bar at a time by using the cursor keys
  217. and 128 bars at a time by using the PgUp and PgDwn keys.  The frequencies
  218. in hertz listed along the bottom of the screen will automatically adjust to
  219. reflect the new range represented by the group of 128 bars currently on screen.
  220.  
  221. A logarithmic scale is provided to more closely represent the way the ear
  222. perceives sound(decibels are a logarithmic scale afterall).  The logarithmic 
  223. scale tends to more clearly discriminate fainter signals and deemphasizes the 
  224. differences between stronger signals.  You can select this scale option
  225. from the command line with the -L(case matters) switch.  From within the 
  226. program it possible to switch between linear and logarithmic scales with
  227. the "/" key.
  228.  
  229. To determine the spectral resolution of the transform just divide the 
  230. sampling rate by the total number of samples. Thus for the default 8000Hz
  231. the spectral resolution under a 256 point transform is 31.25Hz, meaning that
  232. each bar is 31.25 Hz greater than the next.  You can halve this number by 
  233. pressing the "+" key and doubling the number of samples.  The maximum 
  234. observable frequency is always one half of the sampling rate as per the
  235. Nyquist frequency law.
  236.  
  237. When you experiment with Spect try to pick out the harmonics in various 
  238. signals.  Guitar solos really stand out and voices look really beautiful.
  239. After starring at the patterns that voices produce you can get a glimmer
  240. of how one might go about writing a voice recognition program since the 
  241. patterns are fairly regular.  If you cant see the patterns too clearly 
  242. then try reducing the sampling frequency.  Most of the action, in music at
  243. least, occurs below 4000Hz.  The higher harmonics are there of course but
  244. they are fainter and not as interesting to look at and can be done away with
  245. by choosing a lower sampling rate.  Only, take care that the higher harmonics
  246. are not too strong or they will fold over onto the lower frequencies and give
  247. false lines if the sampling rate is too low. If you have more horsepower at 
  248. your disposal try doubling the sampling rate and doubling the zoom.  You will
  249. get the same screen; it will be a little slower though, but much cleaner.
  250. Also, make sure the volume of your input source is set high enough since the
  251. Ultrasound's ADC is not all that sensitive.  
  252.  
  253. Keep in mind that because the Ultrasound only records in 8 bits and lacks
  254. significant dynamic range it will take some fine control of the volume control
  255. to get enough volume to make all of the harmonics show up while at the same 
  256. time prevent clipping.  You don't want clipping since that will transform 
  257. into false lines that aren't in your source.  A little won't hurt too much 
  258. though...
  259.  
  260. If you have access to a signal generator and test it out on spect don't be 
  261. surprised if you don't get nice sharp bars for every frequency tried.  Since
  262. the DFT works on a limited number of points inaccuracies are bound to
  263. show up in the form of broadening.  You can see what I mean by just whistling 
  264. into a microphone.  You will see a nice sharp peak that broadens as it nears
  265. the bottom of the screen.  This is due to the inherent inaccuracies involved
  266. in representing a continuous signal by a finite number of discrete points.
  267.  
  268. Finding the best combination of speed and accuracy by choosing the frequency 
  269. and number of samples is a matter of trial and error.  In general having 
  270. a fast computer will allow you greater flexibility in choosing higher
  271. sampling rates and larger samples while still maintaining decent refresh 
  272. speeds.  A really fast computer is not essential though.  I developed this   
  273. program on a 386-20 and it runs pretty fast as far as I can tell(9 frames per
  274. second with a 256 point transform!).  A fast 486 should run over three times as
  275. fast I imagine and that will provide near realtime performance with a 256 point
  276. transform.  True realtime performance is not possible since it takes a finite
  277. amount of time to record a block of data but with delays in the hundredths of
  278. seconds it should be virtually instantaneous to the eye.  Experiment and have
  279. fun!  
  280.  
  281. Oh, one last thing.  The graphics look great in the dark with the stereo on. 
  282.  
  283.