EOD Simulator


Opening Waveform
There were several modifications made to the opening code for individual waveforms. As with all functions, it had to be doubled to accomodate the second channel. Therefore, the waveforms were split into A and B, and separate open functions were implemented for each of them. As per the given specifications, a few other modifications were made to the open function.

The new function windows from -2.5 ms to 2 ms, increasing the window by 0.5 ms, accommodating slightly larger waveforms to prevent chopping off important data. Another added feature is the hanning window, which solves the problem that some recorded EODs do not return fully to baseline, or their initial baseline may be offset to the final baseline. Therefore, the following simple code takes the signal and applies a hanning window.
The one other addition to the open code is the new implementation of state variables as to whether or not a new waveform has been loaded. As will be discussed later, the new output function creates a WAV file for each signal/spi combination. Therefore, it is important to know if the signal has changed and a new WAV must be created.

New SPI Handling

A new feature of this version is the ability to read in standardized SPI files. These files contain about 60 seconds of SPI data, and the objective is to read in the data and properly format it for display. This two-dimensional plot contains the pulses spaced linearly and vertically based on their intervals. On the horizontal axis, the point is plotted at its place in time. On the vertical, the interval since the last pulse is plotted. The SPI data is stored as clock ticks, and is converted to milliseconds by knowing the clock tick intervals and the sampling rate of the SPI, which are all stored in the file. One additional feature is interval statistic displays for these SPIs. While not in the original specifications, it seemed an interesting method for a quantitative comparison of SPIs to calculate the statistics, especially for comparison purposes with the artifical waveforms.
The other method for selecting intervals is an attempt to more closely approximate the spacing which would ideally exist in nature. The user inputs a mean value for the interval spacing, a standard deviation, and a minimum interval spacing length. The code for implementing this spacing algorithm selects a random interval based on the normal curve with the entered data. The value is added to the list of interval spacings, and the SPI is generated as it was for the SPI files.
    while time_accum<60 interval=max(int_meanA+sdA*randn,min_intervalA); time_accum=time_accum+interval; spi=[spi;interval]; end spimsA=spi*1000; spitimeA=cumsum(spi);

Playing the Sound

Proper output of the sound presenting one of the biggest challenges for this project. I realized that the previous version lacked serious accuracy and did not properly output the EODs. The computational time required to properly space quick EODs severly delayed short pulse intervals. Previously, wait loops would wait the proper interval and output the waveform. However, the time it took to open the sound device, output the sound, close it, and reopen it just delayed the waveform output.

The solution was to pregenerate the sound and store it as a WAV file. This method requires large amounts of memory for generating appropriate length WAV files. For single channel output, the maximum time seemed to be about 20 seconds. For dual channel, the maximum time was 10 seconds.

To output from a single channel, the function first checks to see if the current WAV file represents the current SPI and current waveform. This is accomplished with a simple boolean variable which indicates if the waveform must be reformed. If so, a simple loop reads the SPI, and places enough 0's to indicate silence periods in the pulse intervals, and then adds the signal where appropriate. Once the matrix is created, a two-second ramping function is added to the beginning to avoid startling the fish. This entire process can take up to a minute, but on subsequent plays, the WAV does not need to be recreated so it plays immediately. Another addition, the STOP button, allows a waveform to be stopped while it is playing.

The other new function, two channel output, works very similar to the single channel output. In this case, both channels are simulatenously created and are made into a stereo WAV file. There is another state variable for this function, which is reset by changes to either channel A or channel B.

Webpage created by Joel Avrunin ('01).
Created May 15th, 2001.