From 8e8171e4a41f5c598ff3f2715342cf8ab2f727f5 Mon Sep 17 00:00:00 2001 From: stevenj Date: Wed, 27 Mar 2002 21:48:51 -0500 Subject: [PATCH] add noise option -N --- sines.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sines.c b/sines.c index 5844b4c..f891a71 100644 --- a/sines.c +++ b/sines.c @@ -47,6 +47,7 @@ void usage(FILE *f) " -v : verbose output\n" " -T : specify periods instead of frequencies\n" " -r : random amplitudes\n" + " -N : add white noise with amplitude \n" " -n : output points (default %d * max period)\n" " -t
: time step
(default 1.0)\n", NPERIODS); @@ -70,11 +71,12 @@ int main(int argc, char **argv) int nsines = 0, nalloc = 0, n = 0; double max_period = 0; double dt = 1.0; + double noise = 0.0; int i, is; srand(time(NULL)); - while ((c = getopt(argc, argv, "hVvTrn:t:")) != -1) + while ((c = getopt(argc, argv, "hVvTrn:t:N:")) != -1) switch (c) { case 'h': usage(stdout); @@ -93,6 +95,9 @@ int main(int argc, char **argv) case 'r': random_amplitudes = 1; break; + case 'N': + noise = atof(optarg); + break; case 'n': n = atoi(optarg); if (n < 1) { @@ -175,6 +180,7 @@ int main(int argc, char **argv) output += sines[is].amplitude * cexp(I * (sines[is].phase - TWOPI*sines[is].freq * i*dt) - sines[is].decay * i*dt); + output += noise * (rand() * 2.0/RAND_MAX - 1); printf("%0.17e+%0.17ei\n", creal(output), cimag(output)); }