Advertisement
hbinderup94

FSKDecoder

Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.95 KB | None | 0 0
  1. function [x, amntSigns] = FSKdecoder(signal, fstart, fend, Tsymbol, fs)
  2.  
  3. % FSK Decoder made by group 8
  4.  
  5. % fstart    % transmission band frequency start
  6. % fend      % transmission band frequency end
  7. % Tsymbol   % symbol duration in seconds
  8. % fs        % sampling frequency
  9.  
  10.  
  11. amntSigns = length(signal) / (Tsymbol*fs);                      % Finding symbol amount
  12. farray = round(linspace(fstart, fend, 256));                    % 256 frequencies spread out in band
  13.  
  14. freq = 1:amntSigns;                                             % Preallocating space
  15.  
  16. for i = 1:amntSigns                                             % Find frequencies for each symbol in the signal                      
  17.     decodeSignal = signal((i-1)*Tsymbol*fs+1:i*Tsymbol*fs);     % Dividing the signal - isolating each symbol
  18.     [~,maximum] = max(abs(fft(decodeSignal)));                  % Find the maximum of fft to find the frequency
  19.     freq(i) = maximum / Tsymbol;                                % Converting to actual frequency
  20. end
  21.  
  22. xDec = 1:amntSigns;                                             % Preallocating space
  23.  
  24. for i = 1:amntSigns                                             % Find decimal value for ASCII character
  25.     done = 0;                                                   % Register to check if frequency was found
  26.     for n = 1:256                                               % Checking all frequencies in farray and compare to calculated freq
  27.         if (farray(n) >= freq(i)) && (done == 0)                % Finding the interval of frequencies & check if it's done already
  28.             xDec(i) = n-1;                                      % Assigning the decimal value (-1 because it's bigger than to find interval)
  29.             done = 1;                                           % Setting done - so we don't overwrite decimal value
  30.         end
  31.     end
  32. end
  33.  
  34. x = char(xDec);                                                 % Output signal - converted to char
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement