473,563 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fast 2d brown/pink noise generation?

Dear NG,

I'm looking for a fast way to produce 2d-noise images with 1/f or 1/f^2
spectrum. I currently generate the noise via inverse FFT, but since I
need lots of data (~10^7 for a monte carlo simulation) it needs to be
really fast. Does someone know a faster way than my approach?

- Dimensionality is between 20x20 and 100x100
- The spectrum doesn't need to be exactly pink/brown, an approximation
is fine.
- Implementation in either matlab or scientific python (LAPACK anyway)
Thanks a lot for hints, literature, algorithms!
Mathias

Jul 18 '05 #1
1 5479
Mathias wrote:
Dear NG,

I'm looking for a fast way to produce 2d-noise images with 1/f or 1/f^2
spectrum. I currently generate the noise via inverse FFT, but since I
need lots of data (~10^7 for a monte carlo simulation) it needs to be
really fast. Does someone know a faster way than my approach?

- Dimensionality is between 20x20 and 100x100
- The spectrum doesn't need to be exactly pink/brown, an approximation
is fine.
- Implementation in either matlab or scientific python (LAPACK anyway)


This is a 1D version that I have using scipy. It's naive, so I'm sure
that it is slower. However, I believe the general technique can be
implemented on a larger scale.

The basic idea is to sum up a bunch of white time series with different
time steps. The first level is white noise at every time step. The
second level changes at every second time step. The third changes at
every fourth, etc.

I think you can replicate this by generating a few white noise arrays of
the appropriate sizes, judiciously using repeat(), and summing them
together. I got this scheme from an article I found by googling for pink
noise algorithms, I believe.

from scipy import *

class PinkGenerator(o bject):
updateTable = [0,1,0,2,0,1,0,3 ,0,1,0,2,0,1,0, 4]
updateTable.ext end(updateTable[:-1])
del updateTable[-1]

def __init__(self, rng=stats.norm) :
self.key = 0
self.rng = rng
self.whiteValue s = self.rng.rvs(si ze=5)

def getNextValue(se lf):
self.key += 1
self.key = self.key % len(self.update Table)
self.whiteValue s[self.updateTabl e[self.key]] = self.rng.rvs()[0]
return (sum(self.white Values) + self.rng.rvs()[0])/6

def getManyValues(s elf, size):
data = zeros((size,), Float)
for i in range(size):
data[i] = self.getNextVal ue()
return data

def sampleData(self , size=1024):
data = self.getManyVal ues(size)
p = power(absolute( fftshift(fft(da ta))), 2)/size
f = fftshift(fftfre q(size))
return data, f, p

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
4856
by: Michele Simionato | last post by:
I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C, so I would like to now if something is wrong on my old laptop and if anybody can reproduce my results. Here are I my numbers for calling the error function a...
7
1733
by: drewnoakes | last post by:
I have an application that performs custom deserialisation of object state from byte arrays. This happens very regularly, so needs to be fast. In addition, most of the strings repeat, meaning I'm deserialising the same sequence of bytes repeatedly, giving the same output string. Let's ignore the text encoding method, as it's not relevant to...
20
9123
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg., int_fast32_t 4) integer capable of holding a pointer, intptr_t 5) widest integer in the implementation, intmax_t Is there a valid motivation for...
1
1762
by: macyp | last post by:
I am developing a search page. If the users enter, words like "and", "an" etc, it gives an error. I read something abt noise words. I want to display a friendly error message to the users if they enter noise words. I am storing all the noise words in an array, and string comparing the keyword the user entered with each element of the array,...
1
1591
by: Peter Strĝiman | last post by:
Hi. I have an Sql server 2005 beta2 problem with the full-text index functionality. I have a table with a full text index. In the definition of the full-text index, I have specified the neutral language. The problem domain specifies that texts can be in arbitrary languages. create fulltext index on mytable
13
2973
by: Frode Ĝijord | last post by:
Hi all, given a sequence of n elements i need to generate all possible permutations of length k <= n. I found an elegant way to do this recursively: def comb(items, n): if n==0: yield else: for i in xrange(len(items)):
4
3590
by: Alexis Gallagher | last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if this is a double-post.) Is it possible to do very fast string processing in python? My bioinformatics application needs to scan very large ASCII files (80GB+), compare adjacent lines, and conditionally do some further processing. I believe the disk i/o is the main...
1
1017
by: =?Utf-8?B?TUFSWSBEQUhM?= | last post by:
After creating a project plan we noticed the icon for it was "pink", none of the others have this and now we notice we can't do Updates or edits to the project. Does anyone have any ideas?
8
14928
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to cut and paste code that MSDN recommends for playing a simple wav file from inside an embedded file, like presumeably the 'resources' file .resx is. ...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.