Class FFTDomainRen

java.lang.Object
pl.polsl.rtsa.controller.FFTDomainRen

public class FFTDomainRen extends Object
Renders the FFT magnitude spectrum with:
  • Grid lines at "nice" frequency and magnitude intervals
  • Frequency (X) and magnitude (Y) axis labels
  • Zoom-aware rendering via explicit visible-range parameters
  • Correct bin→Hz mapping: f = bin × (sampleRate / (2 × N))
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final javafx.scene.paint.Color
     
    private static final javafx.scene.paint.Color
     
    private static final javafx.scene.paint.Color
     
    private static final int
     
    private static final javafx.scene.paint.Color
     
    private static final int
     
    private static final double
     
    private static final double
     
    private static final double
     
    private static final double
     
    private boolean
     
    private static final javafx.scene.paint.Color
     
    private static final javafx.scene.paint.Color
     
    private final double[]
     
    private final double[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static double
    clamp(double v, double lo, double hi)
    Clamps v to the range [lo, hi].
    void
    draw(javafx.scene.canvas.GraphicsContext gc, double[] fft, double magMin, double magMax, double freqStart, double freqEnd, double sampleRate, double w, double h)
    Draw the FFT magnitude spectrum.
    private void
    drawBorder(javafx.scene.canvas.GraphicsContext gc, double pw, double ph)
    Draws the plot-area border rectangle.
    void
    drawEmpty(javafx.scene.canvas.GraphicsContext gc, double w, double h)
    Draw empty canvas with default grid and placeholder.
    private void
    drawGrid(javafx.scene.canvas.GraphicsContext gc, double magMin, double magMax, double freqStart, double freqEnd, double pw, double ph)
    Draws magnitude (Y) and frequency (X) grid lines with labels.
    private void
    drawPlaceholder(javafx.scene.canvas.GraphicsContext gc, double pw, double ph, String text)
    Draws centred placeholder text when no FFT data is available.
    private void
    drawSpectrum(javafx.scene.canvas.GraphicsContext gc, double[] fft, double magMin, double magMax, double freqStart, double freqEnd, double sampleRate, double pw, double ph)
    Render the FFT magnitude trace.
    void
    setShowGrid(boolean show)
    Toggles grid-line rendering.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ML

      private static final double ML
      See Also:
    • MR

      private static final double MR
      See Also:
    • MT

      private static final double MT
      See Also:
    • MB

      private static final double MB
      See Also:
    • MAX_POINTS

      private static final int MAX_POINTS
      See Also:
    • GRID_DIVISIONS

      private static final int GRID_DIVISIONS
      See Also:
    • BG_COLOR

      private static final javafx.scene.paint.Color BG_COLOR
    • GRID_COLOR

      private static final javafx.scene.paint.Color GRID_COLOR
    • AXIS_COLOR

      private static final javafx.scene.paint.Color AXIS_COLOR
    • LABEL_COLOR

      private static final javafx.scene.paint.Color LABEL_COLOR
    • SIGNAL_COLOR

      private static final javafx.scene.paint.Color SIGNAL_COLOR
    • TITLE_COLOR

      private static final javafx.scene.paint.Color TITLE_COLOR
    • xBuf

      private final double[] xBuf
    • yBuf

      private final double[] yBuf
    • showGrid

      private boolean showGrid
  • Constructor Details

    • FFTDomainRen

      public FFTDomainRen()
  • Method Details

    • setShowGrid

      public void setShowGrid(boolean show)
      Toggles grid-line rendering.
      Parameters:
      show - true to draw grid lines, false to hide them
    • draw

      public void draw(javafx.scene.canvas.GraphicsContext gc, double[] fft, double magMin, double magMax, double freqStart, double freqEnd, double sampleRate, double w, double h)
      Draw the FFT magnitude spectrum.
      Parameters:
      gc - canvas graphics context
      fft - magnitude values (half-spectrum, N/2 bins, positive freqs)
      magMin - visible magnitude minimum (usually 0)
      magMax - visible magnitude maximum
      freqStart - visible frequency start (Hz)
      freqEnd - visible frequency end (Hz)
      sampleRate - sampling rate (Hz) — needed for bin→Hz mapping
      w - canvas width (px)
      h - canvas height (px)
    • drawEmpty

      public void drawEmpty(javafx.scene.canvas.GraphicsContext gc, double w, double h)
      Draw empty canvas with default grid and placeholder.
    • drawGrid

      private void drawGrid(javafx.scene.canvas.GraphicsContext gc, double magMin, double magMax, double freqStart, double freqEnd, double pw, double ph)
      Draws magnitude (Y) and frequency (X) grid lines with labels.
    • drawBorder

      private void drawBorder(javafx.scene.canvas.GraphicsContext gc, double pw, double ph)
      Draws the plot-area border rectangle.
    • drawSpectrum

      private void drawSpectrum(javafx.scene.canvas.GraphicsContext gc, double[] fft, double magMin, double magMax, double freqStart, double freqEnd, double sampleRate, double pw, double ph)
      Render the FFT magnitude trace.

      Bin-to-frequency mapping: freq(bin) = bin × freqResolution where freqResolution = sampleRate / (2 × fft.length) because fft[] is the half-spectrum (N/2 bins from an N-point FFT).

    • drawPlaceholder

      private void drawPlaceholder(javafx.scene.canvas.GraphicsContext gc, double pw, double ph, String text)
      Draws centred placeholder text when no FFT data is available.
      Parameters:
      gc - graphics context
      pw - plot width (px)
      ph - plot height (px)
      text - the message to display
    • clamp

      private static double clamp(double v, double lo, double hi)
      Clamps v to the range [lo, hi].