-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsptest.c
83 lines (69 loc) · 1.33 KB
/
sptest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// sptest.c - test sigpro library functions
#include <stdio.h>
#include <math.h>
#include "sigpro.h"
#define NP 1024
static void
linspace(float *x, int n, double a, double b)
{
int i;
double d;
d = (b - a) / (n - 1);
for (i = 0; i < n; i++) {
x[i] = a + i * d;
}
}
static void
cdb(float *x, float *y, int n)
{
double a;
int i, j, k, n2;
for (i = 0; i < (n / 2); i++) {
j = i * 2;
k = j + 1;
a = hypot(x[j], x[k]);
if (a < 1e-20) {
y[i] = -400;
} else {
y[i] = 20 * log10(a);
}
}
}
void
sp_copy(float *x, float *y, int n)
{
int i;
for (i = 0; i < n; i++) {
y[i] = x[i];
}
}
void
wr_spec(float *x, int n, double fs, char *fn)
{
float f[n + 1], y[n + 1];
int i, n1, n2;
FILE *fp;
sp_copy(x, y, n);
sp_rcfft(y, n);
n1 = n + 1;
linspace(f, n1, 0, fs);
n2 = n / 2;
cdb(y, y, n2);
fp = fopen(fn, "wt");
fprintf(fp, "; %s\n", fn);
for (i = 0; i < n2; i++) {
fprintf(fp, "%12.4g %12.4g\n", f[i], y[i]);
}
fclose(fp);
}
int
main(int ac, char **av)
{
float x[NP];
int i;
static double fs = 20000;
sp_randn(x, NP);
wr_spec(x, NP, fs, "spec1.txt");
wr_spec(x, NP, fs, "spec2.txt");
return(0);
}