-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultSignal.pde
More file actions
80 lines (65 loc) · 2.1 KB
/
Copy pathDefaultSignal.pde
File metadata and controls
80 lines (65 loc) · 2.1 KB
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
static class DefaultSignal {
// c
public static float[] constant(float c, float tStart, float tStop, float Fs) {
int i, N;
float Ts, y[];
Ts = 1 / Fs;
N = (int)((tStop - tStart) * Fs);
y = new float[N];
for(i = 0; i < N; i++)
y[i] = c;
return(y);
}
// A*sin(b*t + c)
public static float[] sine(float A, float b, float c, float tStart, float tStop, float Fs) {
int i, N;
float Ts, y[];
Ts = 1 / Fs;
N = (int)((tStop - tStart) * Fs);
y = new float[N];
for(i = 0; i < N; i++)
y[i] = A * sin(b*(tStart + Ts*i) + c);
return(y);
}
// A*cos(b*t + c)
public static float[] cosine(float A, float b, float c, float tStart, float tStop, float Fs) {
int i, N;
float Ts, y[];
Ts = 1 / Fs;
N = (int)((tStop - tStart) * Fs);
y = new float[N];
for(i = 0; i < N; i++)
y[i] = A * cos(b*(tStart + Ts*i) + c);
return(y);
}
// A*rect(b*t + c)
public static float[] rect(float A, float b, float c, float tStart, float tStop, float Fs) {
int i, N;
float t, Ts, y[];
Ts = 1 / Fs;
N = (int)((tStop - tStart) * Fs);
y = new float[N];
for(i = 0; i < N; i++)
{
t = b*(tStart + Ts*i) + c;
y[i] = ((t >= -0.5) && (t <= 0.5))? A : 0;
}
return(y);
}
public static float[] signal(int sig, float A, float b, float c, float tStart, float tStop, float Fs) {
switch(sig) {
case 0 : return(constant(c, tStart, tStop, Fs));
case 1 : return(sine(A, b, c, tStart, tStop, Fs));
case 2 : return(cosine(A, b, c, tStart, tStop, Fs));
default: return(DefaultSignal.rect(A, b, c, tStart, tStop, Fs));
}
}
public static float[] setSignal(int sig) {
switch(sig) {
case 0 : return(constant(0, plotTstart, plotTstop, plotPoints));
case 1 : return(sine(1, 2*PI*10, 0, plotTstart, plotTstop, plotPoints));
case 2 : return(cosine(1, 2*PI*10, 0, plotTstart, plotTstop, plotPoints));
default: return(DefaultSignal.rect(1, 20, 0, plotTstart, plotTstop, plotPoints));
}
}
}