필터 지우기
필터 지우기

receive data from sensor on udp at the same time

조회 수: 54 (최근 30일)
Rashi Mehrotra
Rashi Mehrotra 2021년 10월 11일
댓글: Walter Roberson 2024년 5월 13일
I have to receive data from multiple sensors at the same time. I have data received on udp ffrom two different sensors. the process have to be time stamped at the same values of time.
Will this require multithreading in matlab. or it can be also done by vectoring the variable.
Please tell how it can done in both ways.
I have considered using parfor and parpool but cannot arrive at the result.

답변 (1개)

Electrification Enthusiasts
Electrification Enthusiasts 2021년 10월 11일
Hello Rashi,
you should focus on processing the data serially (not in parallel) because UDP doesn't support parallel packets. They may have the same time stamps, but they will not be received simultaneously. One will always come in before the other. Also, technically, UDP can drop packets so there is not guarentee you will get data from each sensor for each time step. As for processing data that was generated at the same time, you can use vectors in maltab. Adding threads won't change that the bottlneck is your network adapter which will process everything serially.
You can look for serial to parallel (and vice versa) converters in the file exchange to starting points.
Regards,
Joel
  댓글 수: 3
Mariana Alegria Palacios
Mariana Alegria Palacios 2024년 5월 13일
Hi, did you resolve the issue? I'm triying to use two ESP-32 to receiving data, but it must be at the same time and I can't find how to use parfor or parpool for this
Walter Roberson
Walter Roberson 2024년 5월 13일
To have a chance that two udp packets could be received with the same timestamp. it would be necessary that the two were being received over different interfaces -- different wireless connectors or different ethernet connectors. For any one interface, inherently packets are queued and so two packets going to the same interface cannot be received with the same timestamp.
In order for two distinct interfaces to receive packets at the same time, it would be necessary to synchronize the interfaces. The only potential way to synchronize interfaces is to use smpd and use spmdBarrier or the older labBarrier and once through the barrier, ask for the udp packet.
The default udp reading interface, read is buffered, and the timestamp might potentially be the time the packet was actually received. So you will need to use an unbuffered UDP reading, namely the DSP udp receiver https://www.mathworks.com/help/dsp/ref/dsp.udpreceiver-system-object.html
But for unbuffered UDP reading, in order for the two packets to get the exact same timestamp, it would be necessary for the two senders to be such that the "distance" from each UDP sender and the time that the packets were sent was carefully matched -- so if one sender was 17 milliseconds away and the other sender was 18 milliseconds away, that the second sender would have to transmit 1 millisecond earlier than the first sender.
Is it all impossible? I wouldn't say that it is impossible -- I would just say that it is fairly unlikely to work out, and it is not likely at all that the streams would stay in synchronization -- not without going through a bunch of trouble.
All in all, I would say that you should probably give up on getting two UDP packets with the same timestamp . You would be much much better off looking for two UDP packets within a synchronization window .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by