home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / misc / sci / gfft / source / oktime3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  3.8 KB  |  111 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        oktime3d.c
  13.  * Purpose:     do a time-3D spectrum (meaning amplitude vs. freq. vs. time)
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     10-February-1994 CPP; Created.
  16.  *              29-August-1994 CPP (1.12); offset start time by 1/2 
  17.  *                interval to permit logarithmic displays.
  18.  * Comment:     To preserve the full set of options available in a regular
  19.  *                ('flat') FFT, this function simply sets up and calls
  20.  *                ok_spectrum for each 'time segment.'
  21.  *              It 'forces' each segment by setting StartFrame and Frames
  22.  *                 as required.  Their original values are preserved
  23.  *                 here.
  24.  *              The real StartFrame (as specified by user) and Frames
  25.  *                 are to refer to the dataset as a whole,
  26.  *                 and NOT to each Time Segment.  Most other options
  27.  *                 (Overlap, Pad, Interleave, etc.) may still be applied
  28.  *                 to each individual time segment.
  29.  */
  30.  
  31. #include "gfft.h"
  32. #include "settings.h" /* Power, Amplitude, ReadPtr */
  33.  
  34. ULONG ok_time3d_spectrum (BOOLEAN do_it_for_real)
  35. {
  36.     ULONG save_ok_start_frame = OkStartFrame;
  37.     ULONG save_ok_frames = OkFrames;
  38.     ULONG dummy = 0;
  39.     ULONG frames;
  40.     ULONG running_offset;
  41.     ULONG bins_used = 0;
  42.     double segment_time_increment;
  43.     double fudge = 1.0 / LONG_MAX;  /* compensate for floating inaccuracy */
  44.     double time_overlap = TimeOverlap;
  45.     long time_segments = TimeSegments;
  46.     long time_seg_size = TimeSegSize;
  47.     long time_offset = TimeOffset;
  48.     long i;
  49.  
  50.     if (time_overlap == INVALID_SET ||
  51.     time_offset == INVALID_SET ||
  52.     time_segments == INVALID_SET ||
  53.     time_seg_size == INVALID_SET)
  54.     {
  55.     error_message (INVALID_TIMESEG_PARAMETERS);
  56.     RAISE_ERROR (NOTHING_SPECIAL);  /* longjmp outa here! */
  57.     }
  58.  
  59.     frames = (OkFrames != ULONG_MAX) ? OkFrames :
  60.       ok_read (NULL, dummy);
  61.  
  62.     if (time_seg_size == NOT_SET)
  63.     {
  64.     if (time_segments == NOT_SET)
  65.     {
  66.         error_message (MISSING_TIMESEG_PARAMETERS);
  67.         RAISE_ERROR (NOTHING_SPECIAL);  /* longjmp outa here! */
  68.     }
  69.     if (time_offset == NOT_SET)
  70.     {
  71.         time_seg_size = fudge + (frames / 
  72.           (1.0 + (1.0 - time_overlap) * (time_segments - 1)));
  73.         time_offset = fudge + (time_seg_size * (1.0 - time_overlap));
  74.     }
  75.     else
  76.     {
  77.         time_seg_size = frames - (time_offset * (time_segments - 1));
  78.     }
  79.     }
  80.     else
  81.     {
  82.     if (time_offset = NOT_SET)
  83.     {
  84.         time_offset = fudge + (time_seg_size * (1.0 - time_overlap));
  85.     }
  86.     time_segments = ((frames - time_seg_size) / time_offset) + 1;
  87.     }
  88. /*
  89.  * Now, we have the all dependent and independent parameters
  90.  */
  91.     segment_time_increment = time_seg_size / OkRate;
  92.     OkSegmentTime = segment_time_increment / 2;
  93.  
  94.     running_offset = save_ok_start_frame;
  95.     for (i = 0; i < time_segments; i++)
  96.     {
  97.     OkStartFrame = running_offset;
  98.     OkFrames = time_seg_size;
  99.  
  100.     ok_rewind ();
  101.     bins_used = ok_spectrum (do_it_for_real);
  102.     if (!do_it_for_real) return bins_used;
  103.  
  104.     running_offset += time_offset;
  105.     OkSegmentTime += segment_time_increment;
  106.     }
  107.     OkStartFrame = save_ok_start_frame;
  108.     OkFrames = save_ok_frames;
  109.     return bins_used;
  110. }
  111.