rf-funcitons-py 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rafpy/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .logic import id_signal_candidates
|
rafpy/logic.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
def id_signal_candidates(fig_num, observed, current_fs, filter_range=None, show_graph=True):
|
|
2
|
+
#identifies potential true frequencies and highlights the one within the analog filter range
|
|
3
|
+
#filter_range: tuple (f_min, f_max)
|
|
4
|
+
|
|
5
|
+
candidates =[]
|
|
6
|
+
f_nyquist = fs /2
|
|
7
|
+
|
|
8
|
+
#logic for finding frequency within filter range
|
|
9
|
+
match = None
|
|
10
|
+
nyquist_zone = None
|
|
11
|
+
if filter_range:
|
|
12
|
+
f_min, f_max = filter_range
|
|
13
|
+
num_candidates = int(np.ceil(f_max / current_fs))
|
|
14
|
+
else:
|
|
15
|
+
num_candidates = 5
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
for N in range(num_candidates+1):
|
|
20
|
+
f_possible_1 = N*current_fs + observed
|
|
21
|
+
f_possible_2 = N*current_fs - observed
|
|
22
|
+
if f_possible_1 > 0: candidates.append(f_possible_1)
|
|
23
|
+
if f_possible_2 > 0: candidates.append(f_possible_2)
|
|
24
|
+
#plt.figure(figsize=(12, 6))
|
|
25
|
+
unique_candidates = sorted(list(set(candidates)))
|
|
26
|
+
|
|
27
|
+
if filter_range:
|
|
28
|
+
for f in unique_candidates:
|
|
29
|
+
if f_min <= f <= f_max:
|
|
30
|
+
match = f
|
|
31
|
+
nyquist_zone = int(np.ceil(f/(current_fs/2)))
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
if show_graph:
|
|
35
|
+
fig, ax = plt.subplots(figsize=(12, 5))
|
|
36
|
+
plt.subplots_adjust(bottom=0.3)
|
|
37
|
+
|
|
38
|
+
#plots all candidates
|
|
39
|
+
markerline, stemlines, baseline = ax.stem(unique_candidates, np.ones(len(unique_candidates)))
|
|
40
|
+
plt.setp(markerline, color='red', marker='D', markersize=6, alpha=0.5)
|
|
41
|
+
plt.setp(stemlines, color='red', linestyle='--', alpha = 0.3)
|
|
42
|
+
|
|
43
|
+
#highlight filter range
|
|
44
|
+
if filter_range:
|
|
45
|
+
ax.axvspan(filter_range[0], filter_range[1], color='orange', alpha=0.15, label='Filter Passband')
|
|
46
|
+
#highlight frequency
|
|
47
|
+
if match:
|
|
48
|
+
ax.stem([match], [1], linefmt='r-', markerfmt='rD', basefmt=' ')
|
|
49
|
+
ax.annotate(f'MATCH: {match} Hz\nZone {nyquist_zone}', xy=(match, 1), xytext=(match, 1.4), arrowprops=dict(facecolor='green', shrink=0.05), ha='center', fontweight='bold', color='green')
|
|
50
|
+
if observed:
|
|
51
|
+
ax.stem([observed], [1], linefmt='r-', markerfmt='rD', basefmt=' ')
|
|
52
|
+
ax.annotate(f'OBSERVED: {observed} Hz', xy=(observed, 1), xytext=(observed, 1.3), arrowprops=dict(facecolor='blue', shrink=0.05), ha='center', fontweight='bold', color='blue')
|
|
53
|
+
#ax.annotate('Observed\n(Alias)', xy=(observed, 1), xytext=(observed, 1.3),
|
|
54
|
+
#arrowprops=dict(facecolor='black', shrink=0.05), ha='center')
|
|
55
|
+
ax.set_yticks([])
|
|
56
|
+
ax.set_title(f"Fig {fig_num}. Signal Identification (Observed: {observed} Hz | $f_s$: {current_fs} Hz | Bandpass {np.min(filter_range)}-{np.max(filter_range)} Hz)", fontweight='bold')
|
|
57
|
+
ax.set_xlabel("Frequency (Hz)", fontweight='bold')
|
|
58
|
+
ax.set_ylim(0, 1.6)
|
|
59
|
+
desc = (
|
|
60
|
+
f"""Fig {fig_num}. You saw a signal at {observed} Hz with a sampling rate of {current_fs} Hz. If you used a bandpass filter then the highlighted frequency is the original frequency considering any aliasing observed and which Nyquist zone it resides in. If you did not use a bandpass filter, then this lists the possible frequencies associated with the sampled signal, which can be filtered manually using known physics of your source."""
|
|
61
|
+
)
|
|
62
|
+
wrapped_desc = textwrap.fill(desc, width=90)
|
|
63
|
+
plt.figtext(0.5, 0.05, wrapped_desc, ha='center', fontsize=10,
|
|
64
|
+
bbox=dict(boxstyle="round,pad=0.3", fc="#f0f0f0", ec="black", alpha=0.5))
|
|
65
|
+
plt.legend(loc='upper right')
|
|
66
|
+
print("-" * 30)
|
|
67
|
+
print(f"ANALYSIS FOR {observed} Hz (Fs = {current_fs} Hz)")
|
|
68
|
+
print(f"Potential Frequencies: {unique_candidates}")
|
|
69
|
+
if match:
|
|
70
|
+
print(f"IDENTIFIED SIGNAL: {match} Hz (Nyquist Zone {nyquist_zone})")
|
|
71
|
+
print("-" * 30)
|
|
72
|
+
plt.show()
|
|
73
|
+
return {"all_candidates": unique_candidates, "identified_f": match, "nyquist_zone":nyquist_zone}, match
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rf_funcitons_py
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: First package from a notebook
|
|
5
|
+
Author-email: Avery Books <abooks104@gmail.com>
|
|
6
|
+
Requires-Python: >3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
#My First Package
|
|
10
|
+
This package contains my alias source signal identification function
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
rafpy/__init__.py,sha256=YJ7WwLTtUPL2cl7hNS_I75dwn4MiCSuXmjbPVYw0c60,39
|
|
2
|
+
rafpy/logic.py,sha256=OQKlZ-AGGbQu1u-yBSdLdUJrrTVUWcYV897HBbMVJ-s,3966
|
|
3
|
+
rf_funcitons_py-0.1.0.dist-info/METADATA,sha256=ygy2KIe3bJPRDcTwMWUCl9itozjc-Zr9wcZyH9cIFR4,306
|
|
4
|
+
rf_funcitons_py-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
+
rf_funcitons_py-0.1.0.dist-info/top_level.txt,sha256=4q_MXcdbMykJYGFjd_1IVwHk_V3unZSegNAYAUumMnw,6
|
|
6
|
+
rf_funcitons_py-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rafpy
|