- #1
gfd43tg
Gold Member
- 950
- 50
Homework Statement
Hardware redundancy is important in many real-world engineering systems. Specifically, installing
multiple sensors that measure the same quantity provides a level of safety in the event that one
instrument fails during the mission lifetime. You do not want an expensive project to become a
complete failure simply due to the malfunction of one small part.
Suppose you are an engineer designing the control logic for a scientific telescope that will be
launched into space to study the sun. In order to provide a reasonable layer of safety, a triple
redundancy in the measurement of the telescope's elevation angle with respect to the horizon of
the Earth has been put into place (i.e. these three sensors measure the same quantity). Your task
is to program the software logic that will determine how the three independent measurements
will be combined in real-time, in order to provide the on-board computer with the best possible
estimate of the true elevation angle.
The following is known about the sensors:
- If a sensor fails, its measurement will read as NaN;
- Otherwise, working sensors provide measurements that will read as finite double values;
- Faulty/loose wiring may cause a measurement to read as NaN for a few samples, but can
return to valid measurements.
The estimator code must incorporate the following logic:
- On startup, the estimator logic defines the "previous estimate" to be NaN
- If there are any working sensors, define the elevation estimate as the average of the mea-
surements from all working sensors
- if all three sensors fail, the elevation estimate should be set to the previous estimate
- if all three sensors read NaN for 30 consecutive samples, then exit the sensor loop.
Load the sensorData.mat file which contains measurements, a Nx3 double array of sensor
measurements. Write code to "simulate" your sensor logic by looping through measurements
one row at a time to mimic the real-time sensor readings. Store the elevation estimates for each
loop iteration in a column vector called elevationEstimates.
Homework Equations
The Attempt at a Solution
This problem has a lot of information, so I am trying to break it down into 'subsystems' and solve the individual subsystems. I have a few problems right now with my code that I haven't been able to reconcile. I will list them out right now as I see them. This is a 150x3 array
1. I don't know how to find the mean of only the components of an array that are not NaN. If I do the mean of a row that has any components that are NaN, the mean is NaN. This problem becomes apparent in my code at the elevationEstimate lines, where I have a [ ] which is where I want to somehow specify to take the mean of the elements that are not NaN.
If I do isnan(measurements(4, for example, I get an array [0 0 1]. Now, I want to go back to the elements of the array where isnan(measurements(i, = 0 and take the mean of those.
2. I want the code to break when I get 30 rows consecutively that have all columns = NaN. I thought to do a while loop with failcounter(i:i+29) == 30. If I add break after that, will that let MATLAB know only to break if that condition is meant, or is it just going to break at that line no matter what. If it does break no matter what, how do I set it so that it will only break the loop if I get 30 consecutive rows of all NaN.
3. I am having some problems implementing this previousEstimates
Code:
failcounter = 0;
counter = 0;
previousEstimate = NaN;
for i = 1:length(measurements)
while failcounter(i:i+29) == 30
break
if sum(isnan(measurements(i,:))) == 0
counter = counter + 1;
failcounter = 0;
elevationEstimates = mean(measurements(i,:));
elseif sum(isnan(measurements(i,:))) == 1
counter = counter + 1;
failcounter = 0;
elevationEstimates = mean(measurements(i,[ ]));
elseif sum(isnan(measurements(i,:))) == 2
counter = counter + 1;
failcounter = 0;
elevationEstimates = mean(measurements(i, [ ]))
else
failcounter = failcounter + 1;
previousEstimate = elevationEstimates(counter);
end
if sum(measurements(1,:)) == 3
previousEstimates = NaN;
end
end
end