Timer anded with a condition ?

hey, i am trying to make an if statement nested in a while loop by having a condition anded with a time period. if the condition is true for that period of time, do what ever is in the if statement.
any ideas ?

2 Comments

So, for example, "execute this section of code if between 38 and 42 seconds have elapsed since the user pressed the GO button" ?
Or is it "execute this section of code if the time been simulated is between 38 and 42 seconds into the simulated operation" ?
Or closer to, "When you reach a weekend in an hourly time-series, total the income and expenses for the previous week" ?
for example , let a variable called 'result'. when the user presses the button the while loop start calculations to get ' result'. what i want is, when the result value does not change for 25 second, another function will execute.
what i am really doing is calculating the delay between two microphones and with that calculating angle of the sound source, if the angle is 0, there are no sound. if there is no sound for 25 second,no one is speaking and the device is not being used, in that case i want to do some commands that will cut off power from devices attached to parallel port. i have done all needed codes but i dont know how to write an if statement that tells matlab do these lines of codes if the angle stays zero for 25 seconds.

Sign in to comment.

Answers (1)

You do not need a timer for that.
You know the number of samples per second, so there is a direct mapping between sample number and time. Record the sample number at which you last detected non-noise, and if you have not reached (sampling frequency * 25) further then do not bother to test.
When conditions are right to test, take the last 25 second's worth of data and search from the end of it towards the front until at least N samples in a row were above the noise floor, where N reflects the shortest continuous sound you consider to be sufficient to keep the system live. You would, for example, not want a single noise sample to be enough to keep the device live. If you do not find such a pattern then time to turn off. If you do find the pattern, then set the last-sound counter to the sample number of the last location you considered to be significant enough to keep the device live.
if CurrentSampleNum >= LastSoundSampleNum + FS * 25
... time to check
end

1 Comment

in that case, if there is no delay, current sample num will never be >= last+Fs*25.. it will be zero, and Fs=44100 is there another way that will do a timer for 25 sec if the angle does not change , so if angleold==anglenew for amount of time codes...... end ??

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 27 Mar 2014

Commented:

on 27 Mar 2014

Community Treasure Hunt

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

Start Hunting!