Testing reception quality

From LinuxTVWiki
Revision as of 15:52, 21 April 2009 by Hlangos (talk | contribs) (→‎Script)
Jump to navigation Jump to search

Testing all channels and get an average

Why? When?

Script that gets you all channels and averages everything

Can be good when doing major changes to the installation, like replacing cables or installing a masthead amplifier. Create a baseline, then compare.


Script

#!/usr/bin/perl -w

# Original script from José Oliver Segura
# From Hex to % for signal strength by Nicolas Will, with help from GT, Feb. 1, 2008
# License unknown....
# Make sure that the tzap and channels.conf locations are correct
#
# Changes 2009-04-21
#   * moved channel.conf variable to begining of script
#   * applied channel.conf to tzap arguments
#   * removed unused variables channelsFEC1 and channelsFEC2
#   * added ignoring of first X output lines to let tuner/decoder settle
#   * sorting output by frequency
#   * changed formating of output to be more readable
#   * added samplesPerChannel variable (used to be hard coded 10)

use strict;
use warnings;

my($tzap) = "/usr/bin/tzap";
my($channelsConf) = $ENV{"HOME"} . "/.tzap/channels.conf";
my($ignoreFirstLines) = 2 ; # sometimes ber/unc can be be extremly high after switching to a new channel
my($samplesPerChannel) = 10 ;

my($tzapArgs) = "-r -c $channelsConf";
my(@channels);
my(%channelsHz);
my(%signalFreqAcum);
my(%signalFreqCount);
my(%berFreqAcum);
my(%berFreqCount);
my(%uncFreqAcum);
my(%uncFreqCount);

sub loadChannels() {
        my $file = $channelsConf;
        open (CHANNELS,"< $file") or die $!;
        while (<CHANNELS>) {
                chomp;
                @_ = split (/:/,$_);
                my $channelName = $_[0];
		$channelsHz{$channelName} = $_[1];
                push(@channels,$channelName);
        }
        close CHANNELS;
}

&loadChannels();
print "Starting...\n";
my $channel;
foreach $channel (@channels) {
	my $count = 0;
	my $ignore = $ignoreFirstLines;
	my $freq = $channelsHz{$channel};

	print "================================================================================";
	print "\n";
	print "Tunning channel $channel ($freq)\n";
        my $zapPid = open ZAP, "$tzap $tzapArgs \"$channel\" 2>&1 |" or die $! . ": $tzap $tzapArgs \"$channel\"";
	while ( $count < $samplesPerChannel && defined( my $line = <ZAP> )  ) {
     		chomp($line);
		if ($line =~ /FE_HAS_LOCK/) {
			if ($ignore > 0 ) {
				print "$line (Ignoring to let tuner/decoder settle.($ignore)\n";
				$ignore--;
				next;
			}
     			#print "$line\n";
			$count++;
			##
			## status 1f | signal a1ae | snr 0000 | ber 00000000 | unc 00000012 | FE_HAS_LOCK
			##
			$line =~ /.+signal (....).+ber (........).+unc (........).+/;
			my $signal = hex $1;
			my $ber = hex $2;
			my $unc = hex $3;
			$signalFreqAcum{$freq} += $signal;
			$signalFreqCount{$freq}++;
			$berFreqAcum{$freq} += $ber;
			$berFreqCount{$freq}++;
			$uncFreqAcum{$freq} += $unc;
			$uncFreqCount{$freq}++;
			print join("\t","Signal: ".int($signal/65536*100)."%","BER ".$ber,"UNC ".$unc),"\n";
		} else {
			print "$line\n";
		}
   	}
	close ZAP;
	print "\n";
}

print "Summary statistics:\n";
print "Frequency\tSignal  \tBer     \tUnc\n";
print "=========\t========\t========\t========\n";
my $freq;
foreach $freq (sort(keys(%signalFreqAcum))) {
	print "$freq\t";
	printf "%6.1f %%",$signalFreqAcum{$freq}/$signalFreqCount{$freq}/65536*100;
	print "\t";
	printf "%8.1f",$berFreqAcum{$freq}/$berFreqCount{$freq};
	print "\t";
	printf "%8.1f",$uncFreqAcum{$freq}/$uncFreqCount{$freq};
	print "\n";
}

Original author: José Oliver Segura

How?

Requirements: a channels.conf file, tzap, veryfy the locations of programs and files in the code.

Usage:

perl signaltest.pl

Sample output

================================================================================
Tunning channel TopUp Anytime3 (722166670)
using '/dev/dvb/adapter0/frontend0' and '/dev/dvb/adapter0/demux0'
tuning to 722166670 Hz
video pid 0x0000, audio pid 0x0000
Signal: 42%	BER 2097151	UNC 0
Signal: 43%	BER 0	UNC 0
Signal: 42%	BER 240	UNC 0
Signal: 43%	BER 1232	UNC 0
Signal: 42%	BER 192	UNC 0
Signal: 43%	BER 256	UNC 0
Signal: 43%	BER 416	UNC 0
Signal: 43%	BER 240	UNC 0
Signal: 43%	BER 592	UNC 0
Signal: 43%	BER 368	UNC 0 

Summary statistics:
Frequency	Signal	Ber     	Unc
=========	======	========	========
713833330	38 %	209715		00000000
634000000	41 %	214722		00000000
658000000	41 %	209715		00000000
578000000	51 %	209715		00000000
546000000	46 %	209715		00000000
722166670	43 %	210289		00000000

Test a channel continuously

Why? When?

Script that tunes a channel and simply converts the Signal strength into a percentage in the tzap output.

Can be good when pointing the antenna.

Recent femon versions have this functionnality built-in by using

femon -H

Script

#!/usr/bin/env python

import sys

f = sys.stdin
while True:
       l = f.readline().strip()
       fields = l.split(" | ") 
       if len(fields) < 2:
               print l
       else:
               # Sig Strength
               sigStr = fields[1].split(" ")[1]
               sig = int(sigStr, 16) / float(int('ffff', 16))
               fields[1] = "signal %.1f%%" % (sig * 100.0)

               # BER 
               berStr = fields[3].split(" ")[1]
               ber = int(berStr, 16) 
               fields[3] = "ber %08d" % (ber)
               print " | ".join(fields)

Original author: Matt Doran


How?

Requirements: a channels.conf file, tzap

Usage:

tzap channel | tzapfilter.py


Sample output

using '/dev/dvb/adapter0/frontend0' and '/dev/dvb/adapter0/demux0'
tuning to 578000000 Hz
video pid 0x0000, audio pid 0x0000
status 1f | signal 51.0% | snr 0000 | ber 02097151 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.1% | snr 0000 | ber 00000000 | unc 0000000f | FE_HAS_LOCK
status 1f | signal 51.1% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.1% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.0% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.0% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.0% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.1% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.1% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal 51.1% | snr 0000 | ber 00000000 | unc 00000000 | FE_HAS_LOCK