Hi
I have attached a Jpeg of my data file displayed in a plot,(0 to 80mS) it shows exactly the data I need how do I convert this data to a new array as is in the plot. The actual array use to create the plot has 16000 samples at 5uS per sample which is of no interest .I just need the 1s and 0s as the plot along with there timing and not 16000 1s and 0s
Thank you for any help
David

 Accepted Answer

I am not certain what your data are, or what you want to do.
One option for reducing the size of the array and still getting the plot is to use the find function to detect the 1 and 0 levels, and simply store them. Use the stem function to plot them. Another (likely more robust) option is to use the Signal Processing Toolbox midcross function to detect the pulses.
The find function might return something like this:
idx = [1 5 6 9 21 23 30 35 40];
that you could then plot as:
figure
stem(idx, ones(size(idx)), 'Marker','none')
grid
.

8 Comments

Hi
I just tried the midcross and this is the result i'm not sure what its doing?
David
I doubt if it will work for logical arrays. I didn’t know what your data were.
Try this:
D = load('Data.mat');
sqwvx = D.sqwvx;
figure
plot(t, sqwvx, 'LineWidth',1.5) % Original
grid
xlim([0 0.01])
t = linspace(0, 80E-3, numel(sqwvx)); % Time Vector
stidx = strfind(sqwvx.', [0 1]); % Encode Starting Indices
enidx = strfind(sqwvx.', [1 0]); % Encode Ending Indices
ts = t(stidx);
te = t(enidx);
figure
hold on
for k = 1:numel(ts)-1
plot([ts(k) ts(k)], [1 0], '-b', 'LineWidth',1.5)
plot([ts(k) te(k)], [0 0], '-b', 'LineWidth',1.5)
plot([te(k) te(k)], [0 1], '-b', 'LineWidth',1.5)
plot([ts(k) te(k+1)], [1 1], '-b', 'LineWidth',1.5)
end
hold off
grid
xlim([0 0.01])
The ‘stidx’ and ‘enidx’ vectors are both (1x130) for this logical vector. That was the easy part.
The difficult part was getting the plot to work. I could not get the plot to be correct without using the loop. (A more efficient solution may occur to me later, however it is eluding me now. I tried several vectorised approaches for the plot.)
HI
As always great help, apologies for being so vague, your solution does work but I dont know how to use it in my project.
I think I should have put more information in the help request so I will try to explain in a little more detail
I have brough an Rfid kit and I am try to decode the data the protocol is EM4100 (please see atached) as you see in my data file the information is there I have managed to take the analogue data and square up the pulses with your earlier help (thanks once again) I think I have been asking the wrong question as it seems I need to feed these pulses into a Manchester Decoder I thought I could just Square them and read the Data can you please help me sorry for any waist of time.
David
Thank you!
I will do my best to help, however my areas of expertise are in the area of biomedical engineering (and relkated disciplines). This problem is quite a bit removed from that, so I have no experience with it.
Rather than reinventing all the necessary coding, see the File Exchange contribution Manchester Encoding Decoding There are also three related File Exchange contributions linked to in the right margin of that page, so look through them as well to determine what works best for you. (There is not much on RFID that I can find in an online search, however you may have already solved that part of the problem.)
After you get them decoded, the starting and ending index calculations (‘stidx’ and ‘enidx’) applied to the decoded signal may help you determine the signal transitions so you can extract the relevant bit values, and then extract the data from those. Once you extract the bit data, there are several core MATLAB functions that can make the subseequent tasks easier. See Hexadecimal and Binary Values for a description.
This is the best I can do. My apologies for not being able to provide more exact solutions.
Thanks for coming back I am part way through will let you know when done thanks for all of your help.
David
My pleasure!
Hi
I think I have managed to convert the data and have attached a copy of the decoded file can you please show me how I can extract the bits as in the file (Kpnai.jpg) start bits 8,9 and then the bytes, any help would be greatly appreciated.
Thank You
I honestly have no idea how best to do that.
Try this:
D = load('mandecode.mat');
y = D.manchesterDecoded;
st = [1 strfind(y, [0 1])];
en = strfind(y, [1 0]);
sten = sort([st en]);
dsten = diff([0 sten]); % <— This May Be What You Want
bitlen = min(dsten);
figure
histogram(dsten, 2*numel(st))
figure
plot(y, 'LineWidth',1.5)
grid
figure
plot(dsten)
grid
.

Sign in to comment.

More Answers (1)

Ameer Hamza
Ameer Hamza on 22 Sep 2020

0 votes

It seems that you want to reduce the number of samples. For your data, a good option seems to be decimate(): https://www.mathworks.com/help/signal/ref/decimate.html

5 Comments

Hi
I have tried to decimate the array but the pulses are no longer accurate to the plot some change.
David
Can you share the data in a .mat file?
Yes please see attached
Check this code. It just keeps one value of 1s and 0s for each consecutive sequence along with the corresponding time
load Data.mat
n = numel(sqwvx);
Ts = 5e-6;
t = 0:Ts:(n-1)*Ts;
idx = find(diff(sqwvx));
t_new = t(idx);
sqwvx_new = sqwvx(idx);
Thank you for your help

Sign in to comment.

Categories

Products

Community Treasure Hunt

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

Start Hunting!