Skip to main content
GameDev.net gamedev.net
🔒 Locked

*SIMPLE* FFT noise sample *SIMPLE*

Started by Grizwald Oct 17, 2003 at 3:48 PM 6 replies 1.5k views
Original Post
Grizwald
Grizwald
can anyone point me in the direction of an FFT noise generator (preferably 2D) that is REALLY simple. I''ve looked at many articles, but i haven''t learned higher math notation as of yet. So i need to see some good ol'' C(++) code. Thanks
I love me and you love you.
Grizwald
Grizwald
does anyone at all know!? ANYONE?
I love me and you love you.
uutee
uutee
>>I''ve looked at many articles, but i haven''t learned
>>higher math notation as of yet. So i need to see some
>>good ol'' C(++) code

"I don''t want to learn the basics, I just want to use your code and come back whining when the code doesn''t work (or when I need to know more) because I don''t know the fundamentals behind the subject."

See this and the links associated with it: http://astronomy.swin.edu.au/~pbourke/terrain/freqland/

The idea is to simply generate a random signal and smooth out the higher frequency components.

- Mikko Kauppila
Grizwald
Grizwald
even though i was mildly insulted i''ll thank you none-the-less. The page you linked to wasn''t much help, but 2D FFT at the top was. Now i must continue trying to learn this math
I love me and you love you.
Hoser
Hoser
What is your current mathematics background? If you let us know where you stand, we could point you in the right direction as to what you should try and grasp first before jumping into Fourier analysis.
Grizwald
Grizwald
I barely have a pre-calc background
but i have a firm grasp on algebra and trig, and if i can see a concept written in a notation i understand (like code for instance) i can generally play around with it and see what makes it tick. I''ve been reading up on limits and some other calculus stuff, but we''ll see how this goes
I love me and you love you.
little_jo
little_jo
I don''t think it takes a genius to understand the basics and how to use the algorithm.

What follows is a very simple idea of how it works, I am not going to go into technical details too much, I am just giving you a heads up of how it mostly works, which should help you get started in understanding how to use it.

All you need to know is what the transform does. You don''t even need to understand how it is coded to use it. There are plenty of codes already out there to be used. Look for FFTW it is one of the best libraries around and is easy to use.

All the FFT is, is a fast algorithm to compute the Discrete Fourier transform.
The discrete fourier transform is a special case of the Fourier transform that works in computers (discrete machines).

The fourier transform is a beautifal theory, that given almost any function, you can break it down into a series of sinewaves that when you add them up, you get the function. The inverse takes all the sine waves, and adds them up to the function again.

The simplest wave is the sin and cosine, which are the fundamental frequency and have no other harmonics. A cosine wave is a sin wave that has a different starting point, and this is called the phase of a waveform. A cosine is a sine wave 90 degrees out of phase (or vice versa). You can see it, cos(0) = 1, sin(0) = 0. Cos(pi/2) = 0, sin(pi/2) = 1. Remember, a radian into degrees is
x*180/pi, so (pi/2)*180/pi = 180/2 = 90 degrees right? A radian, if you forget, is a measure about a circle. 2*pi radians is a complete circle. If you plot out a sine wave from 0 to 2*pi, and then fold it around, you get a circle :-)

amplitude of a sine wave is how big it gets on the y axis. Plot a sine wave of amplitude one, it alternates between -1 and 1. Multiply it by 15, and now you got a sine wave that alternates on the y axis between 15 and -15
as it goes around the circle.

You may have heard of a square wave. This is a formula, of sine waves with certain frequencies (harmonics) and amplitudes, when added togethor, you get this waveform. If you were to do a FFT on it, this is called a spectrum, and if you play with winamp, you will now see that when you see the spectrum analyzer, it is in fact the FFT that does it.

Harmonics are multiples of the fundamental frequency added to it. In a square wave, they decrease quickly at a certain rate as the frequency gets higher (and is a multiple of the base frequency. If you have a square wave which is middle A (which is 440hz) you will get the first harmonic at 880hz, whose amplitude is proportional less than the fundamental, and so on, up until the nyquist limit, which is to say, the maximum frequency you can represent at a given sample rate).

Sound are waves, they carry an amplitude (how loud you might perceieve it or how forceful it is), and a frequency (how high or low it sound, a low frequency is deep like bass, and a high frequency is shrill and piercing). Single sine waves are very pure sounding and almost like flutes sound like at times.

The FFT takes someting in one domain and places it into a frequency domain. If you do sound stuff, you will have time domain and frequency domain. An interesting thing is that multiplication in one of those domains is convulution in the other, and it is an important thing to remember. Filtering in the time domain is convultion in the frequency domain, and that is how filters work. FIR - finite impulse reponse, and IIR - infinite impulse reponse, are the types of filters you would think about doing DSP codings.

First you fill up your array with some number of samples. Most FFT algorithms only work on powers of two. So, you might have an FFT that uses 512 bins.
Than stick these samples into the FFT and it computes the sinusoids whose amplitude is relative to the frequency of that bin.

The circle is a pain, because it introduces aliasing in another complex domain. An alias is not usually something you want. It is a folding of a frequency above the nyquist to an arbitrary frequency below it, and is almost always an inharmonic and unpleasant sound.

The FFT transforms these samples into sine waves. These are all the sine waves that the function (signal) was made of. The FFT just does the DFT very fast. You can do it with the DFT, it is just very slow compared.

The frequency of a bin is proportional to the sampling rate. If your sample rate was 44100, and you use 512 bins, you would get 22050/256 per bin, because the FFT wraps around halfway and the second half is the mirror of the first, and in digital, you can only represent a maximum signal that is half the sample rate.

Now what you got is the relative magnitude of the sinusoids in the centered around the bins. The transform has seperated your samples into individual sine waves at various frequencies and amplitudes. Notice that they get smeared, the larger the amount of bins you use, the more detail you can get.

The other way is called the Inverse FFT. After doing the FFT, and than performing some calculations on it etc. You do the inverse, which takes those bins and returns them to samples again. It has taken all those sinewaves and turned them back into a signal in the time (or whatever) domain it was in.

Now noise has various definitions. The simplest type of noise is called White Noise. This is just truly random sinewaves added togethor all over the place. If you saw a TV with no channel and all that static, you have seen and heard white noise.

Other types of noise, one of them, is called pink noise. Perlin noise is based on pink noise of some sort.

But I think fBm and fractal generators are easier to use and give good results too. 2-dimensional FFT stuff is hard, but if you look at google for image processing with FFT you can get ideas how to do it.

That is the basic, non-technical as much as possible, explanation, and you see if you look at it like that you don''t need much more than algebra and trig to use it and understand it. If I made any mistakes I apologize, I am usually good at doing that :-)



"Never once did I give them hell. All I did was tell them the truth, and they thought it was hell."
Harry S. Truman
"Never once did I give them hell. All I did was tell them the truth, and they thought it was hell."Harry S. Truman
Grizwald
Grizwald
thank you soooo much. I really appreciate that.
I love me and you love you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.