Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UART = serial('COM15', 'BaudRate', 921600, 'StopBit', 2);
- fopen(UART);
- buf = [];
- for c = 1:256
- A = fread(UART, 512, 'uint8');
- buf = cat(1, buf, A);
- end
- fclose(UART);
- delete(UART);
- marker = [hex2dec('01'), hex2dec('23'), hex2dec('45'), hex2dec('67'), hex2dec('89'), hex2dec('AB'), hex2dec('CD'), hex2dec('EF')];
- B = reshape(buf, [1, 512 * 256]);
- pos = strfind(B, marker);
- header = B(pos(1):pos(1) + 11);
- sample_size = header(10) * 256 * 256 + header(11) * 256 + header(12);
- data_width = header(9);
- sample_size_bytes = ceil(data_width / 8) * sample_size;
- data_bytes = B(pos+12:pos+11+sample_size_bytes);
- data = [];
- for i = 1:sample_size
- data = cat(1, data, data_bytes(i * 2 - 1) * 256 + data_bytes(i * 2));
- end
- data = (data - mean(data));
- F = fft(data);
- P2 = abs(F);
- semilogy((1:sample_size/2) * (50.0 / sample_size), P2(1:sample_size/2));
- grid on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement