├── .gitattributes ├── README.txt ├── rtl_ook.m └── sdr_433.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This code repeatedly sends the message 010010100101 repeatedly 2 | via 433MHz on Arduino, and recovers it automatically with a MATLAB script. 3 | See https://ilias.giechaskiel.com/posts/rtl_433/index.html for details. 4 | -------------------------------------------------------------------------------- /rtl_ook.m: -------------------------------------------------------------------------------- 1 | % This code analyzes a 433MHz receiver using the 2 | % http://code.google.com/p/rc-switch/ library and an RTL-SDR dongle. 3 | % It simply filters the signal for noise, calculates the envelope, and 4 | % converts it to a binary 0-1 signal. It converts and prints the encoded 5 | % messages based on the pulse length after a simple debouncing. 6 | % 7 | % See https://ilias.giechaskiel.com/posts/rtl_433/index.html 8 | % for details. 9 | % 10 | % Note that the script is very sensitive so the parameters might need to be 11 | % tweaked for other applications, or even for other receivers/transmitters. 12 | 13 | fc = 433.989e6; % Center frequency (Hz) 14 | sr = 1e6; % Samples per second 15 | fl = 262144; % Frame length (keep it as large as possible) 16 | 17 | sdr_rx = comm.SDRRTLReceiver(... 18 | 'CenterFrequency', fc, ... 19 | 'EnableTunerAGC', true, ... 20 | 'SampleRate', sr, ... 21 | 'SamplesPerFrame', fl, ... 22 | 'OutputDataType', 'double'); 23 | 24 | pl = 350e-6; % pulse length 25 | high_thres = 0.5; % threshold for classifying as a 0 or 1 26 | low_dur = sr*pl; % pulse duration for a 0 27 | high_mult = 3; % multiplier for a 1 28 | high_dur = high_mult*sr*pl; % pulse duration for a 1 29 | db_dur = sr*pl/5; % debouncing duration 30 | 31 | high_len = 0; % number of high pulses 32 | low_len = 0; % number of low pulses for debouncing 33 | 34 | num_secs = 1.5; % number of seconds to listen 35 | 36 | binary = zeros(fl, 1); % array which will keep binary values 37 | 38 | if ~isempty(sdrinfo(sdr_rx.RadioAddress)) % if dongle is connected 39 | num_repeats = ceil(num_secs*sr/fl); % number of loop repetitions 40 | for repeat = 1 : num_repeats 41 | [data,~] = step(sdr_rx); % data is complex-valued and in [-1 1] 42 | 43 | rdata = real(data); % just worry about in-phase data 44 | % plot(rdata) 45 | % ylim([-1 1]) 46 | % pause(1) 47 | 48 | % Savitzky-Golay filtering (cubic with frames of length 41) 49 | smoothed = sgolayfilt(rdata, 3, 41); 50 | % plot(smoothed) 51 | % ylim([-1 1]) 52 | % pause(1) 53 | 54 | % Calculate the envelope of the signal 55 | envelope = abs(hilbert(smoothed)); 56 | % plot(envelope) 57 | % ylim([0 1.2]) 58 | % pause(1) 59 | 60 | % convert to a binary value based on threshold 61 | binary(1:fl) = 0; 62 | binary(envelope >= high_thres) = 1; 63 | % plot(binary) 64 | % ylim([0 1]) 65 | % pause(1) 66 | 67 | for i = 1 : fl 68 | if binary(i) 69 | % if high, increment high pulses and reset debouncing 70 | high_len = high_len + 1; 71 | low_len = 0; 72 | else 73 | if high_len 74 | % if transmission was not silent, increase debouncing 75 | low_len = low_len + 1; 76 | end 77 | 78 | % if have exceeded debouncing, and have transmission 79 | if low_len > db_dur && high_len 80 | % if it's close enough to a low or high pulse, print it 81 | if abs(high_len - low_dur) < db_dur + 10 82 | fprintf('%d', 0) 83 | elseif abs(high_len - high_dur) < db_dur*high_mult 84 | fprintf('%d', 1) 85 | end 86 | 87 | % reset high and debouncing 88 | low_len = 0; 89 | high_len = 0; 90 | end 91 | end 92 | end 93 | end 94 | end 95 | fprintf('\n') 96 | 97 | release(sdr_rx); % release system object 98 | -------------------------------------------------------------------------------- /sdr_433.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic 433MHz transmission example using 3 | * http://code.google.com/p/rc-switch/ 4 | * and based on the SendDemo example 5 | * 6 | * See https://ilias.giechaskiel.com/posts/rtl_433/index.html 7 | * for details. 8 | */ 9 | 10 | #include 11 | 12 | RCSwitch mySwitch = RCSwitch(); 13 | 14 | void setup() { 15 | mySwitch.enableTransmit(10); 16 | } 17 | 18 | void loop() { 19 | mySwitch.send("010010100101"); 20 | delay(1000); 21 | } 22 | 23 | --------------------------------------------------------------------------------