-
Notifications
You must be signed in to change notification settings - Fork 185
/
makewavs.c
116 lines (101 loc) · 2.91 KB
/
makewavs.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**********************************************/
/** Utility to make various flavors of **/
/** sine wave (rectified, etc), and **/
/** other commonly needed waveforms, like **/
/** triangles, ramps, etc. **/
/** The files generated are all 16 bit **/
/** linear signed integer, of length **/
/** as defined by LENGTH below **/
/**********************************************/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define LENGTH 256
#define PI 3.14159265358979323846
void main()
{
int i,j;
double temp;
short data[LENGTH + 2];
FILE *fd;
/////////// Yer Basic TX81Z Waves, Including Sine ///////////
fd = fopen("halfwave.raw","wb");
for (i=0;i<LENGTH/2;i++)
data[i] = 32767 * sin(i * 2 * PI / (double) LENGTH);
for (i=LENGTH/2;i<LENGTH;i++)
data[i] = 0;
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("sinewave.raw","wb");
for (i=LENGTH/2;i<LENGTH;i++)
data[i] = 32767 * sin(i * 2 * PI / (double) LENGTH);
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("sineblnk.raw","wb");
for (i=0;i<LENGTH/2;i++)
data[i] = data[2*i];
for (i=LENGTH/2;i<LENGTH;i++)
data[i] = 0;
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("fwavblnk.raw","wb");
for (i=0;i<LENGTH/4;i++)
data[i+LENGTH/4] = data[i];
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("snglpeak.raw","wb");
for (i=0;i<=LENGTH/4;i++)
data[i] = 32767 * (1.0 - cos(i * 2 * PI / (double) LENGTH));
for (i=0;i<=LENGTH/4;i++)
data[LENGTH/2-i] = data[i];
for (i=LENGTH/2;i<LENGTH;i++)
data[i] = 0;
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("twopeaks.raw","wb");
for (i=0;i<=LENGTH/2;i++) {
data[LENGTH/2+i] = -data[i];
}
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("peksblnk.raw","wb");
for (i=0;i<=LENGTH/2;i++)
data[i] = data[i*2];
for (i=LENGTH/2;i<LENGTH;i++)
data[i] = 0;
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("ppksblnk.raw","wb");
for (i=0;i<=LENGTH/4;i++)
data[i+LENGTH/4] = data[i];
fwrite(&data,2,LENGTH,fd);
fclose(fd);
/////////// Impulses of various bandwidth ///////////
fd = fopen("impuls10.raw","wb");
for (i=0;i<LENGTH;i++) {
temp = 0.0;
for (j=1;j<=10;j++)
temp += cos(i * j * 2 * PI / (double) LENGTH);
data[i] = 32767 / 10.0 * temp;
}
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("impuls20.raw","wb");
for (i=0;i<LENGTH;i++) {
temp = 0.0;
for (j=1;j<=20;j++)
temp += cos(i * j * 2 * PI / (double) LENGTH);
data[i] = 32767 / 20.0 * temp;
}
fwrite(&data,2,LENGTH,fd);
fclose(fd);
fd = fopen("impuls40.raw","wb");
for (i=0;i<LENGTH;i++) {
temp = 0.0;
for (j=1;j<=40;j++)
temp += cos(i * j * 2 * PI / (double) LENGTH);
data[i] = 32767 / 40.0 * temp;
}
fwrite(&data,2,LENGTH,fd);
fclose(fd);
}