1 2 3 4 | Compute Rolloff (a percentile point) of the input fvec. For example if perc_ is 0.90 then Rolloff would be the index where the sum of values before that index are equal to 90% of the total energy. |
1 2 3 4 5 6 7 8 9 10 11 12 | $|=1; #for non buffered standard output, useful for other programs to read require 'sys/syscall.ph'; # for subsecond timing my $option = $ARGV[0] || ""; # simple option handling my $MAX_TIMEOUT_LENGTH = 4; # maximum length in seconds of tone pattern my $LISTEN_TIMEOUT = 2; # timeout value in seconds between tone my $MAX_TIME_DEV = 100000; # maximum acceptable deviation between recorded # pattern values and current time values my $MAX_TONE_DEV = 2; # maximum acceptable deviation between recorded # pattern values and current tone values my $MAX_AVG_TONE = 5; # maximum number of samples to be averaged |
1 2 3 4 5 6 7 8 9 10 11 | my @queTones = (); # running queue of recent tones detected my $prevTone = 0; # the last solid tone detected, used for disambiguation my $prevInterval = 0; # previous interval of time my @baseTones = (); # the currently entered tone sequence my @baseTimes = (); # the currently entered temporal values my %toneHash = (); # tones, times and commands read from ~/.toneFile my $toneCount = 0; # the current count of tones entered my $startTime = ""; # start of a temporal block my $currTime = ""; # current time in the time out loop my $toneAge = 0; # for tone count synchronization my $timeOut = 0; # to reset the timer window |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | sub getEpochMicroSeconds { my $TIMEVAL_T = "LL"; # LL for microseconds my $timeVal = pack($TIMEVAL_T, ()); syscall(&SYS_gettimeofday, $timeVal, 0) != -1 or die "micro seconds: $!"; my @vals = unpack( $TIMEVAL_T, $timeVal ); $timeVal = $vals[0] . $vals[1]; $timeVal = substr( $timeVal, 6); my $padLen = 10 - length($timeVal); $timeVal = $timeVal . "0" x $padLen; return($timeVal); }#getEpochMicroSeconds sub getEpochSeconds { my $TIMEVAL_T = "LL"; # LL for microseconds my $start = pack($TIMEVAL_T, ()); syscall(&SYS_gettimeofday, $start, 0) != -1 or die "seconds: $!"; return( (unpack($TIMEVAL_T, $start))[0] ); }#getEpochSeconds |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | sub readTones { # read the Rolloff output only, my(undef, undef, undef, $currentTone ) = split " ", $_[0]; if( @queTones == $MAX_AVG_TONE ) { my $localDiff = 0; # check for a solid tone by comparing against the last five tones # perform simple time related tonal smoothing, so if the tone # wavers just a bit it's still counted as one tone for my $chkHistTone ( @queTones ) { if( abs($currentTone - $chkHistTone) > $MAX_TONE_DEV ) { $localDiff =1; $prevTone = 0; }#if deviation less than threshold }#for each tone if( $localDiff == 0 ) { # make sure the current tone is different than the previous one, this is to # ensure that long duration tones are not acquired as multiple tone events # this step up or down will allow you to whistle continuously and pick up the # steps as discrete tone events my $upDev = $currentTone + $MAX_TONE_DEV; my $downDev = $currentTone - $MAX_TONE_DEV; if( $prevTone > $upDev || $prevTone < $downDev ) { my $currVal = getEpochMicroSeconds(); my $diffInterval = abs($prevInterval - $currVal); if( $option ){ print "Tone: $currentTone ## last: [$currVal] curr: [$prevInterval] "; print "difference is: $diffInterval\n"; } if( $toneCount == 0 ){ $diffInterval = 0 } push @baseTones, $currentTone; push @baseTimes, $diffInterval; $toneCount++; $prevInterval = $currVal; }#if deviation in tone # now set the previous tone to the current tone so a continuous tone # is not acquired as multiple tone events $prevTone = $currentTone; }#if a solid tone has been found # if enough tones to create an useful queue have been added, pop one off shift @queTones; }#if enough tones to create a useful queue # always push more tones on the avg push @queTones, $currentTone; }#readTones |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |