Skip to content

Commit

Permalink
Rename sps to samples_per_symbol
Browse files Browse the repository at this point in the history
Fixes #397
  • Loading branch information
mhostetter committed Jun 29, 2024
1 parent 05bee3d commit 9a010fc
Show file tree
Hide file tree
Showing 22 changed files with 339 additions and 334 deletions.
21 changes: 12 additions & 9 deletions docs/examples/peak-to-average-power.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"outputs": [],
"source": [
"span = 10 # Length of the pulse shape in symbols\n",
"sps = 200 # Samples per symbol"
"samples_per_symbol = 200 # Samples per symbol"
]
},
{
Expand All @@ -64,11 +64,14 @@
"source": [
"def pulse_shape(alpha):\n",
" if alpha is None:\n",
" h = np.zeros(span * sps + 1)\n",
" h[span * sps // 2 - sps // 2 : span * sps // 2 + sps // 2] = 1 / np.sqrt(sps)\n",
" h = np.zeros(span * samples_per_symbol + 1)\n",
" h[\n",
" span * samples_per_symbol // 2 - samples_per_symbol // 2 : span * samples_per_symbol // 2\n",
" + samples_per_symbol // 2\n",
" ] = 1 / np.sqrt(samples_per_symbol)\n",
" else:\n",
" h = sdr.root_raised_cosine(alpha, span, sps)\n",
" fir = sdr.Interpolator(sps, h)\n",
" h = sdr.root_raised_cosine(alpha, span, samples_per_symbol)\n",
" fir = sdr.Interpolator(samples_per_symbol, h)\n",
"\n",
" bb = fir(x)\n",
" pb = sdr.mix(bb, 0.02)\n",
Expand Down Expand Up @@ -118,7 +121,7 @@
"sdr.plot.time_domain(x_bb_0p9, label=rf\"$\\alpha = 0.9$, PAPR = {papr_bb_0p9:.2f} dB\", diff=\"line\")\n",
"sdr.plot.time_domain(x_bb_0p5, label=rf\"$\\alpha = 0.5$, PAPR = {papr_bb_0p5:.2f} dB\", diff=\"line\")\n",
"sdr.plot.time_domain(x_bb_0p1, label=rf\"$\\alpha = 0.1$, PAPR = {papr_bb_0p1:.2f} dB\", diff=\"line\")\n",
"plt.xlim(25 * sps, 50 * sps)\n",
"plt.xlim(25 * samples_per_symbol, 50 * samples_per_symbol)\n",
"plt.title(\"Baseband QPSK with SRRC pulse shaping\")\n",
"plt.show()"
]
Expand All @@ -145,7 +148,7 @@
"sdr.plot.time_domain(x_pb_0p9, label=rf\"$\\alpha = 0.9$, PAPR = {papr_pb_0p9:.2f} dB\")\n",
"sdr.plot.time_domain(x_pb_0p5, label=rf\"$\\alpha = 0.5$, PAPR = {papr_pb_0p5:.2f} dB\")\n",
"sdr.plot.time_domain(x_pb_0p1, label=rf\"$\\alpha = 0.1$, PAPR = {papr_pb_0p1:.2f} dB\")\n",
"plt.xlim(25 * sps, 50 * sps)\n",
"plt.xlim(25 * samples_per_symbol, 50 * samples_per_symbol)\n",
"plt.title(\"Passband QPSK with SRRC pulse shaping\")\n",
"plt.show()"
]
Expand Down Expand Up @@ -257,8 +260,8 @@
" pb_papr = []\n",
"\n",
" for alpha in alphas:\n",
" h = sdr.root_raised_cosine(alpha, span, sps)\n",
" fir = sdr.Interpolator(sps, h)\n",
" h = sdr.root_raised_cosine(alpha, span, samples_per_symbol)\n",
" fir = sdr.Interpolator(samples_per_symbol, h)\n",
"\n",
" bb = fir(x)\n",
" pb = sdr.mix(bb, 0.02)\n",
Expand Down
16 changes: 8 additions & 8 deletions docs/examples/psk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
" x = psk.map_symbols(s)\n",
"\n",
" # Add AWGN to complex symbols to achieve desired Es/N0\n",
" snr = sdr.esn0_to_snr(esn0, sps=1)\n",
" snr = sdr.esn0_to_snr(esn0, samples_per_symbol=1)\n",
" x_hat = sdr.awgn(x, snr)\n",
"\n",
" plt.figure()\n",
Expand All @@ -61,8 +61,8 @@
" plt.show()\n",
"\n",
" y = psk.modulate(s)\n",
" # h_srrc = sdr.root_raised_cosine(0.1, 6, sps)\n",
" # tx_mf = sdr.Interpolator(sps, h_srrc)\n",
" # h_srrc = sdr.root_raised_cosine(0.1, 6, samples_per_symbol)\n",
" # tx_mf = sdr.Interpolator(samples_per_symbol, h_srrc)\n",
" # y = tx_mf(x)\n",
"\n",
" plt.figure()\n",
Expand Down Expand Up @@ -111,7 +111,7 @@
}
],
"source": [
"bpsk = sdr.PSK(2, sps=10, pulse_shape=\"srrc\")\n",
"bpsk = sdr.PSK(2, samples_per_symbol=10, pulse_shape=\"srrc\")\n",
"analyze_psk(bpsk, 6)"
]
},
Expand Down Expand Up @@ -149,7 +149,7 @@
}
],
"source": [
"qpsk = sdr.PSK(4, phase_offset=45, sps=10, pulse_shape=\"srrc\")\n",
"qpsk = sdr.PSK(4, phase_offset=45, samples_per_symbol=10, pulse_shape=\"srrc\")\n",
"analyze_psk(qpsk, 9)"
]
},
Expand Down Expand Up @@ -187,7 +187,7 @@
}
],
"source": [
"psk8 = sdr.PSK(8, sps=10, pulse_shape=\"srrc\")\n",
"psk8 = sdr.PSK(8, samples_per_symbol=10, pulse_shape=\"srrc\")\n",
"analyze_psk(psk8, 12)"
]
},
Expand Down Expand Up @@ -225,7 +225,7 @@
}
],
"source": [
"psk16 = sdr.PSK(16, sps=10, pulse_shape=\"srrc\")\n",
"psk16 = sdr.PSK(16, samples_per_symbol=10, pulse_shape=\"srrc\")\n",
"analyze_psk(psk16, 18)"
]
},
Expand Down Expand Up @@ -457,7 +457,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.-1"
},
"orig_nbformat": 4
},
Expand Down
86 changes: 44 additions & 42 deletions docs/examples/pulse-shapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"outputs": [],
"source": [
"span = 8 # Length of the pulse shape in symbols\n",
"sps = 10 # Samples per symbol"
"samples_per_symbol = 10 # Samples per symbol"
]
},
{
Expand All @@ -51,8 +51,10 @@
"metadata": {},
"outputs": [],
"source": [
"rect = np.zeros(sps * span + 1)\n",
"rect[rect.size // 2 - sps // 2 : rect.size // 2 + sps // 2] = 1 / np.sqrt(sps)"
"rect = np.zeros(samples_per_symbol * span + 1)\n",
"rect[rect.size // 2 - samples_per_symbol // 2 : rect.size // 2 + samples_per_symbol // 2] = 1 / np.sqrt(\n",
" samples_per_symbol\n",
")"
]
},
{
Expand All @@ -76,9 +78,9 @@
"metadata": {},
"outputs": [],
"source": [
"rc_0p1 = sdr.raised_cosine(0.1, span, sps)\n",
"rc_0p5 = sdr.raised_cosine(0.5, span, sps)\n",
"rc_0p9 = sdr.raised_cosine(0.9, span, sps)"
"rc_0p1 = sdr.raised_cosine(0.1, span, samples_per_symbol)\n",
"rc_0p5 = sdr.raised_cosine(0.5, span, samples_per_symbol)\n",
"rc_0p9 = sdr.raised_cosine(0.9, span, samples_per_symbol)"
]
},
{
Expand Down Expand Up @@ -132,11 +134,11 @@
],
"source": [
"plt.figure()\n",
"sdr.plot.time_domain(np.roll(rc_0p1, -3 * sps))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, -2 * sps))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, -1 * sps))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, 0 * sps))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, 1 * sps))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, -3 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, -2 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, -1 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, 0 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(rc_0p1, 1 * samples_per_symbol))\n",
"plt.xlim(0, 60)\n",
"plt.title(\"Raised cosine pulses for adjacent symbols\")\n",
"plt.show()"
Expand All @@ -160,10 +162,10 @@
],
"source": [
"plt.figure()\n",
"sdr.plot.magnitude_response(rect, sample_rate=sps, color=\"k\", label=\"Rectangular\")\n",
"sdr.plot.magnitude_response(rc_0p1, sample_rate=sps, label=r\"$\\alpha = 0.1$\")\n",
"sdr.plot.magnitude_response(rc_0p5, sample_rate=sps, label=r\"$\\alpha = 0.5$\")\n",
"sdr.plot.magnitude_response(rc_0p9, sample_rate=sps, label=r\"$\\alpha = 0.9$\")\n",
"sdr.plot.magnitude_response(rect, sample_rate=samples_per_symbol, color=\"k\", label=\"Rectangular\")\n",
"sdr.plot.magnitude_response(rc_0p1, sample_rate=samples_per_symbol, label=r\"$\\alpha = 0.1$\")\n",
"sdr.plot.magnitude_response(rc_0p5, sample_rate=samples_per_symbol, label=r\"$\\alpha = 0.5$\")\n",
"sdr.plot.magnitude_response(rc_0p9, sample_rate=samples_per_symbol, label=r\"$\\alpha = 0.9$\")\n",
"plt.xlabel(\"Normalized frequency, $f/f_{sym}$\")\n",
"plt.show()"
]
Expand Down Expand Up @@ -196,10 +198,10 @@
],
"source": [
"# Compute the one-sided power spectral density of the pulses\n",
"w, H_rect = scipy.signal.freqz(rect, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_rc_0p1 = scipy.signal.freqz(rc_0p1, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_rc_0p5 = scipy.signal.freqz(rc_0p5, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_rc_0p9 = scipy.signal.freqz(rc_0p9, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_rect = scipy.signal.freqz(rect, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"w, H_rc_0p1 = scipy.signal.freqz(rc_0p1, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"w, H_rc_0p5 = scipy.signal.freqz(rc_0p5, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"w, H_rc_0p9 = scipy.signal.freqz(rc_0p9, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"\n",
"# Compute the relative power in the main lobe of the pulses\n",
"P_rect = sdr.db(np.cumsum(np.abs(H_rect) ** 2) / np.sum(np.abs(H_rect) ** 2))\n",
Expand Down Expand Up @@ -242,9 +244,9 @@
"metadata": {},
"outputs": [],
"source": [
"srrc_0p1 = sdr.root_raised_cosine(0.1, span, sps)\n",
"srrc_0p5 = sdr.root_raised_cosine(0.5, span, sps)\n",
"srrc_0p9 = sdr.root_raised_cosine(0.9, span, sps)"
"srrc_0p1 = sdr.root_raised_cosine(0.1, span, samples_per_symbol)\n",
"srrc_0p5 = sdr.root_raised_cosine(0.5, span, samples_per_symbol)\n",
"srrc_0p9 = sdr.root_raised_cosine(0.9, span, samples_per_symbol)"
]
},
{
Expand Down Expand Up @@ -298,11 +300,11 @@
],
"source": [
"plt.figure()\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, -3 * sps))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, -2 * sps))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, -1 * sps))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, 0 * sps))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, 1 * sps))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, -3 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, -2 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, -1 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, 0 * samples_per_symbol))\n",
"sdr.plot.time_domain(np.roll(srrc_0p1, 1 * samples_per_symbol))\n",
"plt.xlim(0, 60)\n",
"plt.title(\"Square-root raised cosine pulses for adjacent symbols\")\n",
"plt.show()"
Expand All @@ -326,10 +328,10 @@
],
"source": [
"plt.figure()\n",
"sdr.plot.magnitude_response(rect, sample_rate=sps, color=\"k\", label=\"Rectangular\")\n",
"sdr.plot.magnitude_response(srrc_0p1, sample_rate=sps, label=r\"$\\alpha = 0.1$\")\n",
"sdr.plot.magnitude_response(srrc_0p5, sample_rate=sps, label=r\"$\\alpha = 0.5$\")\n",
"sdr.plot.magnitude_response(srrc_0p9, sample_rate=sps, label=r\"$\\alpha = 0.9$\")\n",
"sdr.plot.magnitude_response(rect, sample_rate=samples_per_symbol, color=\"k\", label=\"Rectangular\")\n",
"sdr.plot.magnitude_response(srrc_0p1, sample_rate=samples_per_symbol, label=r\"$\\alpha = 0.1$\")\n",
"sdr.plot.magnitude_response(srrc_0p5, sample_rate=samples_per_symbol, label=r\"$\\alpha = 0.5$\")\n",
"sdr.plot.magnitude_response(srrc_0p9, sample_rate=samples_per_symbol, label=r\"$\\alpha = 0.9$\")\n",
"plt.xlabel(\"Normalized frequency, $f/f_{sym}$\")\n",
"plt.show()"
]
Expand Down Expand Up @@ -361,10 +363,10 @@
],
"source": [
"# Compute the one-sided power spectral density of the pulses\n",
"w, H_rect = scipy.signal.freqz(rect, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_srrc_0p1 = scipy.signal.freqz(srrc_0p1, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_srrc_0p5 = scipy.signal.freqz(srrc_0p5, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_srrc_0p9 = scipy.signal.freqz(srrc_0p9, 1, worN=1024, whole=False, fs=sps)\n",
"w, H_rect = scipy.signal.freqz(rect, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"w, H_srrc_0p1 = scipy.signal.freqz(srrc_0p1, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"w, H_srrc_0p5 = scipy.signal.freqz(srrc_0p5, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"w, H_srrc_0p9 = scipy.signal.freqz(srrc_0p9, 1, worN=1024, whole=False, fs=samples_per_symbol)\n",
"\n",
"# Compute the relative power in the main lobe of the pulses\n",
"P_rect = sdr.db(np.cumsum(np.abs(H_rect) ** 2) / np.sum(np.abs(H_rect) ** 2))\n",
Expand Down Expand Up @@ -407,9 +409,9 @@
"metadata": {},
"outputs": [],
"source": [
"gauss_0p1 = sdr.gaussian(0.1, span, sps)\n",
"gauss_0p2 = sdr.gaussian(0.2, span, sps)\n",
"gauss_0p3 = sdr.gaussian(0.3, span, sps)"
"gauss_0p1 = sdr.gaussian(0.1, span, samples_per_symbol)\n",
"gauss_0p2 = sdr.gaussian(0.2, span, samples_per_symbol)\n",
"gauss_0p3 = sdr.gaussian(0.3, span, samples_per_symbol)"
]
},
{
Expand Down Expand Up @@ -462,9 +464,9 @@
],
"source": [
"plt.figure()\n",
"sdr.plot.magnitude_response(gauss_0p1, sample_rate=sps, label=r\"$B T_{sym} = 0.1$\")\n",
"sdr.plot.magnitude_response(gauss_0p2, sample_rate=sps, label=r\"$B T_{sym} = 0.2$\")\n",
"sdr.plot.magnitude_response(gauss_0p3, sample_rate=sps, label=r\"$B T_{sym} = 0.3$\")\n",
"sdr.plot.magnitude_response(gauss_0p1, sample_rate=samples_per_symbol, label=r\"$B T_{sym} = 0.1$\")\n",
"sdr.plot.magnitude_response(gauss_0p2, sample_rate=samples_per_symbol, label=r\"$B T_{sym} = 0.2$\")\n",
"sdr.plot.magnitude_response(gauss_0p3, sample_rate=samples_per_symbol, label=r\"$B T_{sym} = 0.3$\")\n",
"plt.xlabel(\"Normalized frequency, $f/f_{sym}$\")\n",
"plt.show()"
]
Expand All @@ -486,7 +488,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.-1"
},
"orig_nbformat": 4
},
Expand Down
Loading

0 comments on commit 9a010fc

Please sign in to comment.