Advertisement
Guest User

Untitled

a guest
Dec 20th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.87 KB | None | 0 0
  1. UART = serial('COM15', 'BaudRate', 921600, 'StopBit', 2);
  2. fopen(UART);
  3. buf = [];
  4.  
  5. for c = 1:256
  6.     A = fread(UART, 512, 'uint8');
  7.     buf = cat(1, buf, A);
  8. end
  9.  
  10. fclose(UART);
  11. delete(UART);
  12.  
  13. marker = [hex2dec('01'), hex2dec('23'), hex2dec('45'), hex2dec('67'), hex2dec('89'), hex2dec('AB'), hex2dec('CD'), hex2dec('EF')];
  14.  
  15. B = reshape(buf, [1, 512 * 256]);
  16. pos = strfind(B, marker);
  17.  
  18. header = B(pos(1):pos(1) + 11);
  19.  
  20. sample_size = header(10) * 256 * 256 + header(11) * 256 + header(12);
  21. data_width = header(9);
  22. sample_size_bytes = ceil(data_width / 8) * sample_size;
  23. data_bytes = B(pos+12:pos+11+sample_size_bytes);
  24.  
  25. data = [];
  26. for i = 1:sample_size
  27.     data = cat(1, data, data_bytes(i * 2 - 1) * 256 + data_bytes(i * 2));
  28. end
  29. data = (data - mean(data));
  30.  
  31. F = fft(data);
  32. P2 = abs(F);
  33. semilogy((1:sample_size/2) * (50.0 / sample_size), P2(1:sample_size/2));
  34. grid on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement