def test9(): N = 128 H = genf2hilbert(N) hc = fourier.ifft(H) h0 = [samp.imag for samp in hc] h = h0[N//2:] + h0[0:N//2] + [h0[0]] print len(h) stemplot(h) #Signal Nsig = 1024 f = 50 signal = [math.sin(2*f*math.pi*x/Nsig) for x in xrange(Nsig)] hilbsign, origsign = convolution.convolveorig(h, N//2, signal) mag = [math.sqrt(origsign[x]*origsign[x] + hilbsign[x]*hilbsign[x]) for x in xrange(len(hilbsign))] fig, ax = pyplot.subplots(1) ax.plot(hilbsign,'-r') ax.plot(origsign,'-b') ax.plot(mag,'-k') pyplot.show()
def test11(): N = 1024 f = 25 dd = N/2 nn = N/10 signal = [math.exp(-((dd-x)/nn)**2/2)*math.sin(2*f*math.pi*x/N) for x in xrange(N)] ### Nhilb = 256 H = genf2hilbert(Nhilb) hc = fourier.ifft(H) h0 = [samp.imag for samp in hc] h = h0[Nhilb//2:] + h0[0:Nhilb//2] + [h0[0]] ### hsignal, origsig = convolution.convolveorig(h, Nhilb//2, signal) mag = [math.sqrt(origsig[x]*origsig[x] + hsignal[x]*hsignal[x]) for x in xrange(len(hsignal))] ### fig, ax = pyplot.subplots(1) ax.plot(origsig,'-b') ax.plot(hsignal,'-r') ax.plot(mag,'-k') pyplot.show()
def test3(): N = 1024 f = 10 signal = [math.sin(2*f*math.pi*x/N) for x in xrange(N)] #signal = [0]*512 + [1] + [0]*511 t = [x/N for x in xrange(N)] hilb = genhilbert(150+1) dly = convolution.Delay(75, len(hilb)) cnv = convolution.Convolution(hilb) hilbsign, origsign = convolution.convolveorig(hilb, 75, signal) print len(origsign) print len(hilbsign) #fig, ax = pyplot.subplots(1) #ax.plot(t, signal,'-') #pyplot.show() mag = [math.sqrt(origsign[x]*origsign[x] + hilbsign[x]*hilbsign[x]) for x in xrange(len(hilbsign))] fig, ax = pyplot.subplots(1) ax.plot(hilbsign,'-r') ax.plot(origsign,'-b') ax.plot(mag,'-k') pyplot.show()
def test7(): N = 1024 f = 20 signal = [math.sin(2*f*math.pi*x/N) for x in xrange(N)] #signal = [0]*512 + [1] + [0]*511 t = [x/N for x in xrange(N)] Nhilb = 128 H = genfhilbert(Nhilb) hc = fourier.ifft(H) h0 = [samp.real for samp in hc] hilb = h0[Nhilb//2:] + h0[0:Nhilb//2] + [h0[0]] print len(hilb) hilbsign, origsign = convolution.convolveorig(hilb, 64, signal) print len(origsign) print len(hilbsign) #fig, ax = pyplot.subplots(1) #ax.plot(t, signal,'-') #pyplot.show() mag = [math.sqrt(origsign[x]*origsign[x] + hilbsign[x]*hilbsign[x]) for x in xrange(len(hilbsign))] fig, ax = pyplot.subplots(1) ax.plot(hilbsign,'-r') ax.plot(origsign,'-b') ax.plot(mag,'-k') pyplot.show()