#!/usr/bin/perl # #Utility to assist in measurement of effective noise bandwidth (ENB) #of SSB receiver. #Reads saved spectrum log from Spectrogram V11 of receiver response to #white noise input, and calculates ENB. # # Copyright: Owen Duffy 06-04-2005. All rights reserved. $id='$Id: sl2enb.pl,v 1.6 2007/09/03 23:03:06 owen Exp $'; use Getopt::Std; printf("\nsl2enb $id\n",$enb1,$f1); getopts('hc:l:'); if($opt_h){ print "\nUsage: sl2enb.pl [-c ReferenceFrequency][-l LoCutFreq] \n\n"; exit; } $f2=1000; $f3=$opt_c; $locut=$opt_l; #get spectrum resolution while(<>){ chomp; #strip newline if(!/^([\d\.]*) Hz Frequency Resolution$/){next;} #skip to resolution line s/^([\d\.]*) Hz Frequency Resolution$/$1/; $res=$_; last; } #skip to col hdr while(<>){ chomp; #strip newline if(!/^Num/){next;} last; } $pwrtot=0; while(<>){ next if (/^$/); #skip empty lines if (/^--/){last;} chomp; #strip newline ($num,$hz,$db)=split; next if $hz<$locut; #lo cut filter $pwr=10**($db/10); $obs[$#obs+1]="$pwr\t$hz"; $pwrtot+=$pwr; if($hz>($f2-20) && $hz<($f2+20)){ $midtot+=$pwr; $midn++; } } #throw away the last obs, it is sometimes defective $#obs--; #1KHz (f2) $f2pwr=$midtot/$midn; $enb2=$pwrtot/$f2pwr*$res; #find passband centre (f1) @obs_s=sort {$b <=> $a} @obs; $fl=100000; ($pwrmax,undef)=split('\t',$obs_s[0]); #find fl and fu such that they are -10dB for $x (@obs_s) { ($pwr,$hz)=split('\t',$x); if($pwr<$pwrmax/10){last;} if($fl>$hz){$fl=$hz}; if($fu<$hz){$fu=$hz}; } #f1 is midway between fl and fu $f1=($fl+$fu)/2; #rescan the data to get the gain at f1. $midtot=0; $midn=0; for $x (@obs_s) { ($pwr,$hz)=split('\t',$x); if($hz>($f1-20) && $hz<($f1+20)){ $midtot+=$pwr; $midn++; } } #passband centre (f1) $f1pwr=$midtot/$midn; $enb1=$pwrtot/$f1pwr*$res; #rescan the data to get the gain at f3. $midtot=0; $midn=0; if($f3>0){for $x (@obs_s) { ($pwr,$hz)=split('\t',$x); if($hz>($f3-20) && $hz<($f3+20)){ $midtot+=$pwr; $midn++; } } #specified freq (f3) $f3pwr=$midtot/$midn; $enb3=$pwrtot/$f3pwr*$res; } #show ENB wrt centre freq printf("\nENB=%5.0fHz with respect to gain at %5.0fHz (passband centre frequency).\n\n",$enb1,$f1); #if gain at f1 (1KHz) is greater than at centre freq -10dB, show ENB wrt f1 if($f2pwr>$f1pwr/10){ printf("ENB=%5.0fHz with respect to gain at %5.0fHz.\n\n",$enb2,$f2); } #if gain at f3 (command line arg) is greater than at centre freq -10dB, show ENB wrt f3 if($f3pwr>$f1pwr/10){ printf("ENB=%5.0fHz with respect to gain at %5.0fHz (specified).\n\n",$enb3,$f3); }