Wednesday, April 3, 2019

How do you construct common waveforms (square, sawtooth, triangle, noise) from sine wave partials using an IFFT?


In the lovely image below we see the addition of sine waves making a square wave. I am coding a wave table synthesiser and thought it would be great to get the user to be able to fiddle with the values of the sine partials and then run an inverse FFT on them to produce the wave form.


enter image description here


I have some code for an FFT and you specify the number of buckets, real and imaginary arrays and the array length. The way it is used in the example is:



  • Imaginary array has all it's values set to 0


  • The real array has its 0th element set to 0

  • The real array has its arrayLength/2 element set to 0

  • Other values are set in the real array. Every time a value is set in the first half of the array one is set at the opposite end of the array, mirroring whatever is happening in the first half of the real array.

  • This spits out a single cycle of the waveform constructed using these sine partials


What are some common patterns for filling these partials to generate waveforms. How do you generate a square wave, a triangle wave, a sawtooth? Can you create noise or is that impossible if it is non periodic?


Extra: What are some tricks for producing 'good' waveforms? This is an opinion question, just a bonus if you have something to share about producing waveforms that sound good. (Good in your opinion :)


For those who would find it interesting there is a flash app here that lets you set the levels of the partials in order to construct waveforms, it's fun.




No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...