Пример #1
0
def construct_system_test(construct_system):


    labDemo = APS('new_data.npy', testing = 'Test', ms = True)
    labDemo.generate_raw_signal([1.2,3.6])
    _, separated = labDemo.post_processing(labDemo.rawSignal)
    labDemo.identify_offsets(separated)
    labDemo.signal_to_distances(((1.2)**2+(3.6)**2)**0.5/340.29)
    distances = labDemo.distancesPost[:4]
    TDOA = labDemo.offsets_to_tdoas()
    v = labDemo.V_AIR
    speakers = labDemo.beaconsLocation


    # Plot the linear relationship of the microphone and speakers.
    isac=1; #index of the beacon to be sacrificed
    A, b = construct_system(speakers,TDOA,labDemo.V_AIR)
    for i in range(len(b)):
        print ("Row %d: %.f should equal %.f"%(i, A[i][0] * 1.2 + A[i][1] * 3.6, b[i]))
Пример #2
0
def test_loc(least_squares, construct_system, x_pos, y_pos, inten, debug=False):


    labDemo = APS('new_data.npy', testing = 'Test', ms = True)
    labDemo.generate_raw_signal([x_pos, y_pos])
    raw_signal = labDemo.add_random_noise(inten)
    _, avgs = labDemo.post_processing(labDemo.rawSignal)
    labDemo.identify_offsets(avgs)
    labDemo.signal_to_distances(((1.2)**2+(3.6)**2)**0.5/340.29)
    distances = labDemo.distancesPost[:4]
    TDOA = labDemo.offsets_to_tdoas()
    v = labDemo.V_AIR
    speakers = labDemo.beaconsLocation
    

    # Construct system of equations
    A, b = construct_system(speakers, TDOA, labDemo.V_AIR)

    # Calculate least squares solution
    pos = labDemo.calculate_position(least_squares, construct_system, speakers, TDOA)

    if debug:
        # Plot the averaged output for each beacon
        plt.figure(figsize=(12,6))
        for i in range(len(avgs)):
            plt.subplot(3,2,i+1)
            plt.plot(avgs[i])
            plt.title("Beacon %d"%i)
        plt.tight_layout()

        # Plot the averaged output for each beacon centered about beacon0
        plt.figure(figsize=(16,4))
        peak = labDemo.identify_peak(avgs[0])
        for i in range(len(avgs)):
            plt.plot(np.roll(avgs[i], len(avgs[0]) // 2 - peak), label="{0}".format(i))
        plt.title("Beacons Detected")
        plt.legend()
        plt.show()

        print( "Offsets (samples): %s"%str(labDemo.offsetsPost))
        print( "Times (s): [%s]\n"%", ".join(["%0.6f" % t for t in TDOA]))
        print( "Constructing system...")
        print( "Verifying system using known position...")
        for i in range(len(b)):
            print( "Row %d: %.f should equal %.f"%(i, A[i][0] * x_pos + A[i][1] * y_pos, b[i]))

        print( "\nCalculating least squares estimate...")
    print("Expected: (%.3f, %.3f); got (%.3f, %.3f)\n"%(x_pos, y_pos, pos[0], pos[1]))
Пример #3
0
def plot_speakers_demo():
    # Plot the speakers
    plt.figure(figsize=(8,8))


    labDemo = APS('new_data.npy', testing = 'Test', ms = True)
    labDemo.generate_raw_signal([1.2,3.6])
    _, separated = labDemo.post_processing(labDemo.rawSignal)
    labDemo.identify_offsets(separated)
    labDemo.signal_to_distances(((1.2)**2+(3.6)**2)**0.5/340.29)
    distances = labDemo.distancesPost[:4]
    TDOA = labDemo.offsets_to_tdoas()
    v = labDemo.V_AIR


    # Plot the linear relationship of the microphone and speakers.
    isac=1; #index of the beacon to be sacrificed
    speakers = labDemo.beaconsLocation
    helper = lambda i: float(speakers[i][0]**2+speakers[i][1]**2)/(v*TDOA[i])-float(speakers[isac][0]**2+speakers[isac][1]**2)/(v*TDOA[isac])
    helperx = lambda i: float(speakers[i][0]*2)/(v*TDOA[i])-float(speakers[isac][0]*2)/(v*TDOA[isac])
    helpery = lambda i: float(speakers[i][1]*2)/(v*TDOA[i])-float(speakers[isac][1]*2)/(v*TDOA[isac])

    x = np.linspace(-9, 9, 1000)
    y1,y2,y3 = [],[],[]
    if isac!=1: y1 = [((helper(1)-helper(isac))-v*(TDOA[1]-TDOA[isac])-helperx(1)*xi)/helpery(1) for xi in x]
    if isac!=2: y2 = [((helper(2)-helper(isac))-v*(TDOA[2]-TDOA[isac])-helperx(2)*xi)/helpery(2) for xi in x]
    if isac!=3: y3 = [((helper(3)-helper(isac))-v*(TDOA[3]-TDOA[isac])-helperx(3)*xi)/helpery(3) for xi in x]

    # You can calculate and plot the equations for the other 2 speakers here.
    if isac!=1: plt.plot(x, y1, label='Equation for beacon 1', color='g')
    if isac!=2: plt.plot(x, y2, label='Equation for beacon 2', color='c')
    if isac!=3: plt.plot(x, y3, label='Equation for beacon 3', color='y')
    plt.legend()
    labDemo.plot_speakers(plt, labDemo.beaconsLocation[:4], distances)
    plt.legend(bbox_to_anchor=(1.4, 1))
    plt.xlim(-9, 11)
    plt.ylim(-6, 6)
    plt.show()
Пример #4
0
def hyperbola_demo_1():
    # Assume we already know the time of arrival of the first beacon, which is R0/(speed_of_sound)
    labDemo = APS('new_data.npy', testing = 'Test', ms = True)
    labDemo.generate_raw_signal([1.2,3.6])
    _, separated = labDemo.post_processing(labDemo.rawSignal)
    labDemo.identify_offsets(separated)
    labDemo.signal_to_distances(((1.2)**2+(3.6)**2)**0.5/340.29)
    distances = labDemo.distancesPost[:4]
    print("The distances are: " + str(distances))
    TDOA = labDemo.offsets_to_tdoas()
    plt.figure(figsize=(8,8))
    dist=np.multiply(340.29,TDOA)
    colors = ['r', 'g', 'c', 'y', 'm', 'b', 'k']
    for i in range(3):
        hyp=labDemo.draw_hyperbola(labDemo.beaconsLocation[i+1], labDemo.beaconsLocation[0], dist[i+1]) #Draw hyperbola
        plt.plot(hyp[:,0], hyp[:,1], color=colors[i+1], label='Hyperbola for beacon '+str(i+1), linestyle='--')
    labDemo.plot_speakers(plt, labDemo.beaconsLocation[:4], distances)
    plt.xlim(-9, 18)
    plt.ylim(-6, 6)
    plt.legend()
    plt.show()
Пример #5
0
import math
import numpy as np
import warnings
warnings.filterwarnings('ignore')
# from IPython.html.widgets import *
from IPython.html.widgets import interact
#from ipywidgets import *
import matplotlib.pyplot as plt
from math import sin, cos, pi, sqrt
from random import random
import scipy.io
import scipy.signal
from APS import APS


Lab = APS('new_data.npy', testing = 'Test', ms = True)


#########
# APS 1 #
#########

def cross_correlation(stationary_signal, sliding_signal):
    """Compute the cross_correlation of two given signals
    Args:
    stationary_signal (np.array): input signal 1
    sliding_signal (np.array): input signal 2

    Returns:
    cross_correlation (np.array): cross-correlation of stationary_signal and sliding_signal
Пример #6
0
from APS import APS
from sqlalchemy import create_engine
import pandas as pd
import numpy as np

import mysql.connector

## Cell one, Make table

PRX = APS(abbrev='prx')
PRX.indexVolumes()
#Get total number of issues
PRX.indexIssues(verbose=True, skip=3)  #Unused test parameters:

print('link current issue:', PRX.link())
print('link volume 3 issue 2:', PRX.link(vol=2, iss=4))
print('total number of volumes:', PRX.nVolumes)
print('total number of issues:', PRX.nIssues)

#Scraping to PD Dataframe
#-----------------STATUS: Part way------------------------------------------#
#Create data frame containing the links to all articles
#vi = np.array(range(PRX.nVolumes)) + 1 #volume index
#ni = np.array(range(PRX.nIssues)) + 1 #issue index
vol_iss = {
    'Vol': list(reversed([
        *PRX.volumes,
    ])),
    'Iss': []
}
for v in vol_iss['Vol']:
Пример #7
0
from APS import APS
import pandas as pd

PRX = APS(abbrev='prx')
PRX.indexVolumes()
PRX.indexIssues(verbose=True, skip=3)

print('link current issue:', PRX.link())
print('link volume 3 issue 2:', PRX.link(vol=2, iss=4))
print('total number of volumes:', PRX.nVolumes)
print('total number of issues:', PRX.nIssues)

#%%

vol_iss = {
    'Vol': list(reversed([
        *PRX.volumes,
    ])),
    'Iss': [],
    'Yr': []
}
for v in vol_iss['Vol']:
    #Print number of issues in each volume
    PRX.indexIssues(All=False, num=int(v))
    ni = PRX.volumes[v].nIssues
    vol_iss['Iss'].append(ni)
    print('Volume: {}, Issues: {}'.format(v, ni))
    for i in range(1, ni + 1):
        print(PRX.link(vol=v, iss=i))
        r = PRX.monthRange(v, i)
    #Append to year column