Why does this Matlab snippet create biased Fourier waveforms?

2 replies · 3K views · last reply
Andrew732
Messages
9
Reaction score
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:

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!
 


Well assuming that you're using the rand() function you should have like a 67% change of being within one standard deviation of 0.

What is the code that you are using to generate your interval of [-2*pi,+2*pi]?
 
Last edited:


Actually, phrasing the question forced me to take another look at my code and I discovered that I was multiplying everything by another factor, unlike in the code I actually posted, so there's no bias anymore. Thanks anyways!