# developer.spectrogram

### From autoplot.org

## Contents |

# 1. Purpose

Reiner and I were talking about the spectrogram algorithm and its shortcomings, and this page is the beginning of identifying and addressing these issues. Also Jon and Larry at APL have a long-standing request to have more control of the algorithm.

# 2. The current algorithm

The current algorithm was developed for viewing data produced by instruments from the Radio and Plasma Wave Group at Iowa. This data looks best when interpolating between measurements in both time and frequency. Typically there are no data dropouts, and the data is fairly smooth, so picking nearest neighbors would introduce cusps in the data. It's useful to think about the frequency content of the image, like a 2-D FFT. Nearest neighbor sampling introduces high-frequency cusps in the visualization of the data. Also they tend to have as many channels in Y as there are pixels, so NN sampling would introduce strange Nyquist features.

- Identify pixels location for all data points.
- Average all the data at the same pixel location. This is done in the linear space.
- (If you set the rebin mode to "noInterpolateNoEnlarge" it will stop here)
- For each pixel row:
- identify the adjacent values bracketing the pixel.
- "Interpolate" the value if possible. This is either picking a close neighbor, or interpolating between two values depending on rebin setting

- We now have a pixel grid with horizontal lines.
- For each pixel column:
- identify the adjacent values, which may have been interpolated, bracketing the pixel.
- "Interpolate" the value if possible. This is either picking a close neighbor, or interpolating between two values depending on rebin

# 3. Shortcomings of the algorithm

- limited control: interpolate or NN. Requests for NN in X, interpolate in Y.
- Interpolation is done in the data space, should be done in pixel color space
- Algorithm still introduces Nyquist effects, because of pixel shift into bins.
- Data gaps are sometimes incorrectly drawn because shifting pixels means we must adjust interpolation limits.
- Nearest Neighbor interpolation is sub-optimal implementation (Reiner's original complaint.) (This is a bug that can be addressed).
- Nearest Neighbor interpolation may fail because we loose the identity of the dataset table when we put it into bins.
- Nearest Neighbor interpolation may fail to show single-point drop out.

# 4. Communication of Average Type

Another problem the Das2server has, as well as the spectrogram renderer, is that averages are always done as linear averages. Larry and I were just chatting about this and enumerated a bunch of average types. Note the CDAWeb has a similar property, and I believe this would satisfy a number of needs.

**linear** return the linear average of two points, using weights.

**geometric** return the geometric average of two points, using weights.

**nearestNeighbor** return the point with the bigger weight.

**max** return the larger point.

**mod360** return the linear average, where 259 and 1 are 2 units apart.

**mod24** return the linear average, where 23 and 1 are 2 units apart.

**modPI** return the linear average, where PI and 2*PI are the same

**modTAU** return the linear average, where PI and 3*PI are the same

**mod_m90_p90** where 89 and 91 are the same, as are -89 and -91.

**mode** return the point with the biggest weight.

**median** return the median-filter point. This is more complex than others, requiring a number of points.

Larry suggests that we might be able to express each algorithmically. So for example instead of "linear" we would say "(MA*WA+MB*WB)/(WA+WB)" or instead of "nearestNeighbor" we would say "WA>WB?MA:MB". (Larry will correct these provide expressions for others.)

See https://spdf.gsfc.nasa.gov/istp_guide/vattributes.html#AVG_TYPE

# 5. See Also

- http://das2.org/wiki/index.php/SpectrogramRenderer
- https://sourceforge.net/tracker/index.php?func=detail&aid=3237397&group_id=199733&atid=970682 "gaps in das2 spectrograms back"
- https://sourceforge.net/tracker/index.php?func=detail&aid=3117538&group_id=199733&atid=970682 "Cluster/PEACE interpolation issue with das2 nn spectrograms"
- http://autoplot.org/developer.spectrogram.rebin