Wednesday, October 19, 2016

Morse Code, Linux, and Powershell


Here are some CW tips:

Use this to receive audio through mic jack and decode the cw signal:

arecord -f S16_LE -c1 -r48000 -D hw:CARD=Device,DEV=0 - | sox -t raw -esigned-integer -b16 -r 48000 - -esigned-integer -b16 -r 22050 -t raw - |multimon-ng -a MORSE_CW -t raw -


Use a command like this to receive and decode CW from an RTL2832U SDR:

rtl_fm -f <freq> -s 22050 -M wbfm | multimon-ng -a DTMF -t raw - 


Use Powershell to make system speaker beep CW:

$frequency = 400
#frequency needs to be between 37 and 32767

$time = 200

$dot_duration = 100
$dash_duration = 300

$dot = '[console]::beep($frequency, $dot_duration)'
$dash = '[console]::beep($frequency, $dash_duration)'

$spacing = 0.1
$char_spacing = .3
$word_spacing = 0.7

$morse_rev_lookup = @{
    ".-"="A";
    "-..."="B";
    "-.-."=    "C";
    "-.."=    "D";
    "."=    "E";
    "..-."=    "F";
    "--."=    "G";
    "...."=    "H";
    ".."=    "I";
    ".---"=    "J";
    "-.-"=    "K";
    ".-.."=    "L";
    "--"=    "M";
    "-."=    "N";
    "---"=    "O";
    ".--."=    "P";
    "--.-"=    "Q";
    ".-."=    "R";
    "..."=    "S";
    "-"=    "T";
    "..-"=    "U";
    "...-"=    "V";
    ".--"=    "W";
    "-..-"=    "X";
    "-.--"=    "Y";
    "--.."=    "Z";
    ".----"=    "1";
    "..---"=    "2";
    "...--"=    "3";
    "....-"=    "4";
    "....."=    "5";
    "-...."=    "6";
    "--..."=    "7";
    "---.."=    "8";
    "----."=    "9";
    "-----"=    "0";
    ".-.-.-"=  ".";
    "--..--"= ";";
    "..--.."= "?";
    "-...-"= "==";
    "-..-."= "/";
    "---..."= "=";
    "-....-"= "-";
    "..--.-"= "_"
    }

$morse_lookup = @{}

foreach($k in $morse_rev_lookup.Keys){
    $morse_lookup.add($morse_rev_lookup[$k], $k)
}

$someinput  = [Environment]::UserName

$chararr = $someinput.ToCharArray()
foreach($k in $chararr){
    
    if( $morse_lookup[$k -join ""] ){

        Write-Host $k, ":", $morse_lookup[$k -join ""]
        $letter = $morse_lookup[$k -join ""].ToCharArray()
        foreach($l in $letter){
            if($l -eq "."){
                Invoke-Expression $dot
            }else{
                Invoke-Expression $dash
            }
            sleep($spacing)
        }
        sleep($char_spacing)
    }else{
        sleep($word_spacing)
    }
}




No comments:

Post a Comment