Esempio n. 1
0
def main():
    from getopt import getopt
    import popen2
    opts,args = getopt( sys.argv[1:],'u:n:Rt:' )
    opts=dict(opts)
    exitcode=0

    util = opts.get('-u','./kf_float')

    try:
        dims = [ int(d) for d in opts['-n'].split(',')]
        cpx = opts.get('-R') is None
        fmt=opts.get('-t','f')
    except KeyError:
        sys.stderr.write("""
        usage: compfft.py 
        -n d1[,d2,d3...]  : FFT dimension(s)
        -u utilname : see sample_code/fftutil.c, default = ./kf_float
        -R : real-optimized version\n""")
        sys.exit(1)

    x = fft.make_random( dims )

    cmd = '%s -n %s ' % ( util, ','.join([ str(d) for d in dims]) )
    if cpx:
        xout = FFT.fftnd(x)
        xout = reshape(xout,(size(xout),))
    else:
        cmd += '-R '
        xout = FFT.real_fft(x)

    proc = popen2.Popen3( cmd , bufsize=len(x) )

    proc.tochild.write( dopack( x , fmt ,cpx ) )
    proc.tochild.close()
    xoutcomp = dounpack( proc.fromchild.read( ) , fmt ,1 )
    #xoutcomp = reshape( xoutcomp , dims )

    sig = xout * conjugate(xout)
    sigpow = sum( sig )

    diff = xout-xoutcomp
    noisepow = sum( diff * conjugate(diff) )

    snr = 10 * math.log10(abs( sigpow / noisepow ) )
    if snr<100:
        print xout
        print xoutcomp
        exitcode=1
    print 'NFFT=%s,SNR = %f dB' % (str(dims),snr)
    sys.exit(exitcode)
def main():
    from getopt import getopt
    import popen2
    opts, args = getopt(sys.argv[1:], 'u:n:Rt:')
    opts = dict(opts)
    exitcode = 0

    util = opts.get('-u', './kf_float')

    try:
        dims = [int(d) for d in opts['-n'].split(',')]
        cpx = opts.get('-R') is None
        fmt = opts.get('-t', 'f')
    except KeyError:
        sys.stderr.write("""
        usage: compfft.py 
        -n d1[,d2,d3...]  : FFT dimension(s)
        -u utilname : see sample_code/fftutil.c, default = ./kf_float
        -R : real-optimized version\n""")
        sys.exit(1)

    x = fft.make_random(dims)

    cmd = '%s -n %s ' % (util, ','.join([str(d) for d in dims]))
    if cpx:
        xout = FFT.fftnd(x)
        xout = reshape(xout, (size(xout), ))
    else:
        cmd += '-R '
        xout = FFT.real_fft(x)

    proc = popen2.Popen3(cmd, bufsize=len(x))

    proc.tochild.write(dopack(x, fmt, cpx))
    proc.tochild.close()
    xoutcomp = dounpack(proc.fromchild.read(), fmt, 1)
    #xoutcomp = reshape( xoutcomp , dims )

    sig = xout * conjugate(xout)
    sigpow = sum(sig)

    diff = xout - xoutcomp
    noisepow = sum(diff * conjugate(diff))

    snr = 10 * math.log10(abs(sigpow / noisepow))
    if snr < 100:
        print xout
        print xoutcomp
        exitcode = 1
    print 'NFFT=%s,SNR = %f dB' % (str(dims), snr)
    sys.exit(exitcode)