Reversing Bit for FFT in Python

18 01 2008

I always found this Fast Fourier Transform (FFT) business a little foggy. Now what happened is that on my new Leopard distribution after the installation of Matplotlib I found that I had the fft function but not the ifft function… So in the end I took the legendary Numerical Recipes book and I started to convert the C++ version in python. Well, let me say that it wasn’t that trivial since the C++ version was based on vectors with intercalated real and imaginary parts which were messing up the understanding of the indexes in some of the for loops… In the end I managed. Here is the code for the function needed: you need a function to rearrange the input vector reversing position according their number in binary format (i.e. 0101 goes into 1010 and 0001 into 1000 etc.)… here is the code:

"""
This function serves as a base for the calculation of FFT. It simply
swaps vector elements just according to their position expressed in
binary digits. For example using a vector of lenght 16 (4 bits), the
vector element 4 = 0100 transforms into 0010 = 2 and 10 = 1010 goes
into 0101 = 5 and so on...
"""
def bitReverse(x):

	xn = 1.0*x
	N = int(len(xn))
	if N%2 != 0: raise ValueError, 'N is not power of 2'
	j = 0
	for i in range(0,N):
		if j>i:
			shelf = xn[j]
			xn[j] = xn[i]
			xn[i] = shelf
		m = N/2
		while (m >= 2 and j > m-1):
			j = j-m
			m = m >> 1
		j += m

	return xn




Hysteric Avocado Sauce

18 11 2007

Avocados

 La cena deve iniziare con un aperitivo degno di nota, di gusto, di carattere… un po’ esotico magari. Questo e’ quello che stavi cercando. La musica consigliata per la preparazione sono i Gotan Project con le loro note calde, un po’ magiche.

Ingredienti:

  •  1 avocado
  • 1/4 di cipolla
  • 1/2 pomodoro
  • 1 lime
  • tabasco
  • olio di oliva
  • pepe

Preparazione:quindi si comincia con il pelare l’avocado. Si taglia grosolanamente la polpa in pezzi. La stessa cosa va fatta per il pomodoro privato dei semi e del quartino di cipolla. Mettere il tutto nel bicchire di un mixer e frullare il tutto aggiungendo il succo di un lime e l’olio di oliva. Gradualmente si aggiunge poi il tabasco e si continua a frullare fino a quando la salsa non raggiunge il livello desiderato di piccantezza. Notare che la spicy sensation arriva in ritardo rispetto al gusto dell’avocado e dovrebbe essere solo una “sensation” e non uno shock… Si puo’ regolare la sapidita’ e aggiungere del pepe e/o del coriandolo. L’ideale e’ servire con patatine messicane poco piccanti.

 





Peperonata Old Style

18 11 2007

 RedPepper

La peperonata Old Syle e’ un classico intramontabile. E chi se ne frega se e’ intramontabile anche per lo stomaco… Veramente mitica!Instructions:

  •  Pulire i peperoni (tavolozza di colori a piacere…) e tagliarli a pezzi;
  • mettere un po’ di olio in una casseruola e fare imbiondire due spicchi di aglio;
  • togliere l’aglio e aggiungere i peperoni;
  • lasciare cuocere con il coperchio finche’ l’acqua dei peperoni non sara’ completamente evaporata;
  • salare, pepare e aggiungere capperi e olive nere.

Una variante prevede l’aggiunta di un paio di pomodori assieme ai peperoni. Ma resta sempre Old Style e sempre deliziosa.





Green Pepper Filetto

18 11 2007

Ingredienti per 4 persone:

  •  4 fette di filetto (~150 g l’una)
  • 4 cucchiai di pepe verde in grani
  • 4 cucchiai di brandy
  • 1 dl di panna fresca
  • 4 g di burro
  • sale q.b.

Preparazione:

  • Schiacciare meta’ dei grani di pepe e comprimerli su entrambi i lati dei filetti;
  • fare sciogliere il burro e cuocere i filetti a fuoco vivace per circa 3 minuti su ogni lato. In seguito togliere i filetti dal fuoco e tenere al caldo;
  • nella stessa padella unire il brandy e farlo fiammeggiare. Quando la fiamma si e’ spenta unire la panna, il pepe rimasto e il sale e lasciare addensare il tutto.
  • aggiungere per finire i filetti con il loro sughetto e lasciare insaporire per un paio di minuti. 

Servire ben caldo.





Torta a misura Yogurt

18 11 2007

Tra le varie unita’ di misura nel Sistema Internazionale c’e', ma guarda un po’, il Vasetto di Yogurt che sara’ definito d’ora in avanti VY. Ecco dunque una torta pensata e creata a misura di vasetto di yogurt… Ingredienti:

  •  2 VY (gusto a piacere)
  • 3 VY di zucchero
  • 5 VY di farina (4 farina + 1 fecola)
  • 1 VY di olio di semi
  • 3 uova (qui il vasetto e’ un po’ difficile da usare…)
  • 1 bustina di lievito per dolci
  • 1 buccia di limone grattugiata
  • 1 bustina di vanillina

