How do I decode encrypted data and plot it??

조회 수: 3 (최근 30일)
Beau Imber
Beau Imber . 2022년 5월 10일
편집: Beau Imber . 2022년 5월 15일
I have some data that is encrypted so that values <1.2V are considered logic 0 and values >2.2V are considered logic 1. The true signal is either 0V (for logic 0) or 3.3V (for logic 1), and any value above or below this threshold will include noise. I am stuck on how to get the values to stay within the threshold and how to plot the new data once it does so.
I have attached the data and my code so far but I am unsure of how to progess. Can I get any help?
time = xlsread('data.csv', 'A2:A201');
pair_1 = xlsread('data.csv', 'B2:B201');
pair_2 = xlsread('data.csv', 'C2:C201');
pair_3 = xlsread('data.csv', 'D2:D201');
pair_4 = xlsread('data.csv', 'E2:E201');
if pair_1 < 1.2
pair_1 = 0
if pair_1 > 2.2
pair_1 = 3.3
plot(time, pair_1)

채택된 답변

Mitch Lautigar
Mitch Lautigar 2022년 5월 10일
You have a couple different ways to do this. I've listed two below to try and help.
Both ways I did it start with the following.
% Predeclarations %
data = readtable('data.csv'); %read in csv file as a table. xlsread is being/has been phased out.
data2 = table2array(data); %gets csv file into an array for easy checking.
%method 1 -- for loops
%this method works because data2 is an array of set size.
% Advantages: Easy to debug, and results are quite viewable.
% Disadvantages: If you are looking at 10k data points, this can become memory intensive.
data_check_array = []; %empty array to stack in checks.
[a,b] = size(data2);
for i = 1:length(data2) %handles each row
stack = [];
for j = 2:b %handles each column ignoring the time value.
if (data2(i,j) >= 1.2) && (data2(i,j) <= 2.2) %this means neither true or false
stack = [stack,0.5];
elseif (data2(i,j) < 1.2) %means false
stack = [stack,0];
else %means true
stack = [stack,1];
end %end j for loop
data_check_array = [data_check_array;stack];
end %end i for loop
% method 2 -- Hide and Seek
%This method works because you are only seeking specific numerical values in the table
% Advantages: This method is quick on computations and leads to solid end results
% Disadvantages: This method is much harder to debug.
true_indx = find(data2(:,2:end) > 2.2);
false_indx = find(data2(:,2:end) < 1.2);
[a,b] = size(data2);
check_array(1:a,2:b) = 0.5; %assume all values are not checked to not have to have a null index.
check_array(true_indx) = 1;
check_array(false_indx) = 0;
check_array(:,1) = data2(:,1);
I sadly don't have the capabilities to test this code, but I am confident the logic is good. Hope it helps!

추가 답변 (0개)


Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by