- #1
Andrew732
- 9
- 0
Why does this Matlab snippet create "biased" Fourier waveforms?
I'm trying to search through the space of all possible waveforms (or a reasonable approximation of that space), where waveforms are described by 20 parameters: the first 9 Fourier coefficients for sine terms a(1:9), the first 9 Fourier coefficients for cosine terms b(1:9), a frequency parameter w, and a phase parameter p. The range of the parameters are uniform random over the range [-0.2, 0.2] for each element in a and b, [-1, 1] for w, and [-2 * pi, 2 * pi] for p. The Matlab code that creates a waveform using the parameters is simply:
This makes waveforms that are fine for my purposes except for a bias that I have noticed over thousands of runs and that I can't explain. Given the uniform random values for the parameters, why would the values of the waveform be greater than 0 significantly more often than 50% of the time? This is not a homework question, just something that's come up in a program I'm writing. I'm mostly just curious and am probably doing something dumb. Thanks for any help!
I'm trying to search through the space of all possible waveforms (or a reasonable approximation of that space), where waveforms are described by 20 parameters: the first 9 Fourier coefficients for sine terms a(1:9), the first 9 Fourier coefficients for cosine terms b(1:9), a frequency parameter w, and a phase parameter p. The range of the parameters are uniform random over the range [-0.2, 0.2] for each element in a and b, [-1, 1] for w, and [-2 * pi, 2 * pi] for p. The Matlab code that creates a waveform using the parameters is simply:
Code:
t = 0:0.1:10;
wave = zeros(1, numel(t));
for count = 1:9
s = a(count) * sin(count1 * w * t + p);
s = s + b(count) * cos(count1 * w * t + p);
wave = wave + s;
end
This makes waveforms that are fine for my purposes except for a bias that I have noticed over thousands of runs and that I can't explain. Given the uniform random values for the parameters, why would the values of the waveform be greater than 0 significantly more often than 50% of the time? This is not a homework question, just something that's come up in a program I'm writing. I'm mostly just curious and am probably doing something dumb. Thanks for any help!