Skip to main content

Mrp40 Morse Code Decoder Apr 2026

def extract_run_lengths(binary_signal): pulses = [] spaces = [] count = 1 current = binary_signal[0] for sample in binary_signal[1:]: if sample == current: count += 1 else: if current == 1: pulses.append(count) else: spaces.append(count) count = 1 current = sample return pulses, spaces MRP40 uses a statistical histogram of all pulse lengths. The shortest cluster = dot length.

def adaptive_threshold(envelope, alpha=0.8, beta=1.5, window_ms=100, fs=8000): window = int(window_ms * fs / 1000) local_peak = np.zeros_like(envelope) for i in range(len(envelope)): start = max(0, i - window) end = min(len(envelope), i + window) local_peak[i] = np.max(envelope[start:end]) threshold = alpha * np.median(local_peak) # hysteresis: on if > beta*threshold, off if < threshold return (envelope > beta * threshold).astype(int) Morse code is defined by dot duration – all other timings are multiples. 5.1 Extract Pulse & Space Lengths From the binary signal, measure consecutive high (pulse) and low (space) runs. mrp40 morse code decoder

MORSE_CODE = '.-': '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', '-----': '0', '.----': '1', '..---': '2', '...--': '3', '....-': '4', '.....': '5', '-....': '6', '--...': '7', '---..': '8', '----.': '9' i - window) end = min(len(envelope)

from sklearn.cluster import KMeans def estimate_dot_length(pulses, spaces, fs=8000): # Convert samples to ms pulses_ms = [p * 1000 / fs for p in pulses] spaces_ms = [s * 1000 / fs for s in spaces] all_durations = pulses_ms + spaces_ms off if &lt