def simpleExample(): # Create a signal N = 256 signal = numpy.zeros(N,numpy.complex128) # Make our signal 1 in the middle, zero elsewhere signal[N/2] = 1.0 # plot our signal pylab.figure() pylab.plot(abs(signal)) # Do the GFT on the signal SIGNAL = gft.gft1d(signal,'gaussian') # plot the magnitude of the signal pylab.figure() pylab.plot(abs(SIGNAL),'b') # get the partitions partitions = gft.partitions(N) # for each partition, draw a line on the graph. Since the partitions only indicate the # positive frequencies, we need to draw partitions on both sides of the DC for i in partitions[0:len(partitions)/2]: pylab.axvline((N/2+i),color='r',alpha=0.2) pylab.axvline((N/2-i),color='r',alpha=0.2) # finally, interpolate the GFT spectrum and plot a spectrogram pylab.figure() pylab.imshow(abs(gft.gft1dInterpolateNN(SIGNAL)))
def gaussianWindow(signal,t,k): l = len(signal) x = numpy.arange(0,1,1./l).astype(numpy.complex64) win = 1*numpy.abs(k)/numpy.sqrt(2*numpy.pi)*numpy.e**(-(x-0.5)**2*numpy.abs(k)**2/2.) win = win/(numpy.sum(win)/l) win = gft.shift(win,-l/2) win = gft.shift(win,t) return win
def plot2D(image,window,figTitle=None): N = numpy.shape(image)[0] transform = gft.gft2d(image,window) pylab.figure() pylab.subplot(121) if figTitle: pylab.title(figTitle) pylab.imshow(image.real) pylab.subplot(122) pylab.imshow(abs(transform)) partitions = gft.partitions(N) for i in partitions[0:len(partitions)/2]: pylab.axvline((N/2+i),color='r',alpha=0.2) pylab.axvline((N/2-i),color='r',alpha=0.2) pylab.axhline((N/2+i),color='r',alpha=0.2) pylab.axhline((N/2-i),color='r',alpha=0.2) pylab.axis((0,N,0,N))
def transform2D(): N = 256 image = numpy.zeros((N,N)) image1 = numpy.copy(image); image1[N/2,N/2] = 1.0 plot2D(image1,'gaussian','Transform of A 2D Delta: Gaussian Window') plot2D(image1,'box','Transform of A 2D Delta: Boxcar Window') image2 = dist(image); image2 /= numpy.max(numpy.ravel(numpy.abs(image2))); image2 = numpy.cos(2*numpy.pi*96*image2) plot2D(image2,'gaussian','Transform of A Circularly Symmetric Cosine: Gaussian Window') plot2D(image2,'box','Transform of A Circularly Symmetric Cosine: Boxcar Window') image3 = dist(image); image3 /= numpy.max(numpy.ravel(numpy.abs(image3))); image3 = numpy.cos(2*numpy.pi*48*image3)*gaussian2D(image3,8) image3 = gft.shift(image3,-N/4,-N/4) image3 += gft.shift(image2*gaussian2D(image3,8),N/4,N/4) plot2D(image3,'gaussian','Transform of A Gaussian Modulated Circularly Symmetric Cosine: Gaussian Window') plot2D(image3,'box','Transform of A Gaussian Modulated Circularly Symmetric Cosine: Boxcar Window')
def plot1D(signal,window,figTitle=None): N = len(signal) x = numpy.arange(0,1,1./N) transform = gft.gft1d(signal,window) pylab.figure() pylab.subplot(211) if figTitle: pylab.title(figTitle) pylab.plot(x,signal.real,'b') pylab.plot(x,signal.imag,'b--') ax = pylab.axis() pylab.subplot(212) pylab.plot(x,transform.real,'b') pylab.plot(x,transform.imag,'g--') partitions = gft.partitions(N) for i in partitions[0:len(partitions)/2]: pylab.axvline((N/2+i)/float(N),color='r',alpha=0.2) pylab.axvline((N/2-i)/float(N),color='r',alpha=0.2)