Ejemplo n.º 1
0
def test(datasetname, N, et, rt, ur):
    dataset = sio.loadmat(datasetname)

    fs =float(dataset['fs'])
    h = float(dataset['h'])
    l = float(dataset['l'])
    w = float(dataset['w'])
    r = dataset['receivers']
    s = dataset['sources']
    data = dataset['data'].T[:N]
    c = float(dataset['c'])

    room = np.array([[0,0],[0,l],[w,l],[w,0]])

    maxsize = np.sqrt(w**2+l**2+h**2) #m
    max_delay = maxsize / float(c) 
    maxlength = int(2 * max_delay * fs)
    t0 = time.time()
    measurements  = [measurement.MeasurementData(data=np.hstack(source_data).T, 
                                     receivers=r, 
                                     sources=s[i], 
                                     room_dimensions=(w,l,h), 
                                     c=c, 
                                     fs=fs) 
                     for i,source_data in enumerate(data)]

    echo_data = [echo.EchoData(m.find_echoes(crop=maxlength, interpolate=ur)) for m in measurements]

    D = measurement.squared_distance_matrix(r, augmented=True)
    S, E = zip(*[e.find_labels(D,threshold=et, parallel=True, verbose=args.verbose) for e in echo_data[:N]])
    E = [e for e in E if len(e) > 0]
    S = np.vstack(S)

    distancedata = distance.DistanceData(S,E)
    results = distancedata.find_images(r)

    t1 = time.time()
    if len(results) > 0:
        imagedata = image.ImageSourceData(results, N, r, (w,l,h))
        wall_points,vertices = imagedata.find_walls(threshold=rt, bestN=10)
        if len(vertices) == 4:
            i = find_matching(room, vertices)
            error = np.sqrt(np.mean((vertices[i] - room)**2))
            return (w*l*h, error, fs, t1-t0)
    return (w*l*h, -1, fs, t1-t0)
Ejemplo n.º 2
0
maxsize = np.sqrt(w**2+l**2+h**2) #m
max_delay = maxsize / float(c) 
maxlength = int(2 * max_delay * fs)

measurements  = [measurement.MeasurementData(data=np.hstack(source_data).T, 
                                 receivers=r, 
                                 sources=s[i], 
                                 room_dimensions=(w,l,h), 
                                 c=c, 
                                 fs=fs) 
                 for i,source_data in enumerate(data)]

echo_data = [echo.EchoData(m.find_echoes(crop=maxlength, interpolate=10)) for m in measurements]

D = measurement.squared_distance_matrix(r, augmented=True)
S, E = zip(*[e.find_labels(D,threshold=et, parallel=True, verbose=args.verbose) for e in echo_data[:N]])
E = [e for e in E if len(e) > 0]
S = np.vstack(S)

distancedata = distance.DistanceData(S,E)
results = distancedata.find_images(r)

if len(results) > 0:
    imagedata = image.ImageSourceData(results, N, r, (w,l,h))
    wall_points,vertices = imagedata.find_walls(threshold=rt, bestN=10)
    im = np.vstack(imagedata.images)
    plt.scatter(im[:,0], im[:,1])
    wp = np.vstack(wall_points)
    plt.scatter(wp[:,0], wp[:,1], color=(1,0,0,1))
    plt.scatter(vertices[:,0], vertices[:,1], color=(0,1,0,1))