Mescolare tutti gli ingredienti fino ad ottenere una crema spessa, densa e priva di grumi. Versare il tutto in uno stampo per torte imburrato o foderato di carta da forno. Cuocere per 180 gradi per 50 minuti circa. La superficie deve risultare dorata e crepata. Fantastica nel latte caldo la mattina.





Pizza Time

18 11 2007

Pizza Time 

Ingredienti:

  •  450 g di farina tipo “00″ + 50 g per l’impasto
  • 2.5 dl di acqua
  • 1 cc di sale
  • 1 cubetto di lievito di birra sciolto in 2 dita di acqua tiepida e 1/2 cc di ingrediente segreto
  • 3 cz di olio di oliva

Impastare il tutto e lasciare riposare poi la pasta per 3 ore prima di stendere, condire, infornare  a 180 gradi (in orizzontale certo…), aspettare 15-20 minuti e infine mangiare! La birretta fresca-fresca e’ un di piu’, una partita alla TV un extra, gli amici un lusso.





Lussureggianti sonorità spagnole anni Ottanta

9 05 2007

The Gang

Dopo serate e serate anni ottanta con tanto di colonna sonora “Rhythm is a dancer” degli Snap (in realtà ci eravamo già chiesti “cosa resterà degli anni ottanta” visto che era il ‘92…) ecco cosa resta di tanto sballo, di tante droghe, di ambienti allucinanti come non mai, di onde alcoliche, di tavole imbandite, di banditi con le tavole, di sonorità spagnole che quasi non si notano neanche, di flamenco, di mojto, di sangria, di sudore, calore… Una girandola di forchette, tazzine, vasi, cubetti di ghiaccio… e che la festa continui! Nonostante… GOT 30… but just … 30…

Clicca sul floppy e scarica subito questa magnifica collezione! Puoi vincere uno degli splendidi cavatappi in ghisa per dare un peso alle tue serate importanti!

Pictures… Got 30.





Tributo al Baffo

9 05 2007

Magnum and Me

Prima di incominciare a scrivere della festa di sabato scorso ecco qui il mio doveroso tributo al “baffo anni 80″. Allora cosa facciamo!? Lo rilanciamo o no!? Il baffo e il capello riccio ci sono, ora mi devo solo procurare dei bigodini speciali per i peli sul petto e un cellulare da spiaggia… gorgeous!

Non mi resta ora che fare un po’ di pub al sito che ha lanciato tutto questo delirio del “baffo anni 80″… Enjoy!





Deep into the Mac World…

25 05 2006

I need to add extra comments on my personal discovery of the Mac world. First of all I'm using Microsoft Win since I was 16 and now, after 13 years would be difficult to discover a new system… or may be discover AND appreciate it. But listen to me: it's magic!

My Mac!

After a little problem with my shortname (but apparently is quite common for novices) I finally installed all the programs. What I mean with all!? Well, I mean all the programs that are stupid basically but that keep us attached to the old Window, like MSN, skype, Firefox etc. But don't panic, I found everything in the net. And everything is perfectly working!

Since I'm a researcher i also looked up for scientific software and the scenario is not bad at all! A lot of programs free and also an high quality!

I'm not a big fan of MS Office but I know that it is spread and using different applications could bring you into a sort of incompatibility state with the rest of the world… well there is also MS Office for OS X. But ok, maybe it's fundamental to have Office on Mac but just try to give a look to iWork and to its Powerpoint like program… After doing that you'll certainly think that powerpoint is just crap.

Personally I feel more and more fascinated by this Mac-World. I should have thought about it before! But it's not to late, it's never too late!





Waiting for a Mac

25 05 2006

Right! I did it… Finally I bought a MAC. WOW! After years of doubts and sleepless nights (!!!) thinking about the mistery behind the MAworld I finally decided to buy a second hand 12'' Powerbook.

On eBay you can really find very good deals expecially now that the new Intel processor powerbook serie is in the shop. You can safely go for a G4 processor and your computer will work perfectly even with the most advanced OS X (Tiger in my case).

So I received yesterday my Mac! It looks great and I wouldn't define it a second hand computer… It's really mint-like! The only thing that I had to add was a airport extreme card for wireless connection and a ram module, for the rest everything was perfect. The installation of the card was easy and the pc immediately recognized the new hardware. I set up all the parameters for the wireless router and I was on the NET! Easy, fast, zero problems! What would you ask more!?

So… First impression: Impressive.

Good surprise: the UNIX core (I'm so happy!!!)

Now I'm already thinking to sell my vaio and buy a 15'' PB… ;-)