Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,12 +10,19 @@ load_dotenv()
|
|
10 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
11 |
|
12 |
# Functions for Antenna Calculations
|
13 |
-
def calculate_microstrip_patch(frequency, permittivity, thickness):
|
14 |
c = 3e8 # Speed of light in m/s
|
15 |
wavelength = c / frequency
|
16 |
effective_wavelength = wavelength / np.sqrt(permittivity)
|
17 |
patch_length = effective_wavelength / 2
|
18 |
patch_width = wavelength / (2 * np.sqrt(1 + permittivity))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
return patch_length, patch_width, thickness
|
20 |
|
21 |
def calculate_dipole_antenna(frequency):
|
@@ -93,12 +100,12 @@ def plot_radiation_pattern(theta, gain_pattern):
|
|
93 |
return fig
|
94 |
|
95 |
# Main Function
|
96 |
-
def design_antenna(antenna_type, frequency, permittivity, thickness):
|
97 |
frequency_hz = frequency * 1e9
|
98 |
frequencies = np.linspace(frequency - 0.5, frequency + 0.5, 100)
|
99 |
|
100 |
if antenna_type == "Microstrip Patch":
|
101 |
-
patch_length, patch_width, thickness = calculate_microstrip_patch(frequency_hz, permittivity, thickness)
|
102 |
s11_values = [calculate_s11(f) for f in frequencies]
|
103 |
directivities, gains = zip(*[calculate_directivity_and_gain(f) for f in frequencies])
|
104 |
theta = np.linspace(-180, 180, 360)
|
@@ -114,6 +121,7 @@ def design_antenna(antenna_type, frequency, permittivity, thickness):
|
|
114 |
f"Operating Frequency: {frequency:.2f} GHz\n"
|
115 |
f"S11 at Operating Frequency: {s11_values[len(s11_values)//2]:.2f} dB\n"
|
116 |
f"Patch Dimensions: {patch_length:.2f} m x {patch_width:.2f} m x {thickness:.2f} m\n"
|
|
|
117 |
)
|
118 |
|
119 |
elif antenna_type == "Dipole":
|
@@ -148,6 +156,7 @@ with gr.Blocks() as demo:
|
|
148 |
frequency = gr.Slider(1.0, 10.0, step=0.1, label="Operating Frequency (GHz)")
|
149 |
permittivity = gr.Number(value=4.4, label="Substrate Permittivity")
|
150 |
thickness = gr.Number(value=0.01, label="Substrate Thickness (m)")
|
|
|
151 |
design_button = gr.Button("Design Antenna")
|
152 |
output_text = gr.Textbox(label="Design Results")
|
153 |
s11_plot = gr.Plot(label="S11 Plot")
|
@@ -157,7 +166,7 @@ with gr.Blocks() as demo:
|
|
157 |
|
158 |
design_button.click(
|
159 |
design_antenna,
|
160 |
-
inputs=[antenna_type, frequency, permittivity, thickness],
|
161 |
outputs=[output_text, s11_plot, directivity_gain_plot, radiation_pattern_plot, antenna_3d_display]
|
162 |
)
|
163 |
|
|
|
10 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
11 |
|
12 |
# Functions for Antenna Calculations
|
13 |
+
def calculate_microstrip_patch(frequency, permittivity, thickness, tangent_loss):
|
14 |
c = 3e8 # Speed of light in m/s
|
15 |
wavelength = c / frequency
|
16 |
effective_wavelength = wavelength / np.sqrt(permittivity)
|
17 |
patch_length = effective_wavelength / 2
|
18 |
patch_width = wavelength / (2 * np.sqrt(1 + permittivity))
|
19 |
+
|
20 |
+
# Adjustments for tangent loss (approximation)
|
21 |
+
# The tangent loss will slightly affect the width and length of the patch
|
22 |
+
adjustment_factor = 1 + tangent_loss / 10
|
23 |
+
patch_length *= adjustment_factor
|
24 |
+
patch_width *= adjustment_factor
|
25 |
+
|
26 |
return patch_length, patch_width, thickness
|
27 |
|
28 |
def calculate_dipole_antenna(frequency):
|
|
|
100 |
return fig
|
101 |
|
102 |
# Main Function
|
103 |
+
def design_antenna(antenna_type, frequency, permittivity, thickness, tangent_loss):
|
104 |
frequency_hz = frequency * 1e9
|
105 |
frequencies = np.linspace(frequency - 0.5, frequency + 0.5, 100)
|
106 |
|
107 |
if antenna_type == "Microstrip Patch":
|
108 |
+
patch_length, patch_width, thickness = calculate_microstrip_patch(frequency_hz, permittivity, thickness, tangent_loss)
|
109 |
s11_values = [calculate_s11(f) for f in frequencies]
|
110 |
directivities, gains = zip(*[calculate_directivity_and_gain(f) for f in frequencies])
|
111 |
theta = np.linspace(-180, 180, 360)
|
|
|
121 |
f"Operating Frequency: {frequency:.2f} GHz\n"
|
122 |
f"S11 at Operating Frequency: {s11_values[len(s11_values)//2]:.2f} dB\n"
|
123 |
f"Patch Dimensions: {patch_length:.2f} m x {patch_width:.2f} m x {thickness:.2f} m\n"
|
124 |
+
f"Substrate Tangent Loss: {tangent_loss:.2f}\n"
|
125 |
)
|
126 |
|
127 |
elif antenna_type == "Dipole":
|
|
|
156 |
frequency = gr.Slider(1.0, 10.0, step=0.1, label="Operating Frequency (GHz)")
|
157 |
permittivity = gr.Number(value=4.4, label="Substrate Permittivity")
|
158 |
thickness = gr.Number(value=0.01, label="Substrate Thickness (m)")
|
159 |
+
tangent_loss = gr.Number(value=0.02, label="Substrate Tangent Loss (tan δ)", step=0.01)
|
160 |
design_button = gr.Button("Design Antenna")
|
161 |
output_text = gr.Textbox(label="Design Results")
|
162 |
s11_plot = gr.Plot(label="S11 Plot")
|
|
|
166 |
|
167 |
design_button.click(
|
168 |
design_antenna,
|
169 |
+
inputs=[antenna_type, frequency, permittivity, thickness, tangent_loss],
|
170 |
outputs=[output_text, s11_plot, directivity_gain_plot, radiation_pattern_plot, antenna_3d_display]
|
171 |
)
|
172 |
|