简体   繁体   中英

Handling signal with exceptions

I am trying to find a way to calculate the falling time of a signal, which looks like this signal pulse . The falling time is found by finding the value at which the signal falls below a certain level below the plateau. Here's what I tried so far, but I am not getting anywhere.

minvalue = np.argmin(data)                                              
for i in range(minvalue - 500, minvalue + 1, - 1):                      
    try:                                                                
        if data[i - 1] >= level and data[i] < level:                    
            return times[i]                                             
    except:                                                                                                                    
        continue  

Any suggestions are welcomed! Thanks. Here's how I am using the defined function:

        t0 = self.crossingTime1(upADC, channel_data, times)
        t1 = self.crossingTime1(downADC, channel_data, times)
        fall_time = t1 - t0 

So if either t1 or t0 aren't returned by the function, then it won't be possible to obtain a number, given that I will be trying to subtract a None object from a float object.

Try the following code. It should work according to the description in your question.

minvalue = np.argmin(data)                                              
for i in range(minvalue + 1, minvalue - 500, -1):                      
    if data[i - 1] >= level and data[i] < level:                    
        return times[i]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM