<jupyter_start><jupyter_text>Sampling TheoremIn this simple notebook, we will show why the Nyquist sampling theorem is necessary. See also chapter 2 of [Unpingco's book](https://search.library.uq.edu.au/primo-explore/fulldisplay?docid=61UQ_ALMA51151217360003131&context=L&vid=61UQ&search_scope=61UQ_All&isFrbr=true&tab=61uq_all&lang=en_US).Imagine that we are measuring the output of a blackbox (purpose and construction unknown). Let's called this a function called 'blackBox'.<jupyter_code>import numpy
import math

f = 1.0  # Hz, signal frequency

def blackBox(sr):
    
    t = numpy.arange(-1,1+1/sr,1/sr) # sample interval, symmetric for convenience later
    x = numpy.sin(2*numpy.pi*f*t)
    
    return x, t<jupyter_output><empty_output><jupyter_text>We will measure the output of the blackbox at a fixed interval sampling rate $s_r$<jupyter_code>sr = 5.0 # Hz, sampling rate (ie. >= 2*f) 
x, t = blackBox(sr)<jupyter_output><empty_output><jupyter_text>We guess that it is producing a sine curve, so we draw a near perfectly sampled sine curve for comparison<jupyter_code>sr2 = 1000.0
t2 = numpy.arange(-1,1+1/sr2,1/sr2) # sample interval, symmetric for convenience later
y = numpy.sin(2*numpy.pi*f*t2)
import matplotlib.pyplot as plt

plt.plot(t,x,'o-')
plt.plot(t2,y,'-')
plt.xlabel('Time',fontsize=18)
plt.ylabel('Amplitude',fontsize=18)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11942446043165468, 'fraction_numerical': 0.04028776978417266, 'mean_word_length': 5.818627450980392, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '55846', 'license': 'Apache-2.0', 'n_tokens_mistral': 548, 'n_tokens_neox': 508, 'n_words': 127, 'path': 'Examples/notebooks/Sampling+Theorem.ipynb', 'repo_name': 'thulithwilfred/ELEC3004', 'size': '1390'}