Guest User

OOK binary decoding script

a guest
Jan 15th, 2019
19
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for i = 5
  2.     fileNumber = i;
  3.     fileName = i + ".wav";
  4.     fileName = char(fileName);
  5.     [y,Fs] = audioread(fileName);
  6.     x = length(y);
  7.  
  8.     %Threshold
  9.     for(i = 1:x e)
  10.         y(i) = (y(i)>0.4);
  11.     end
  12.  
  13.  
  14.     %Find asynchronous clock
  15.         %Finds the gaps between changes
  16.     changesCounter = 0;
  17.     changeSamples = zeros(1,10000);
  18.  
  19.  
  20.     prevState = 0;
  21.     for i = 1:x
  22.         changeSamples(changesCounter + 1) = changeSamples(changesCounter + 1) + 1;
  23.  
  24.         if y(i) ~= prevState % Changed State
  25.            prevState = y(i);
  26.             changesCounter = changesCounter + 1;
  27.             changeSamples(changesCounter + 1) = 0;
  28.         end
  29.    
  30.     end
  31.  
  32.     changeTime = changeSamples ./ Fs;
  33.     clockPeriod = min(changeTime(changeTime>0));
  34.     clockPeriod = round(0.001,3);
  35.     samplesPeriod = clockPeriod .* Fs *1.2;
  36.  
  37.     periodCounter = samplesPeriod;
  38.     binaryIndex = 1;
  39.     for i = 1:x
  40.         periodCounter = periodCounter - 1;
  41.         if y(i) ~= prevState || periodCounter <= 0 % Changed State or clock
  42.             binary(fileNumber, binaryIndex) = y(i);
  43.             binaryIndex = binaryIndex + 1;
  44.             z = y(i);
  45.             periodCounter = samplesPeriod;
  46.         end
  47.         prevState = y(i);
  48.     end
  49.    
  50.     plot(y);
  51. end
RAW Paste Data