Skip to content

Simulation showing how a signal can be reconstructed based on the sampling frequency

Notifications You must be signed in to change notification settings

estods3/Sampling-usingNyquistTheorem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sampling-usingNyquistTheorem

This simulation is a useful demonstration of how an input signal can be sampled to collect and store data in a digital system. The simulator generates a an input signal of a randomized frequency and allows the user to select a sampling frequency to read the input signal and then recreate it in the output based on the samples.

The simulation demonstrates the importance of the Nyquist–Shannon Sampling Theorem in determining what sampling frequency should be selected for a data collection system.

System Requirements

You will need Python to run this program. I tested it with Python 2.7.15+ 64 bit. You will also need a few Python modules. You can install these by typing

pip install -r requirements.txt

in your cloned directory of this repository.

Example:

Clone or download the code and navigate to its directory in a terminal. Run the program by typing the following in a terminal:

python src/runSimulation.py

A pygame window will appear with the simulator: an input signal window, an output signal window, and a slider at the top to select a sampling frequency.

Drag the slider to select a frequency to sample the input signal. The corresponding output will show on the right. If the sampling frequency is less than the minimum Nyquist frequency (2 X Max. Input Frequency) the output signal will look very different from the input due to aliasing. The estimated frequency (displayed in the terminal) will also be inaccurate. Alt text

If the sampling frequency is greater than the Nyquist frequency, the output signal will more closely mirror the input and the estimated frequency (displayed in the terminal) will also be accurate. This means the signal can be reconstructed and its frequency approximated without aliasing. Alt text

Note, because the ouput signal is drawn using lines rather than a sinusoid, the output signal will not match the input unless the sampling frequency is an order of magnitude higher than the input frequency as shown below. Alt text

Resources:

https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem

About

Simulation showing how a signal can be reconstructed based on the sampling frequency

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages