Why does this Matlab snippet create biased Fourier waveforms?

Click For Summary
SUMMARY

The discussion centers on a Matlab snippet that generates Fourier waveforms using 20 parameters, including 9 sine and 9 cosine Fourier coefficients, a frequency parameter (w), and a phase parameter (p). The parameters are uniformly randomized within specified ranges. The original issue was a perceived bias in the generated waveforms, where values were greater than 0 more than 50% of the time. Upon further inspection, the user identified an error in their code that caused the bias, which was resolved by correcting the multiplication factor applied to the parameters.

PREREQUISITES
  • Understanding of Fourier series and coefficients
  • Familiarity with Matlab programming and syntax
  • Knowledge of random number generation in programming
  • Basic concepts of waveform generation and analysis
NEXT STEPS
  • Explore Matlab's rand() function and its implications on random number generation
  • Study Fourier series and their applications in signal processing
  • Learn about parameter tuning in waveform generation
  • Investigate common pitfalls in numerical programming and debugging techniques
USEFUL FOR

Matlab programmers, signal processing engineers, and anyone interested in waveform generation and analysis will benefit from this discussion.

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!
 
Physics news on Phys.org


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!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
19K
  • · Replies 2 ·
Replies
2
Views
15K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K