Help with Analyzing RS232 Voltage Data Recorded in a CSV File - Page 1
Forum section: electronics / general

author: Abdeldjafer
author_rank: Newbie
timestamp: March 07, 2025, 11:34:34 pm
content: I recently performed an RS232 communication test and recorded some voltage data. The interface was RS232, and I transmitted the character "H". The transmission settings were 1 start bit, 1 stop bit, no parity, and 8 data bits. The baud rate was set to 9600, and the sample frequency was 200ksps. The voltage data was saved as a comma-separated values (CSV) file. I'm trying to analyze this data and would appreciate help in interpreting the recorded voltage levels, given the sample rate and transmission settings. Specifically, I want to know how to extract the bit information from the voltage data for the transmitted character "H". Can anyone provide insight into how to work with this data and reconstruct the transmitted bits?Thank you!

author: thm_w
author_rank: Super Contributor
timestamp: March 07, 2025, 11:49:06 pm
content: Not clear, you transmitted 'H' and then the voltage byte after that?You can use python, excel, librecalc, etc. to pull the data out and graph it.For excel, if its not already in columns, do Data -> Text to columns -> Delimited, let it select the commas and turn that into columns. Then take that 8 byte value and put it into an equation to convert to voltage.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: March 08, 2025, 12:51:04 am
content: Sampling a 9600 baud bit stream at 200 kHz will give you approximately 21 samples per bit of data.In terms of voltage levels, the RS232 standard dictates that anything above +3V will be a '0' bit, and anything below -3V is a '1' bit (seeWikipedia article).So, basically, to identify the transmitted '1' and '0' bits amongst your sample data, you will need to look for at least 20 contiguous samples of >3V for a '0' or 20 of <-3 for a '1'. Ten of these runs in a row will make up a single character byte (inc. start/stop bits). Bear in mind that bytes are transmitted least-significant-byte first, so for ASCII 'H' (0b01001000), the bits will have been transmitted right-to-left (0b00010010). The start bit is always a '0', and the stop bit is a '1'. Serial lines typically idle in the '0' state when nothing is being transmitted.

author: Nominal Animal
author_rank: Super Contributor
timestamp: March 08, 2025, 02:03:06 am
content: I'd feed it toPulseView.If your lines are of formatsec.onds,volt.agethen useImport Comma-separated valuesfrom the corner of the Open file button, with column format specst,a(for time and analog; lowercase letter L would be logic,-skips a column); set samplerate200000and keep or omit theGet channel names from first linedepending on whether your CSV file has a header or not. (It doesn't support quotes or escaping.)You get the analog view of the signal. Clicking on the signal label lets you chooseConversion to Logicvia thresholds; signal average should work.Then, you stack a protocol decoder, UART for example. Clicking on its label, you click on the RX or TX, to select the converted logic signal. Also set the baud rate and format here. It'll then show you the signal, the decoded logic, the bits and the conditions, and the decoded byte values.I like usingAwkto preprocess such data. The stanza to convert a comma-separated file with second column containing voltage, to a new file withvolt.age,logicusing +3 and -3 volt thresholds, isawk -F ',' -v 'OFS=,' '{ print $2, ($2>3) ? 1 : ($2<-3) ? -1 : 0 }'input.csv>output.csvThe-F ','part tells it that input is comma-separated,-v 'OFS=,'tells it to output comma-separated data, and each rule in braces{ .. }is executed once per every row. Question mark is a ternary operator,test?value-if-true:value-if-false. To make a rule conditional, one can add the condition before the brace. For example, to skip the first line,awk -F ',' -v 'OFS=,' 'NR>=2 { print $2, ($2>3) ? 1 : ($2<-3) ? -1 : 0 }'input.csv>output.csvbecauseNRis the number of record (lines).GNU Awkis available for all operating systems, and is an excellent quick tool for massaging those CSV files before feeding them into other programs, without having to hassle with spreadsheet programs and such –– assuming you don't mind command-line tools, though.One can also write the above Awk snippet more verbosely:Code:awk 'BEGIN { FS=","; OFS=","; print "Analog", "TX" }{ logic = 0;if ($2 >= +3.0) logic = +1;if ($2 <= -3.0) logic = -1;print $2, logic}' input.csv > output.csvIt's okay if you write it all on a single line; the semicolons separate statements. I also used theBEGINrule to set the separators, and print the output header line; I often use that and the correspondingENDrule to show e.g. histograms and such. Awk has amazingly powerful and fast associative arrays, you see. You can also useprintf "format",variable,another.. using the C printf format strings:Code:awk -F ',' '{ printf "%s,%d\n", $2, ($2<-3) ? -1 : ($2>+3) ? +1 : 0 }' input.csv > output.csvSomething likeAwkis needed to convert analog data to logic levels for PulseView protocol decoders.