Jump to content
  • 0

Get frequency of the pwm-signal with WaveForms SDK


lokobob99

Question

Hello everyone,

 

I have a simple question: Lets say for example you have a simple LED, which runs with a pwm-signal and a frequency of 100kHz.

Is it possible to use the waveforms sdk to get the frequency (100kHz) of the LED and save it in a variable (e.g. in Python). Thanks in advance!

 

Kind regards,

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hey @attila,

thanks for the reply! So you mentioned data processing: I would assume the first step is to measure the signal and save the values in a buffer of a certain size (e.g. 4096 values). Do you have a hint of what to do next? I would also assume you also need the sampling rate/frequency.

Kind regards,

 

Link to comment
Share on other sites

  • 0

Hi @lokobob99

The standard mathematical tool to estimate the frequency from a bunch of equally spaced samples is the discrete fourier transform, or its slightly more complicated sibling, the discrete chirp-Z transform.

Depending on how strong your mathematical background is, you may want to consult any standard text on digital signal processing to learn about those.

If you just want something that works, you may want to look at this Github repository I made. The demo generates samples from a sinusoid signal and then recovers its frequency using the discrete fourier transform, the discrete fourier transform with zero-padding (to increase spectral resolution), and finally the discrete chirp-Z transform:

https://github.com/sidneycadot/czt


If you want to apply this technique to real data, the first thing to do is to fetch equidistant samples using the AD2. If you want to use Python for that, I can recommend that you take a look at pydwf (https://pypi.org/project/pydwf/), which makes it quite a bit easier to program Digilent devices from Python. Using that, getting a buffer of analog samples from the AD2 is about 15 lines of code.

Link to comment
Share on other sites

  • 0

Hi @lokobob99

You could use the newly added FDwfDigitalInStatusCompress/ed functions.
This works similar to record (see WK SDK/DigitalIn_Record_Compress.py) except it returns the value and stable count pairs. From this the signal period can be calculated.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...