/* SPXAMP.C is a file of files. First is an INCLUDE file which should*/
/* be labled SPAINCL.H and #included in each example, and may also be */
/* included in other programs. */
/* .................Begin include file.................*/
/* Latest date: 06/29/92 */
#include <math.h>
/* In the VMS compiler, M_PI is not defined in math.h */
#ifdef vms
#define M_PI 3.14159265358979323846
#endif
#ifndef KR
#define M_PI 3.14159265358979323846
#endif
#define FALSE 0
#define TRUE 1
#define BIG 1e10
#define SMALL 1e-10
#define ORDER5 1e-5
#define ORDER4 1e-4
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define MAX(a,b) ((a) >= (b) ? (a) : (b))
typedef struct {
float r, i;
} complex;
typedef struct {
double r, i;
} doublecomplex;
/* .................End of include file.................*/
/* SPA0301 */
#include "spaincl.h"
long pos_i8 = 8;
/* Initialized data */
float x[8] = { -6.0, -2.0, 0.0, 2.0, 4.0, 6.0, 3.0, -1.0 };
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void spdftr();
long m;
complex y[5];
/* DEMONSTRATION OF THE USE OF SUBROUTINE SPDFTR. */
spdftr(x, y, &pos_i8);
printf(" M REAL IMAGINARY\n");
for (m = 0 ; m <= 4 ; ++m)
{
printf("%2ld %10.4f %10.4f\n", m, y[m].r, y[m].i);
}
}
/* SPA0302 */
#include "spaincl.h"
long pos_i8 = 8;
/* Initialized data */
float x[10] = { -6.0, -2.0, 0.0, 2.0, 4.0,
6.0, 3.0, -1.0, 0.0, 0.0};
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void spfftr();
long m;
/* DEMONSTRATION OF THE USE OF SUBROUTINE SPFFTR. */
spfftr(x, &pos_i8);
printf(" M REAL IMAGINARY\n");
for (m = 0 ; m <= 9 ; m += 2)
{
printf("%2ld %10.4f %10.4f\n", m / 2, x[m], x[m+1]);
}
}
/* SPA0303 */
#include "spaincl.h"
long pos_i8 = 8;
/* Initialized data */
float x1[8] = { -6.0, -2.0, 0.0, 2.0, 4.0, 6.0, 3.0, -1.0 };
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void spdftr(), spidtr();
long k;
complex y[5];
float x2[8];
/* DEMONSTRATION OF THE USE OF SPIDTR. */
spdftr(x1, y, &pos_i8);
spidtr(y, x2, &pos_i8);
printf(" K X(K)\t K X(K)\n");
for (k = 0 ; k <= 3 ; k++)
{
printf("%2ld %6.1f\t%2ld %6.1f\n", k, x2[k], k + 4, x2[k + 4]);
}
}
/* SPA0304 */
#include "spaincl.h"
long pos_i8 = 8;
/* Initialized data */
float x[10] = { -6.0, -2.0, 0.0, 2.0, 4.0, 6.0, 3.0, -1.0, 0.0, 0.0 };
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void spfftr(), spiftr();
long k;
/* DEMONSTRATION OF THE USE OF SUBROUTINE SPIFTR. */
spfftr(x, &pos_i8);
spiftr(x, &pos_i8);
printf(" K X(K)\t K X(K)\n");
for (k = 0 ; k <= 3 ; k++)
{
printf("%2ld %6.1f\t%2ld %6.1f\n",k, x[k], k + 4, x[k + 4]);
}
}
/* SPA0305 */
#include "spaincl.h"
long neg_i1 = -1;
long pos_i1 = 1;
long pos_i4 = 4;
/* Initialized data */
complex x1[4] = { {2.0, 1.0 },{0.0, 2.0 },
{1.0, 1.0 },{-1.0, 0.0 } };
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void spdftc();
long i;
complex x2[4];
/* DEMONSTRATION OF THE USE OF SUBROUTINE SPDFTC. */
spdftc(x1, x2, &pos_i4, &neg_i1);
spdftc(x2, x1, &pos_i4, &pos_i1);
printf(" I X1(I)\t\t X2(I)\n");
for (i = 0 ; i <= 3 ; i++)
{
printf("%2ld %4.1f %4.1f %12.7f %12.7f\n",
i, x1[i].r, x1[i].i, x2[i].r, x2[i].i );
}
}
/* SPA0306 */
#include "spaincl.h"
long neg_i1 = -1;
long pos_i1 = 1;
long pos_i4 = 4;
/* Initialized data */
complex x1[4] = { {2.0, 1.0 },{0.0, 2.0 },
{1.0, 1.0 },{-1.0, 0.0 } };
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void spfftc();
long i, m;
complex x2[4];
/* DEMONSTRATION OF THE USE OF SUBROUTINE SPFFTC. */
spfftc(x1, &pos_i4, &neg_i1);
for (m = 0 ; m <= 3 ; ++m)
{
x2[m].r = x1[m].r;
x2[m].i = x1[m].i;
}
spfftc(x1, &pos_i4, &pos_i1);
printf(" I X1(I)\t\t X2(I)\n");
for (i = 0 ; i <= 3 ; i++)
{
printf("%2ld %4.1f %4.1f %12.7f %12.7f\n",
i, x1[i].r, x1[i].i, x2[i].r, x2[i].i);
}
}
/* SPA0307 */
#include "spaincl.h"
long pos_i8 = 8;
/* Initialized data */
float x[8] = { -6.0, -2.0, 0.0, 2.0, 4.0, 6.0, 3.0, -1.0 };
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
long m;
complex spcomp(), y;
float tmp_float;
/* DEMONSTRATION OF THE USE OF COMPLEX FUNCTION SPCOMP */
printf(" M REAL IMAGINARY\n");
for (m = 0 ; m <= 4 ; ++m)
{
tmp_float = m / 8.0;
y = spcomp(x, &pos_i8, &tmp_float);
printf("%2ld %10.4f %10.4f\n", m, y.r, y.i);
}
}
/* SPA0401 */
#include "spaincl.h"
long pos_i1 = 1;
long pos_i16 = 16;
long pos_i31 = 31;
float f0 = 0.0;
float pos_fp03125 = 0.03125;
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void sppowr();
long k, error, nsgmts, number_points;
float work[34], x[32], y[17];
/* GENERATES A PERIODOGRAM SIMILAR TO FIG. 4.1. */
for (k = 0 ; k <= 31 ; ++k)
{
x[k] = (float) sin(2.0 * M_PI * (double) k / 8.0);
}
sppowr(x, y, work, &pos_i31, &pos_i16, &pos_i1, &f0, &nsgmts, &error);
printf(" NSGMTS,IERROR= %ld %ld\n", nsgmts, error);
printf(" Y=");
for (k = 0 ; k <= 16 ; ++k)
{
if ( k == 8 )
{
printf("\n ");
}
printf("%7.3f", y[k]);
}
printf("\n");
number_points = 17;
pfile2(&f0,&pos_fp03125,y,&number_points,&pos_i1,"P0401A");
}
/* SPA0402 */
#include "spaincl.h"
long pos_i1 = 1;
long pos_i16 = 16;
long pos_i999 = 999;
float f0 = 0.0;
float pos_fp03125 = 0.03125;
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void sppowr();
long k, m, error, nsgmts, number_points;
long seed;
float work[34], x[1000], y[17];
double ex2, sprand(), tpower;
/* POWER DENSITY SPECTRUM OF WHITE UNIFORM NOISE. */
seed = 12357;
ex2 = 0.0;
for (k = 0 ; k <= 999 ; ++k)
{
x[k] = (float) (6.0 * (sprand(&seed) - 0.5));
ex2 += (double) (x[k] * x[k] / 1000.0);
}
sppowr(x, y, work, &pos_i999, &pos_i16, &pos_i1, &f0, &nsgmts, &error);
tpower = (double) ((y[0] + y[16]) / 32.0);
for (m = 1 ; m <= 15 ; ++m)
{
tpower += ((double) y[m] * 2.0 / 32.0);
}
printf(" IERROR,NSGMTS= %ld %ld\n", error, nsgmts);
printf(" Y=");
for (k = 0 ; k <= 16 ; ++k)
{
if ( k == 8 )
{
printf("\n ");
}
printf("%7.3f", y[k]);
}
printf("\n");
printf(" ACTUAL POWER, ESTIMATED POWER: %7.3f %7.3f\n", ex2, tpower);
number_points = 17;
pfile2(&f0,&pos_fp03125,y,&number_points,&pos_i1,"P0402A");
}
/* SPA0403 */
#include "spaincl.h"
long pos_i1 = 1;
long pos_i16 = 16;
long pos_i999 = 999;
float f0 = 0.0;
float pos_fp03125 = 0.03125;
float pos_fp5 = 0.5;
#ifndef KR
main(void)
#else
main()
#endif
{
/* Local variables */
void sppowr();
long k, m, error, nsgmts, number_points, work[34];
long seed;
float x[1000], y[17];
double signal, sprand(), tmp_double;
/* POWER DENSITY SPECTRUM OF SINE WAVE IN WHITE UNIFORM NOISE. */
seed = 12357;
for (k = 0 ; k <= 999 ; ++k)
{
signal = sin(3.0 * M_PI * (double) k / 16.0) +
0.5 * sin(7.0 * M_PI * (double) k / 16.0);
tmp_double = sqrt(0.12) * (sprand(&seed) - 0.5);
x[k] = (float) (signal + sqrt(0.12) * (sprand(&seed) - 0.5))