   Frequency modulated Sine wave
  I'm generating a sine wave via Sin( FreqInHz * t * PI*2)and I want to modulate its frequency. When I do the following, the vibrato effect I expect to get increases its sweep every period, each time going to higher and higher frequency.ModulatingWave = Sin( 1Hz * t * PI*2 )MaximumVibratoAmount = 0.25HzVibratoHZ = MaximumVibratoAmount * ModulatingWaveModulatedWave = Sin( (440Hz + VibratoHZ) * t * PI*2)But it's as though MaximumVibratoHz continually increases as t increases. Why?Below is the spectrogram going from t = -15 to t = 15
  I had the same problem before, unfortunately, I don't remember how to fix it.  [embarrass]Try this:Sin( 440Hz * t * PI*2 + VibratoHZ )   ;  That works!I can't figure out why it works though. Aren't we just modulating the phase, without converting to radians? And still, I can't figure out why my math is bad on the first one. Thanks for the right formula though!!!   ;Quote:Original post by djzAnd still, I can't figure out why my math is bad on the first one. Thanks for the right formula though!!!It's nothing to do with converting to radians. Its because you were multiplying VibratoHZ by time which you dont want to do. (VibratoHZ would be better called VibratoDisplacement.)Have a look at this graph to see what I mean.;  In order to do frequency modulation, you generally want to have a variable that integrates the signal plus some offset, and then compute the sine of that variable. The offset determines what the carrier is.IntegratedSignal += (VibratoHZ + 440Hz) * dt;[EDIT: As you probably noticed, it should beIntegratedSignal += (VibratoHZ + 440Hz) * 2 * PI * dt;]ModulatedWave = Sin(IntegratedSignal);[Edited by - alvaro on April 8, 2010 6:46:45 AM];  Alavaro has a point; take a look at the functions (windowed at x=[0,15] and y=[-2,2]):And I bet the first sounds something like this:  http://fastcall.meg-tech.com/wtf.mp3*Makes for interesting sound effects though; take a look at the spectrum graph:(Warning: 5 MB png)*Audio sample is me demonstrating playing a few notes on an early prototype of my software synthesizer.   ;  Spectrographs of these types of sounds always remind me of sierpinski sieves...So, while I have frequency modulation working with Sin waves, I am having trouble controlling the HZ of the wave with an envelope. I get big jumps in frequency when the slope of the envelope changes. I mitigated this by using a spline for the envelope or using an LPF on the envelope, but I am trying to understand why I can't simply modify the HZ by the amount of EnvelopeHzAmount * Envelope(t) with Envelope(t) returning a value between 0...1say for t 0sec-2sec have a slope of 10Hz/sec and from 2-6 sec have a slope of (-1)*5Hz/sec; at 2sec, there is a jump of a few Hz.I can post the spectrographs later if I've been unclear...   ;  Are you doing what I said (integrating the signal plus some constant and then taking the sine)? If you are still naively multiplying t by the current desired frequency, you won't get anything reasonable.;Quote:Original post by alvaroAre you doing what I said (integrating the signal plus some constant and then taking the sine)? If you are still naively multiplying t by the current desired frequency, you won't get anything reasonable.I tried but I think I am misunderstanding the concept of integrating; or over thinking it.double Sin(double Hz, double t, double addHz){    double IntegratedSignal = (addHZ + Hz) * Math.PI*2 * t;    return Math.Sin(IntegratedSignal)}This doesn't seem to be working properly. I notice in what you posted you used the "+=" operator. Do I need to calculate something before adding (addHZ+Hz)*Math.PI*2*t to IntegratedSignal?If I could see what the "proper" code for the above function would be, that might help. I have a feeling there's a gap in my knowledge that I can't see for blindness that is stopping me from understanding....;  Okay, here's what I've figured with the help of Wolfram Mathematics; can you let me know if I'm right on this one?Integrated Signal = -Cos[Hz * 2 * Pi * T]---------------------Hz * 2 * PiSo I calculate that for the frequency Hz I want to modulate, then to THAT variable I add the DisplacementHz (as generated by another sinwave, or by an envelope) Output = Sin (  -Cos[Hz * 2 * Pi * T] + (DisplacementHz * 2*Pi * T ) )---------------------Hz * 2 * Piedit: Nope, that doesn't seem to work how I expect either... I am also wondering if maybe I'm looking at this the wrong way, in terms of practicality for implementing a soft-synth/audio-generator. What i'm trying boil down to is a function Sin(HZ,AddHZ,Time) where AddHz can be the output of another oscillator (sin) for FM, or alternatively, the value of Hz to add for an envelope. Is this even possible? Or should I treat FM as a special case, and use a different method for varying the Hz of the oscillator for envelopes?[Edited by - djz on April 7, 2010 7:41:48 PM]