PIN - Edge/Notch Detection

                                                      Programming Note No. 5 
                                                      Ravi Kochhar 
                                                      Alan Musicant 
                                                      Joe Chan 
                                                      Dept. of Neurophysiology 
                                                      Feb. 17, 1992 
                                                      Rev. July 12, 1996
                                                      Rev. level : 2.001

This note is a description of the method used by the PIN program to identify edges and notches for cat ear transfer functions in the frequency domain. This method was suggested by Alan Musicant and Joe Chan.

The PIN program (ref. 1) is used for both data collection and analysis of recordings made at the cat's eardrum from all locations in space between -36 deg and +90 deg elevation and -180 deg and +180 deg azimuth at 4.5 deg steps. The recordings were done in an anechoic chamber by Musicant, Chan and Hind (ref. 2). The raw data consists of time domain waveforms digitized by an analog- to-digital converter in response to clicks from various locations in space. These click responses (transfer functions) are converted to the frequency domain using an FFT routine, and stored in a STATPK compatible data file.

The PIN program is written in FORTRAN and currently runs on a VAX/VMS computer.


The Edge/Notch detection program is called from within the PIN program by selecting option (8) Analyze Data followed by option (1) Frequency Domain Analysis and then option (4) Edge/Notch detection.

The program begins by asking the user for the STATPK file name containing the frequency domain transfer functions. The transfer functions are assumed stored in such a way that the first column of the data set contains frequency in Hertz, and any of the remaining columns contains the amplitude (in dB).

Next, the program asks for the range of data sets for which the edge/notch procedure is to be done. The range is specified in the format (from,to,incr). For example, 1,100,1 would mean "do all data sets from 1 to 100", and 1,100,10 would mean "do every 10th data set from 1 to 100". The program now asks for the column number containing the amplitude, and the frequency range to be analyzed (the default range is 6000 Hz to 40000 Hz). Next, the program asks for the width OCTL (in octaves) and the depth DBL (in dB) to be used for left edge detection (see below also). The defaults are 1/3 oct and 7 dB. Then the user is asked to specify the width OCTR (octaves), Max width OCTM (octaves) and depth DBR (dB) for the right edge detection. The defaults are 1/3 oct, 0.4 oct and 7 dB respectively. Finally, for the notch detection, the user can select between smoothing using an n-point window, or no smoothing. The default is no smoothing.

The program then proceeds to detect the edges/notches for the data sets asked for, using the following steps for each.

(1) The frequency and amplitude columns are read in from the data file.

(2) The azimuth and elevation are deciphered from the data set ID.

(3) The amplitude column is scanned for a left edge as follows :

(a) Starting with the "start frequency", a window equal to the left edge window (OCTL) is scanned for the first frequency at which the amplitude is at least DBL dB less than at the start frequency. See figure 1.

(b) If no such freq. is found within the window, then the "start freq" is incremented to the next higher frequency, and step (a) is repeated. If we exceed the "high frequency" limit without finding an edge then proceed to step (8) below.

(c) If a freq. is found at which the amplitude is DBL dB down from the start, then an attempt is made to "narrow" the edge by scanning all pairs of points between the start freq. and the edge freq. (from step (a) above), until a pair of points is found which are separated by at least DBL in amplitude, are closest in frequency, and which are closer in freq. than the points found in step (a). This scanning is restricted such that the start or shoulder frequency is always less than the edge frequency. Figure 2 illustrates this point. In this example, A' and B' are the new points, with B' being the new left edge.

(d) The left edge frequency is further improved by scanning backwards (towards lower frequencies) looking for inflections in the amplitude spectrum. An inflection is defined as an amplitude being less than its neighbor at the next higher frequency for two successive points. If an inflection is found, then the second point after (i.e. at a higher freq. than) the inflection point is used as a "start frequency", and a subsequent window of width OCTL is scanned for a point at least DBL dB down from the start point. If no such point is found, then the previous left edge is retained, and the program proceeds to step (e) below.

If a point is found that is DBL dB down from the shoulder, then it is defined as the new "left edge" point. However, if this new left edge is at a higher frequency than the original left edge (from step (c)), then the original is retained as the left edge.

