Ciao a tutti ho un problemino che non riesco a risolvere.
Ho queste 2 classi Cwt e Morlet:

class Cwt:
    fourierwl=1.00

    def _log2(self, x):
        # utility function to return (integer) log2
        return int( NP.log(float(x))/ NP.log(2.0)+0.0001 )

def __init__(self, data, largestscale=1, notes=0, order=2, scaling='linear'):
        """
        Continuous wavelet transform of data

        data:    data in array to transform, length must be power of 2
        notes:   number of scale intervals per octave
        largestscale: largest scale as inverse fraction of length
                 of data array
                 scale = len(data)/largestscale
                 smallest scale should be >= 2 for meaningful data
        order:   Order of wavelet basis function for some families
        scaling: Linear or log
        """
        ndata = len(data)
        self.order=order
        self.scale=largestscale
        self._setscales(ndata,largestscale,notes,scaling)
        self.cwt= NP.zeros((self.nscale,ndata), NP.complex64)
omega= NP.array(range(0,ndata/2)+range(-ndata/2,0))*(2.0*NP.pi/ndata)
        datahat=NP.fft.fft(data)
        self.fftdata=datahat
        for scaleindex in range(self.nscale):
            currentscale=self.scales[scaleindex]
            self.currentscale=currentscale  # for internal use
            s_omega = omega*currentscale
            psihat=self.wf(s_omega)
            psihat = psihat *  NP.sqrt(2.0*NP.pi*currentscale)
            convhat = psihat * datahat
            W    = NP.fft.ifft(convhat)
            self.cwt[scaleindex,0:ndata] = W
        return

    def _setscales(self,ndata,largestscale,notes,scaling):

        if scaling=="log":
            if notes<=0: notes=1
            # adjust nscale so smallest scale is 2
            noctave=self._log2( ndata/largestscale/2 )
            self.nscale=notes*noctave
            self.scales=NP.zeros(self.nscale,float)
            for j in range(self.nscale):
self.scales[j] = ndata/(self.scale*(2.0**(float(self.nscale-1-j)/notes)))
        elif scaling=="linear":
            nmax=ndata/largestscale/2
            self.scales=NP.arange(float(2),float(nmax))
            self.nscale=len(self.scales)
        else: raise ValueError, "scaling must be linear or log"
        return

    def getdata(self):
        return self.cwt
    def getcoefficients(self):
        return self.cwt
    def getpower(self):
        return (self.cwt* NP.conjugate(self.cwt)).real
    def getscales(self):
        return self.scales
    def getnscale(self):
        return self.nscale

class Morlet(Cwt):
    _omega0=5
    fourierwl=4* NP.pi/(_omega0+ NP.sqrt(2.0+_omega0**2))
    def wf(self, s_omega):
        H=(s_omega>0)*1.
    xhat=0.75112554*( NP.exp(-(s_omega-self._omega0)**2/2.0))*H
        return xhat

Da un altro file importo la classe Morlet con:
from nomefile import Morlet

e poi la richiamo col comando
cw=Morlet(A,maxscale,notes,scaling=scaling)

e tutto funziona!!

Però avrei la necessità di passare il parametro _omega0=xxx quando chiamo la classe.... tipo così:
cw=Morlet(A,maxscale,notes,scaling=scaling,_omega0=5)

ho fatto un po di prove ma non riesco.
Ogni aiuto è ben accetto.
Grazie
Matteo

_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a