<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Track.apt &mdash; SiqNAL  documentation</title>
  

  
  
  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  

  
        <link rel="index" title="Index"
              href="../../genindex.html"/>
        <link rel="search" title="Search" href="../../search.html"/>
    <link rel="top" title="SiqNAL  documentation" href="../../index.html"/>
        <link rel="up" title="Module code" href="../index.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> SiqNAL
          

          
            
            <img src="../../_static/logo.png" class="logo" />
          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../Install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../Module.html">Helper Modules of SiqNAL</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../Track.html">Tracking Modules of SiqNAL</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../Demo.html">Demonstration</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">SiqNAL</a>
        
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>Track.apt</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for Track.apt</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    **Author :** *Jay Krishna*</span>
<span class="sd">    </span>
<span class="sd">    This module detects the presence of signal sent following Automatic Picture Transmission(APT). Since signal under APT is sent twice every</span>
<span class="sd">    second when under contact hence it significantly affects the statistical parameters of the signal hence statistical method is developed for detection.</span>

<span class="sd">    Approach</span>
<span class="sd">    ----------------------------</span>
<span class="sd">     </span>
<span class="sd">    * Signal is broken down in chunks of one second each.</span>
<span class="sd">    * For each smaller signal statistical values(mean, standard deviation and median) was calculated along with mean of whole signal file. </span>
<span class="sd">    * Presence of signal is confirmed by evaluating the statistical distribution of signal relative to threshold. </span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">math</span>

<span class="kn">from</span> <span class="nn">Modules</span> <span class="k">import</span> <span class="n">SignalData</span>


<div class="viewcode-block" id="stat_check"><a class="viewcode-back" href="../../Track.html#Track.apt.stat_check">[docs]</a><span class="k">def</span> <span class="nf">stat_check</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="n">threshold</span><span class="p">,</span> <span class="n">chunknumber</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Based upon the threshold views the statistical distribution of</span>
<span class="sd">        points in signal file and concludes the presence of APT signal.</span>

<span class="sd">        Parameters</span>
<span class="sd">        -----------------------</span>
<span class="sd">            values : list</span>
<span class="sd">                Calculated statistical values of each small signals.</span>
<span class="sd">            threshold : float</span>
<span class="sd">                Calculated threshold for signal file.</span>
<span class="sd">            chunknumber : int</span>
<span class="sd">                Size of each smaller signal</span>

<span class="sd">        Returns</span>
<span class="sd">        ------------------------------</span>
<span class="sd">            is_present : bool</span>
<span class="sd">                Showing presence of APT signal.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">is_present</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="n">stat</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">17</span><span class="p">,</span> <span class="mi">2</span><span class="p">):</span>
        <span class="n">measure</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">values</span> <span class="o">&gt;</span> <span class="p">(</span><span class="n">threshold</span> <span class="o">/</span> <span class="n">i</span><span class="p">))</span> <span class="o">/</span> <span class="n">chunknumber</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
        <span class="n">stat</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">measure</span><span class="p">)</span>

    <span class="k">if</span><span class="p">(</span><span class="n">stat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mf">0.5</span> <span class="ow">and</span> <span class="n">stat</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mf">0.7</span> <span class="ow">and</span> <span class="n">stat</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mf">0.8</span> <span class="ow">and</span> <span class="n">stat</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mf">0.9</span> <span class="ow">and</span> <span class="n">stat</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="mf">0.95</span><span class="p">):</span>
        <span class="n">is_present</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="k">return</span> <span class="n">is_present</span></div>


<div class="viewcode-block" id="check"><a class="viewcode-back" href="../../Track.html#Track.apt.check">[docs]</a><span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="n">SignaIInfo</span><span class="p">,</span> <span class="n">signal</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        Breaks the signal into smaller chunks and calculates statistical parameters</span>
<span class="sd">        for each chunk. Also calculates mean of whole signal file.</span>

<span class="sd">        Parameters</span>
<span class="sd">        -----------------------</span>
<span class="sd">            SignalInfo : object</span>
<span class="sd">                Instance of class SignalData having meta-data of file and signal.</span>
<span class="sd">            signal : ndarray</span>
<span class="sd">                Numpy complex array of signal.</span>

<span class="sd">        Returns</span>
<span class="sd">        ------------------------------</span>
<span class="sd">            points : list</span>
<span class="sd">                List of starting index of aprs signal.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">value</span> <span class="o">=</span> <span class="n">SignaIInfo</span><span class="o">.</span><span class="n">getvalues</span><span class="p">()</span>

    <span class="n">fs</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
    <span class="n">chunksize</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">fs</span><span class="p">)</span>
    <span class="n">chunknumber</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">signal</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">//</span> <span class="n">chunksize</span><span class="p">)</span>

    <span class="n">values</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">total</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">chunknumber</span><span class="p">):</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">i</span> <span class="o">*</span> <span class="n">chunksize</span>
        <span class="n">end</span> <span class="o">=</span> <span class="n">start</span> <span class="o">+</span> <span class="n">chunksize</span>

        <span class="n">hay</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">absolute</span><span class="p">(</span><span class="n">signal</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">end</span><span class="p">])</span>

        <span class="n">mean</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">hay</span><span class="p">)</span>
        <span class="n">std</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">hay</span><span class="p">)</span>
        <span class="n">median</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">median</span><span class="p">(</span><span class="n">hay</span><span class="p">)</span>
        <span class="n">total</span> <span class="o">=</span> <span class="n">total</span> <span class="o">+</span> <span class="nb">sum</span><span class="p">(</span><span class="n">hay</span><span class="p">)</span>

        <span class="n">value</span> <span class="o">=</span> <span class="p">(((</span><span class="n">mean</span><span class="p">)</span> <span class="o">/</span> <span class="n">std</span><span class="p">)</span> <span class="o">*</span> <span class="n">median</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span>
        <span class="n">values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

    <span class="n">threshold</span> <span class="o">=</span> <span class="mi">10</span> <span class="o">*</span> <span class="p">(</span><span class="n">total</span> <span class="o">/</span> <span class="p">(</span><span class="n">chunknumber</span> <span class="o">*</span> <span class="n">chunksize</span><span class="p">))</span>

    <span class="n">is_present</span> <span class="o">=</span> <span class="n">stat_check</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="n">threshold</span><span class="p">,</span> <span class="n">chunknumber</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">is_present</span></div>
</pre></div>

           </div>
           <div class="articleComments">
            
           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, Jay Krishna.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>