Figure 3 illustrates this point. Here, an inflection point has been found at X. Then A" was chosen as the new start frequency, and B" was found as the new left edge. If B" had been at a higher frequency than B', then B' would have been retained as the left edge. It is important to note that in such cases the freq. width from A"-B" is more than the width A'-B', but B" is still considered the better "left edge" because it is DBL down from A", which is considered a better "shoulder" point than A'.

(e) If this is the second or later left edge, then it is compared with the most recent left edge to check whether it is along the same slope. This is done by looking for at least one inflection point between the two left edges. An inflection is defined as an amplitude being less than its neighbor at the next higher frequency for two successive points. If no inflection point is found between the two left edges, then they are considered to be along the same slope. An example of this is shown in figure 4. Edges E and E' in figure 4A are along the same slope, while in figure 4B they are not.

The "left edge frequency" is stored in a results array (ENOT). If this edge is on the same slope as the most recent left edge, then the frequency stored in ENOT for the current left edge is multiplied by minus one (-1).

The negative freq. value is used as a flag in later analyses to mark the case of more than one left edge along the same slope.

(4) After the left edge is determined, the program searches for the next amplitude minima. This is done by scanning the amplitude spectrum starting at the left edge frequency looking for the first frequency where the amplitude starts to increase.

(5) Starting from the minimum point, the program looks for the next "right edge frequency" as follows :

(a) A destination freq. is computed. This is the lesser of a window of width OCTR starting at the min. freq. and a window of width OCTM starting at the left edge frequency.

(b) Starting with the min. freq., all amplitudes are scanned upto the destination freq. looking for the first point where the amplitude is at least DBR dB greater than the minimum.

If found, this point is saved as the "right edge frequency", and the program proceeds to step (6) below.

If not found, the start (min. freq.) is moved up one point and step (a) above is repeated until a right edge is found or OCTM is reached. If no right edge is found within the OCTM window, then the "start frequency" is set equal to the current frequency, and the program looks for a new left edge starting at step (3) above. The right edge (and notch) frequencies in this case are recorded as "missing values" in the ENOT array.

Figure 5 below illustrates this point. In figure 5A, the right edge (R) if found within the OCTM window. In figure 5B, the point R is outside the OCTM window, and therefore the right edge will be recorded as "missing".

(6) A "notch frequency" is computed from the left and right edge frequencies by looking for the point of minimum amplitude between the two. If the user asked for (optional) smoothing for edge detection, then that is done first by transforming the amplitudes from dB to linear units and then smoothing.

(7) The "start frequency" is now set equal to the right edge frequency, and the whole procedure is repeated starting with step (3) above. If seven left edges have been determined then the program proceeds with step (8) below.

(8) The (upto) seven left and right edge and notch frequencies are compiled into a table along with the azimuth and elevations. The results table (ENOT) consists of twenty four columns. The first two columns hold the azimuth and elevation computed in step (2) above, the next 21 columns hold the left edge freq., right edge freq., and notch freq. values for upto seven such edge/notch combinations. The last (24th) column holds a count of the number of notch frequencies computed. Any edges/notches that could not be computed are recorded as "missing points" in the results table. Also note that any left edges found on the same slope as the previous left edge are recorded with negative frequencies (see 3(e) above).

(9) When all possible edges/notches for the current data set have been determined, the program fetches the next data set, if any, and repeats from step (2) above. When all data sets are done, the results table is stored back into the data file as a new data set.


Attached below are a couple of plots of frequency domain transfer functions showing computed left edges marked with squares, right edges marked with asterisks (*) and notches marked with circles. Note how three of the "left edges" in figure 6 are along the same slope. The procedure described above works very well in about 90 percent of the cases. It is somewhat specialized for this particular type of data.


(1) Kochhar R., "Summary of PIN programs", Programming note no. 3, Dept. of Neurophysiology, 1989.

(2) Musicant A., Chan J. and Hind J. (1990), "Direction dependent spectral properties of cat external ear : New data and cross species comparisons", J.Acoust.Soc.Am,87,757-781.

Back to Top

If you have questions about, or suggestions for, this document, please send e-mail to
Return to Documentation Page
Return to Basement Page
This page last modified on : July 12, 1996