#!/usr/local/bin/perl -w # # watermark.p writes a correlation plot for a watermark and a received signal # see code/watermark # $pbmplot = 1 ; $pbmfile = "figs/watermark.pbm" ; $pbmx = 100 ; $ascii = 1 ; # whether also to write an ascii summary to stdout. $prob = 0.5 ; $pd = 0.05 ; $pi = 0.05 ; $pbmy= 0 ; $pf = 0.05 ;# data density #$prob = 0.5 ; $pd = 0.01 ; $pi = 0.01 ; $pbmy= 0 ; $pf = 0.01 ;# data density $seed = 123 ; $style = 1 ; # 0 for a square picture, 1 for diamond # eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # srand($seed) ; for ( $i = 1 ; $i <= $pbmx ; $i ++ ) { $w[$i] = ( rand() < $prob ) ? 1:0 ; if ( rand() > $pd ) { $pbmy ++ ; $r[$pbmy] = ( rand() < $pf ) ? $w[$i] : 1-$w[$i] ; } if ( rand() < $pi ) { $pbmy ++ ; $r[$pbmy] = ( rand() < $prob ) ? 1:0 ; } } if ( $style ) { # diamond $realpbmx = ( $pbmy + $pbmx ) - 1 ; $realpbmy = $realpbmx ; } else { $realpbmx = $pbmx ; $realpbmy = $pbmy ; } if ( $ascii ) { print "$realpbmx $realpbmy\n" ; # } if ( $pbmplot ) { # note I actually write a pgm file . open (PBM,"> $pbmfile"); if ($style>0) { print PBM "P2\n" ; } else { print PBM "P1\n" ; } print "# CREATOR: wallpaper.p DJCM 98 11 09\n" ; print PBM "$realpbmx $realpbmy\n" ; if ($style>0) { $maxpbm=2; print PBM "$maxpbm\n" ; } } if ( $pbmplot ) { for ( $i = 1 ; $i <= $realpbmy ; $i ++ ) { for ( $j = 1 ; $j <= $realpbmx ; $j ++ ) { if ( $style < 1 ) { $c = ($w[$j] == $r[$i] ) ? 1:0 ; } else { $ri = $i + $j - $pbmx ; $rj = $i - $j + $pbmy+1 ; $nri = $ri / 2 ; $nrj = $rj / 2 ; # if ( ($nri < 1) || ($nri > $pbmy) || # ($nrj < 1) || # ($nrj > $pbmx) ) { $c = 0 ; # forbidden = black } else { # printf "%d %d %d %d\n" , $ri , !( $ri % 2 ) , $rj, !( $rj % 2 ); if ( !( $ri % 2 ) && !( $rj % 2 ) ) { # $c = ($w[$nrj] == $r[$nri] ) ? 0:2 ; # ????? } else { $c = 1 ; # gray } } } print PBM "$c " ; } print PBM "\n" ; } # bottom line close ( PBM ) ; } print STDERR "\n# xv $pbmfile\n" ;