def loaddata(filename): def loaddata(filename): class ImportScreen(QtGui.QDialog, SelectScreen.Ui_Dialog):
    def __init__(self):
    def initialize(self):
    def choosefile(self):
    def importvalues(self):
def select(): class Signal(object):
    def __init__(self, filename=None, filetype=None, filedata=None, Fsample=None, Fcentre=None):
    def setvalues(self, filename, filetype, Fsample, Fcentre, filedata=None):
    def setdatavalue(self, filedata):
    def getvalues(self): def loadfile(filename): def CalcFourier(signal):
def CalcFourierPower(signal, fs, fc):
def CalcIFourier(signal):
    N = transform.shape[0] def calc_parameter(flow, fhigh, fc, fs):
def butter_bandpass_filter(data, width, fs):
def filter(signal, SignalInfo, Flow, Fhigh, chunksize):
def filter_box(SignalInfo, Flow, Fhigh, chunksize): def getbands(SignalInfo, filename): def plot_waterfall(SignalInfo, chunksize, number): class ImportScreen(QtGui.QDialog, FolderScreen.Ui_Dialog):
    def __init__(self):
    def initialize(self):
    def choosefile(self):
    def importvalues(self):
def select(): def find_segs(samples, threshold, min_dur, merge_dur, fs, n, signal_filtered):
def calc_average(signal_filtered, n):
def re_check(signal, point, threshold, m):
def calc_threshold(signal): def radar_detect(diff, refLength, threshold_min=1.2, threshold_ratio=10, threshold_max=1.5):
def cfar(signal_chunk, refLength=10000, guardLength=10, p=0.001):
def check(SignaIInfo, signal_chunk):
    N = 2 * refLength def merge(peak, signal_chunk):
def radar_detect(radar, signal_chunk):
def cfar(signal_chunk, refLength=1000, guardLength=100, p=0.01):
def check(SignaIInfo, signal_chunk):
    N = 2 * refLength def stat_check(values, threshold, chunknumber):
def check(SignaIInfo, signal):
import numpy as np
import os
import time
import matplotlib.pyplot as plt
from os import listdir
from os.path import isfile, join, getmtime
from scipy.fftpack import fft, fftshift
from Modules import read_dat
from Modules import read_wav
from Modules import selectfile
from Modules import SignalData
from Modules import importfile
from Modules import fourier
from Modules import bandpass
from Modules import freqbands
from Modules import waterfall
from Modules import selectfolder
from Track import detect
from Track import aprs
from Track import beacon
from Track import apt




def analysis(SignalInfo):

    filename = 'satellite_db.json'
    bands = freqbands.getbands(SignalInfo, filename)
    print(bands)
    chunksize = int(1024 * 2 * 2 * 2 * 2 * 2 * 2 * 2)
    waterfall.plot_waterfall(SignalInfo, chunksize, 30)

    peaks = []
    is_peaks_all = False
    fc = SignalInfo.Fcentre
    fs = SignalInfo.Fsample

    for band in bands:

        name = band[0]
        FLow = band[1]
        FHigh = band[2]
        description = band[3]
        # print(band, FLow, FHigh)

        if(fc - fs / 2 < FLow and fc + fs / 2 > FHigh):

            signal_filtered = bandpass.filter_box(
                SignalInfo, FLow, FHigh, chunksize)

            if("APT" in description):

                is_present = apt.check(SignalInfo, signal_filtered)
                
                if(is_present == True):
                    is_peaks_all = True
                    # Data kept in json format
                    data = ({"Peaks": True}, {"Band Name": name}, {"FLow": FLow}, {
                        "FHigh": FHigh}, {"Description": description})
                    peaks = "NOAA Present"
                else:
                    data = ({"Peaks": False}, {"Band Name": name}, {"FLow": FLow}, {
                        "FHigh": FHigh}, {"Description": description})
                    peaks = "NOAA not Present"

            elif("beacon" in description):
                # For Beacon like funcube
                points = beacon.check(SignalInfo, signal_filtered)
                if(len(points) > 0):
                    is_peaks_all = True
                    # Data kept in json format
                    data = ({"Peaks": True}, {"Band Name": name}, {"FLow": FLow}, {
                            "FHigh": FHigh}, {"Description": description}, {"Points": points})
                    peaks.append({SignalInfo.filename: data})
                else:
                    data = ({"Peaks": False}, {"Band Name": name}, {"FLow": FLow}, {
                            "FHigh": FHigh}, {"Description": description}, {"Points": []})
                    peaks.append({SignalInfo.filename: data})

            else:
                # For APRS
                points = aprs.check(SignalInfo, signal_filtered)
                if(len(points) > 0):
                    is_peaks_all = True
                    # Data kept in json format
                    data = ({"Peaks": True}, {"Band Name": name}, {"FLow": FLow}, {
                            "FHigh": FHigh}, {"Description": description}, {"Points": points})
                    peaks.append({SignalInfo.filename: data})
                else:
                    data = ({"Peaks": False}, {"Band Name": name}, {"FLow": FLow}, {
                            "FHigh": FHigh}, {"Description": description}, {"Points": []})
                    peaks.append({SignalInfo.filename: data})

            del signal_filtered

    return peaks, is_peaks_all


def singlefile():


    SignalInfo = selectfile.select()