I'm writing a function in an electrical engineering class as a part of a lab where we're to build an oscilloscope. This particular function is our software "trigger circuit." This function is just supposed to register as 1 if it meets certain conditions. The exact wording is:
"Write a MATLAB function called triggering_circuit that has the input parameters: past_sample, current_sample, trigger_level, and trigger_slope. The function is to return a value of 1 if trigger_level is between past_sample and current_sample and the difference between the current sample and the past sample (i.e., current_sample - past_sample) has the same sign as trigger_slope."
We feel as if we've written the function properly, but when we try to call it in our function, we get the error:
"Error in triggering_circuit (line 4) if trigger_level >= past_sample && trigger_level <= current_sample"
It's not giving any other errors, except that the function isn't assigning anything to the output variable m. I imagine, that's because the function won't finish running.
Now, I've looked online and I don't understand how we could be using the logical operator wrong. I would really appreciate any help.
The function is as follows:
function [ m ] = triggering_circuit( past_sample, current_sample, trigger_level, trigger_slope )
if trigger_level >= past_sample && trigger_level <= current_sample
a = current_sample - past_sample;
if a < 0 && trigger_slope < 0
m = 1;
elseif a > 0 && trigger_slope > 0
m = 1;
else
m = 0;
end
end
end
m=0if you don't enter the mainif-statement. You are also assuming thatcurrent_sampleis bigger thanpast_sample.m?