Created
October 13, 2023 18:29
-
-
Save guighub/1ba4f2e0540e305f4ff350c0eabbc57c to your computer and use it in GitHub Desktop.
EAS/SAME Message Encoder (NOT FOR PROFESSIONAL USE, DO NOT TRANSMIT OR BROADCAST THESE SIGNALS!!!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # "Emergency Alert System" message replicator | |
| # NOT FOR PUBLIC USE, DO NOT BROADCAST OR TRANSMIT. | |
| import matplotlib.pyplot as plt | |
| from scipy.interpolate import interp1d | |
| from scipy.io import wavfile | |
| import numpy as np | |
| mfrequency = 2083.33 # Mark bit frequency, SAME standard: 2083 1/3 Hertz. | |
| sfrequency = 1562.5 # Space bit frequency, SAME standard: 1562 1/2 Hertz. | |
| bit_length = 0.00192 # Length of one bit in seconds, SAME standard: 1920 microseconds, or 0.00192 seconds. | |
| # Reciever calibration, hexadecimal 0xAB repeated 16 times. | |
| calibration = bytes([0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab]) | |
| # Emergency message to be encoded. Formatted as such: | |
| # "ZCZC-ORG-EEE-PSSCCC+TTTT-JJJHHMM-LLLLLLLL-" | |
| # | |
| # ZCZC | Decoder attention | |
| # ORG | Code of originator | |
| # EEE | Event code | |
| # PSSCCC | Location codes (up to 31 can be present in one message) | |
| # TTTT | Purge time | |
| # JJJHHMM | Exact UTC time of issue | |
| # LLLLLLLL | Station callsign ID | |
| message = "ZCZC-ORG-EEE-PSSCCC+TTTT-JJJHHMM-LLLLLLLL-" | |
| # End marker of one transmission | |
| eom = bytes([0x4e, 0x4e, 0x4e, 0x4e]) | |
| # Binary data of message | |
| byte_data = calibration + bytes(message, 'utf-8') + eom | |
| # How many times to repeat message, SAME standard is 3 times. | |
| repeats = 3 | |
| # Spacing between transmissions in seconds. | |
| spacing = 1 | |
| # Sample rate of audio, standard quality is 44100 Hertz. | |
| rate = 44100 | |
| # Length of single transmission in samples. | |
| length = int(bit_length * rate) * (len(byte_data * 8)) | |
| x = np.arange(0, (length / rate), 1 / rate) | |
| y = [] | |
| for byte in range(len(byte_data)): | |
| for bit in range(8): | |
| if byte_data[byte] >> bit & 1: | |
| frequency = mfrequency | |
| else: | |
| frequency = sfrequency | |
| # Create sine wave of frequency and append to signal. | |
| y1 = np.sin((2 * (np.pi * x)) * frequency)[:int(bit_length * rate)] | |
| y = np.concatenate([y, y1]) | |
| # Add spacing and repeats. | |
| space = np.zeros(spacing * rate) | |
| repeated = [] | |
| for repeat in range(repeats): | |
| repeated.append(np.concatenate([y, space])) | |
| # Create final signal. | |
| y = np.concatenate(repeated) | |
| # Save, and optionally save binary data or plot. | |
| wavfile.write('out.wav', rate, y) | |
| print('Wrote wav file') | |
| # Uncomment to save raw binary data. | |
| # binary_file = open('out.bin', 'wb') | |
| # binary_file.write(byte_data) | |
| # binary_file.close() | |
| # print('Wrote binary file') | |
| # Uncomment to plot signal. | |
| # plt.plot(x, y) | |
| # plt.xlabel('sample(n)') | |
| # plt.ylabel('amplitude(V)') | |
| # plt.show() | |
| # print('Done plotting') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those wondering:
While the FCC doesn't regulate online content (YouTube and other social media) they can and will most likely track you down if you attempt to broadcast or transmit this signal over the air. This includes FM radio, television, etc.
The FCC has also fined stations hundreds of thousands of dollars just for broadcasting shortened or altered versions of the EAS/SAME message this script generates, along with the "attention tone" that comes after the three message transmissions. (see here)