Jump to content
  • 0

Analog Discovery 2 - Filter


Weevil

Question

Hello,

i am looking for how to use the filter possibilities of the Analog Discovery 2. In the first step i want filter the min and max values of my incomming signal, if possible with time stamp or something else. (my receiving signal is a sinus). Maybe someone can help me how to get this function working. Following my code example.

Greetings from Germany :) 

 

 


libdwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True))
    
libdwf.FDwfAnalogInFrequencySet(hdwf, c_double(100000000))

libdwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5))
   


libdwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(5000))
    

#####----
#Filter
libdwf.FDwfAnalogInChannelFilterSet(c_int(1), c_int(1))

#FILTER
#filterDecimate = c_int(0)
#filterAverage  = c_int(1)
#filterMinMax   = c_int(2)    
#####-----    
    
time.sleep(2)
    
   
    
 

    
sts = c_int()
rgc1 = (c_double(5000))()
rgc2 = (c_double(5000))()
    
    

libdwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1))    

libdwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
    
        
    #Channel 1
libdwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgc1), len(rgc1))

results1 = np.array(rgc1)

        
    #Channel 2
libdwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgc2), len(rgc2))

results2 = np.array(rgc2)

 

print(results1)

 

libdwf.FDwfDeviceCloseAll()


 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Hello,

The min-max filter stores sample pairs and it will work at lower frequency than the 100MHz ADC rate.

from ctypes import *
import time
import sys
import numpy as np

if sys.platform.startswith("win"):
    dwf = cdll.dwf
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("libdwf.so")

#declare ctype variables
version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print "Version: "+version.value

cdevices = c_int()
dwf.FDwfEnum(c_int(0), byref(cdevices))
print "Number of Devices: "+str(cdevices.value)

if cdevices.value == 0:
    print "no device detected"
    quit()

print "Opening first device"
hdwf = c_int()
dwf.FDwfDeviceOpen(c_int(0), byref(hdwf))

if hdwf.value == 0:
    print "failed to open device"
    quit()
    
# 1 MHz rate is 500kHz min-max sample pair rate
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_bool(True))
dwf.FDwfAnalogInFrequencySet(hdwf, c_double(1000000))
csamples = 5000
dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(csamples))
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5))
dwf.FDwfAnalogInChannelFilterSet(c_int(-1), c_int(2)) # min-max

time.sleep(2)

dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1))

sts = c_int()
print "   waiting to finish"
while True:
    dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
    if sts.value == 2 : # done
        break
    time.sleep(0.1)
print "Acquisition finished"

rgc = (c_double*csamples)()
#Channel 1
dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgc), len(rgc))
results1=[0.0]*len(rgc)
for i in range(0,len(results1)):
    results1[i]=rgc[i]

#Channel 2
dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgc), len(rgc))
results2=[0.0]*len(rgc)
for i in range(0,len(results2)):
    results2[i]=rgc[i]

print(results1)

 

Link to comment
Share on other sites

I am analysing a sine wave and have some additional question about this topic

I would need to get the equal result from the following procedures, is there a possibility?

 

1. 

sine frequency = 50 000 Hz (signalgenerator)

sample frequency = 50 000 000 Hz

finalResult = np.max(aquiredDatas)

 

2.

sine frequency = 50 000 Hz (signalgenerator)

sample frequency = 1 000 Hz

dwf.FDwfAnalogInChannelFilterSet(c_int(0), c_int(2)) #filterMinMax -> so it should take the maxima and minima from my sine wave

take every second value, which should be equal to the finalResult from 1.

 

Actual i set sine frequency to 50 000 Hz (signal generator) and sample frequency to 100 000 Hz and would expect to get the min/max from one sine wave. ...But the signal is drifting...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...