473,701 Members | 2,405 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 5488
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
4871
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 million times (Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz): $ time p23 erf.py real ...
7
1743
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 my question. Right now, I'm using BinaryReader.ReadString() which gives the correct result,...
20
9154
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 having both int_least and int_fast?
1
1767
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, else redirecting them to a searchresults page. But when I am doing this, it is redirecting to the...
1
1599
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
2983
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
3606
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 bottleneck so for now that's what I'm optimizing. What I have now is roughly as follows (on python...
1
1022
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
14939
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. I want to embed the .wav file in a 'resource file' since I don't want the user storing the file on...
0
8733
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8975
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6569
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5904
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2398
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2035
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.