Matlab Matrix calculation coming wrong
11 views (last 30 days)
Show older comments
Hello,
I am working on a sensor data. I have three csv file from which I do voltage and strain calculation. After calculation of strain, when its comes to calculation of angle theta here is following condtion happening:
Condition 1: the one with correct calculations
If I take individual value(for example take value no 110 of from each variable i.e gauge1 , gauge2 and gauge3) and apply formula for performing the calculation of angle of strain I get the correct answer.
Conditon 2: the one with wrong calculated answer
However, If I apply this formula to entire matrix gauge1,2,3 I get differenent value for calculated angle. I know this one is wrong since I have calculated the values by hand and they don't match up with this condition.
I have attached csv file in order if one can help.
Thank you
Hiril
%%
clc;
clear;
% ADC and strain gauge settings
vref = 3300; % ADC reference volts
ADC_resolution = 2^24; % 2^23 24bit of resolution
A = 4; % if fsr = +/-2
pga = 128; % ADS1234 amplifier gain setting
E = 3300; % Bridge excitation in millivolts
K = 2.04; % Gauge factor
% Importing adc values
ch1 = readmatrix('C:\Users\Hiril Patel\PycharmProjects\writetofile\correct strain gauge -0.8\ch0.csv');
ch2 = readmatrix('C:\Users\Hiril Patel\PycharmProjects\writetofile\correct strain gauge -0.8\ch1.csv');
ch3 = readmatrix('C:\Users\Hiril Patel\PycharmProjects\writetofile\correct strain gauge -0.8\ch2.csv');
% Conversion to proportional millivoltage
FSR = vref/pga;
LSB = FSR/(ADC_resolution);
Channel1 = LSB*ch1;
Channel2 = LSB*ch2;
Channel3 = LSB*ch3;
Channel1mean = mean(Channel1(1:50));
Channel2mean = mean(Channel2(1:50));
Channel3mean = mean(Channel3(1:50));
Channel1 = Channel1 - Channel1mean;
Channel2 = Channel2 - Channel2mean;
Channel3 = Channel3 - Channel3mean;
% Strain calculation
gauge1 = (4/K)*(Channel1/E);
gauge2 = (4/K)*(Channel2/E);
gauge3 = (4/K)*(Channel3/E);
fig = figure;
subplot(3,1,1);
plot(gauge1,'.-');
title('Gauge1');
subplot(3,1,2);
plot(gauge2,'.-');
title('Gauge2');
subplot(3,1,3);
plot(gauge3,'.-');
title('Gauge3');
han=axes(fig,'visible','off');
han.Title.Visible='on';
han.XLabel.Visible='on';
han.YLabel.Visible='on';
ylabel(han,'Micro-strain');
xlabel(han,'Samples');
a = ((sqrt(2))/3)*(sqrt(((gauge1-gauge2).^2) + ((gauge2 - gauge3).^2) + ((gauge3-gauge1).^2)));
e1 = ((gauge1 + gauge2 + gauge3)/3) + a;
e2 = ((gauge1 + gauge2 + gauge3)/3) - a;
% Uptill here answers from calculation are correct.
%The problem starts after this point where entire matrix is considered for
%calculation
b = (sqrt(3))*(gauge3-gauge2);
c = ((2*gauge1) - gauge2 - gauge3);
T = b/c;
theta = (-0.5)*(atand(T));
figure;
if gauge1 > ((gauge2+gauge3)/2)
plot(theta);
elseif gauge1 < ((gauge2+gauge3)/2)
theta = theta - 90;
plot(theta)
elseif gauge1 == ((gauge2+gauge3)/2) & gauge2<gauge1
theta = - 45;
plot(theta);
elseif gauge1 == ((gauge2 + gauge3)/2) & gauge2>gauge1
theta = 45;
plot(theta);
else
plot(theta)
end
0 Comments
Answers (2)
Alex Hanes
on 26 Oct 2022
4 Comments
Torsten
on 26 Oct 2022
I hope I was able to explain clearly
Yes, but you didn't get my point (see below).
Torsten
on 26 Oct 2022
Edited: Torsten
on 26 Oct 2022
% Strain calculation
gauge1 = [700;300;500;500];
gauge2 = [700;300;300;700];
gauge3 = [300;700;700;300];
fig = figure;
subplot(3,1,1);
plot(gauge1,'.-');
title('Gauge1');
subplot(3,1,2);
plot(gauge2,'.-');
title('Gauge2');
subplot(3,1,3);
plot(gauge3,'.-');
title('Gauge3');
han=axes(fig,'visible','off');
han.Title.Visible='on';
han.XLabel.Visible='on';
han.YLabel.Visible='on';
ylabel(han,'Micro-strain');
xlabel(han,'Samples');
a = ((sqrt(2))/3)*(sqrt(((gauge1-gauge2).^2) + ((gauge2 - gauge3).^2) + ((gauge3-gauge1).^2)));
e1 = ((gauge1 + gauge2 + gauge3)/3) + a;
e2 = ((gauge1 + gauge2 + gauge3)/3) - a;
% Uptill here answers from calculation are correct.
%The problem starts after this point where entire matrix is considered for
%calculation
b = (sqrt(3))*(gauge3-gauge2);
c = ((2*gauge1) - gauge2 - gauge3);
T = b./c;
theta = (-0.5)*(atand(T))
figure;
for i = 1:numel(gauge1)
if gauge1(i) > ((gauge2(i)+gauge3(i))/2)
disp(theta(i));
elseif gauge1(i) < ((gauge2(i)+gauge3(i))/2)
theta(i) = theta(i) - 90;
disp(theta(i))
elseif gauge1(i) == ((gauge2(i)+gauge3(i))/2) & gauge2(i)<gauge1(i)
theta(i) = - 45;
disp(theta(i));
elseif gauge1(i) == ((gauge2(i) + gauge3(i))/2) & gauge2(i)>gauge1(i)
theta(i) = 45;
disp(theta(i));
else
disp(theta(i))
end
end
See Also
Categories
Find more on Structural Mechanics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!