mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
Fixup: always put a ylabel
This commit is contained in:
parent
b01463ddce
commit
0d26b21a27
1 changed files with 8 additions and 5 deletions
|
@ -59,7 +59,7 @@
|
||||||
" f_\\mathrm{max} = \\frac{1}{2} f_\\mathrm{sampling} = \\frac{1}{2} \\frac{1}{\\Delta t}\n",
|
" f_\\mathrm{max} = \\frac{1}{2} f_\\mathrm{sampling} = \\frac{1}{2} \\frac{1}{\\Delta t}\n",
|
||||||
" .\n",
|
" .\n",
|
||||||
"$$\n",
|
"$$\n",
|
||||||
"Higher frequencies will fall in between two adjacent samples, causing them to go unnoticed in the data. Note that because of folding, such frequencies can actually appear as aliases.\n",
|
"Higher frequencies will fall in between two adjacent samples. This means that these frequencies are then 'measured\\` with differing phases in such a way that they are 'folded' around the Nyquist frequency and appear as aliased frequencies below it.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Likewise, the lowest frequency depends on the length of the signal $T$, such that over the whole signal one oscillation can be found\n",
|
"Likewise, the lowest frequency depends on the length of the signal $T$, such that over the whole signal one oscillation can be found\n",
|
||||||
"$$\n",
|
"$$\n",
|
||||||
|
@ -85,7 +85,7 @@
|
||||||
"def ft_spectrum( signal, sample_rate, fft=None, freq=None, mask_bias=False):\n",
|
"def ft_spectrum( signal, sample_rate, fft=None, freq=None, mask_bias=False):\n",
|
||||||
" \"\"\"Return a FT of $signal$, with corresponding frequencies\"\"\"\n",
|
" \"\"\"Return a FT of $signal$, with corresponding frequencies\"\"\"\n",
|
||||||
" n_samples = len(signal)\n",
|
" n_samples = len(signal)\n",
|
||||||
" real_signal = np.all(np.isreal(signal))\n",
|
" real_signal = np.isrealobj(signal)\n",
|
||||||
" \n",
|
" \n",
|
||||||
" if fft is None:\n",
|
" if fft is None:\n",
|
||||||
" if real_signal:\n",
|
" if real_signal:\n",
|
||||||
|
@ -115,7 +115,7 @@
|
||||||
" ax.set_title(\"Spectrum\")\n",
|
" ax.set_title(\"Spectrum\")\n",
|
||||||
" ax.set_xlabel(\"f (Hz)\")\n",
|
" ax.set_xlabel(\"f (Hz)\")\n",
|
||||||
" ylabel = \"\"\n",
|
" ylabel = \"\"\n",
|
||||||
" if plot_amplitude:\n",
|
" if plot_amplitude or plot_complex:\n",
|
||||||
" ylabel = \"Amplitude\"\n",
|
" ylabel = \"Amplitude\"\n",
|
||||||
" if plot_power:\n",
|
" if plot_power:\n",
|
||||||
" if ylabel:\n",
|
" if ylabel:\n",
|
||||||
|
@ -127,7 +127,6 @@
|
||||||
" alpha = 0.5\n",
|
" alpha = 0.5\n",
|
||||||
" ax.plot(freqs, np.real(spectrum), '.-', label='Real', alpha=alpha)\n",
|
" ax.plot(freqs, np.real(spectrum), '.-', label='Real', alpha=alpha)\n",
|
||||||
" ax.plot(freqs, np.imag(spectrum), '.-', label='Imag', alpha=alpha)\n",
|
" ax.plot(freqs, np.imag(spectrum), '.-', label='Imag', alpha=alpha)\n",
|
||||||
" ax.legend()\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" if plot_power:\n",
|
" if plot_power:\n",
|
||||||
" ax.plot(freqs, np.abs(spectrum)**2, '.-', label='Power', alpha=alpha)\n",
|
" ax.plot(freqs, np.abs(spectrum)**2, '.-', label='Power', alpha=alpha)\n",
|
||||||
|
@ -135,6 +134,8 @@
|
||||||
" if plot_amplitude:\n",
|
" if plot_amplitude:\n",
|
||||||
" ax.plot(freqs, np.abs(spectrum), '.-', label='Abs', alpha=alpha)\n",
|
" ax.plot(freqs, np.abs(spectrum), '.-', label='Abs', alpha=alpha)\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" ax.legend()\n",
|
||||||
|
"\n",
|
||||||
" return ax\n",
|
" return ax\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -338,9 +339,11 @@
|
||||||
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
|
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"signal_sine = np.sin( 2*np.pi*f*t )\n",
|
"signal_sine = np.sin( 2*np.pi*f*t )\n",
|
||||||
|
"\n",
|
||||||
"if False:\n",
|
"if False:\n",
|
||||||
" # aliased peak\n",
|
" # aliased peak\n",
|
||||||
" signal_sine += 1/2*np.sin( 2*np.pi* (1.1* sample_rate/2) *t)\n",
|
" f_alias = (1.1* sample_rate/2)\n",
|
||||||
|
" signal_sine += 1/2*np.sin( 2*np.pi* f_alias *t)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"fig, axes = plot_signal_and_spectrum(signal_sine, sample_rate, \"Single frequency at $f = {:g}$MHz\".format(f/10**6))\n",
|
"fig, axes = plot_signal_and_spectrum(signal_sine, sample_rate, \"Single frequency at $f = {:g}$MHz\".format(f/10**6))\n",
|
||||||
"axes.flat[1].axvline(sample_rate/2, color='r', label='Nyquist Frequency');\n",
|
"axes.flat[1].axvline(sample_rate/2, color='r', label='Nyquist Frequency');\n",
|
||||||
|
|
Loading…
Reference in a new issue