hussain2010 commited on
Commit
688a3e3
·
verified ·
1 Parent(s): 76c7608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -3
app.py CHANGED
@@ -18,6 +18,12 @@ def calculate_microstrip_patch(frequency, permittivity, thickness):
18
  patch_width = wavelength / (2 * np.sqrt(1 + permittivity))
19
  return patch_length, patch_width, thickness
20
 
 
 
 
 
 
 
21
  def calculate_s11(frequency):
22
  # Simulate S11 (just an example function for demonstration)
23
  s11 = -20 + 5 * np.cos(2 * np.pi * frequency / 10)
@@ -56,6 +62,16 @@ def plot_3d_microstrip_patch(patch_length, patch_width, thickness):
56
  fig.update_layout(title="3D Microstrip Patch Antenna", showlegend=False)
57
  return fig
58
 
 
 
 
 
 
 
 
 
 
 
59
  def plot_s11_graph(frequencies, s11_values):
60
  fig = go.Figure()
61
  fig.add_trace(go.Scatter(x=frequencies, y=s11_values, mode='lines', name="S11"))
@@ -99,8 +115,28 @@ def design_antenna(antenna_type, frequency, permittivity, thickness):
99
  f"S11 at Operating Frequency: {s11_values[len(s11_values)//2]:.2f} dB\n"
100
  f"Patch Dimensions: {patch_length:.2f} m x {patch_width:.2f} m x {thickness:.2f} m\n"
101
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  else:
103
- output = "Currently, only Microstrip Patch Antenna is supported."
104
  s11_graph, directivity_gain_graph, radiation_graph, antenna_3d = None, None, None, None
105
 
106
  return output, s11_graph, directivity_gain_graph, radiation_graph, antenna_3d
@@ -108,7 +144,7 @@ def design_antenna(antenna_type, frequency, permittivity, thickness):
108
  # Gradio Interface
109
  with gr.Blocks() as demo:
110
  gr.Markdown("# Antenna Design Tool with Groq API")
111
- antenna_type = gr.Dropdown(["Microstrip Patch"], label="Select Antenna Type")
112
  frequency = gr.Slider(1.0, 10.0, step=0.1, label="Operating Frequency (GHz)")
113
  permittivity = gr.Number(value=4.4, label="Substrate Permittivity")
114
  thickness = gr.Number(value=0.01, label="Substrate Thickness (m)")
@@ -125,4 +161,4 @@ with gr.Blocks() as demo:
125
  outputs=[output_text, s11_plot, directivity_gain_plot, radiation_pattern_plot, antenna_3d_display]
126
  )
127
 
128
- demo.launch()
 
18
  patch_width = wavelength / (2 * np.sqrt(1 + permittivity))
19
  return patch_length, patch_width, thickness
20
 
21
+ def calculate_dipole_antenna(frequency):
22
+ c = 3e8 # Speed of light in m/s
23
+ wavelength = c / frequency
24
+ dipole_length = wavelength / 2 # Length of dipole antenna is half wavelength
25
+ return dipole_length
26
+
27
  def calculate_s11(frequency):
28
  # Simulate S11 (just an example function for demonstration)
29
  s11 = -20 + 5 * np.cos(2 * np.pi * frequency / 10)
 
62
  fig.update_layout(title="3D Microstrip Patch Antenna", showlegend=False)
63
  return fig
64
 
65
+ def plot_3d_dipole_antenna(dipole_length):
66
+ fig = go.Figure()
67
+ fig.add_trace(go.Scatter3d(
68
+ x=[0, dipole_length], y=[0, 0], z=[0, 0], marker=dict(size=5, color='red'),
69
+ line=dict(color='red', width=4), name="Dipole Antenna"
70
+ ))
71
+ fig.update_layout(title="3D Dipole Antenna", scene=dict(
72
+ xaxis_title='Length (m)', yaxis_title='Y', zaxis_title='Z'))
73
+ return fig
74
+
75
  def plot_s11_graph(frequencies, s11_values):
76
  fig = go.Figure()
77
  fig.add_trace(go.Scatter(x=frequencies, y=s11_values, mode='lines', name="S11"))
 
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":
120
+ dipole_length = calculate_dipole_antenna(frequency_hz)
121
+ s11_values = [calculate_s11(f) for f in frequencies]
122
+ directivities, gains = zip(*[calculate_directivity_and_gain(f) for f in frequencies])
123
+ theta = np.linspace(-180, 180, 360)
124
+ gain_pattern = radiation_pattern(theta, frequency_hz)
125
+
126
+ s11_graph = plot_s11_graph(frequencies, s11_values)
127
+ directivity_gain_graph = plot_directivity_and_gain(frequencies, directivities, gains)
128
+ radiation_graph = plot_radiation_pattern(theta, gain_pattern)
129
+ antenna_3d = plot_3d_dipole_antenna(dipole_length)
130
+
131
+ output = (
132
+ f"Design Type: Dipole Antenna\n"
133
+ f"Operating Frequency: {frequency:.2f} GHz\n"
134
+ f"S11 at Operating Frequency: {s11_values[len(s11_values)//2]:.2f} dB\n"
135
+ f"Dipole Length: {dipole_length:.2f} m\n"
136
+ )
137
+
138
  else:
139
+ output = "Currently, only Microstrip Patch and Dipole Antenna are supported."
140
  s11_graph, directivity_gain_graph, radiation_graph, antenna_3d = None, None, None, None
141
 
142
  return output, s11_graph, directivity_gain_graph, radiation_graph, antenna_3d
 
144
  # Gradio Interface
145
  with gr.Blocks() as demo:
146
  gr.Markdown("# Antenna Design Tool with Groq API")
147
+ antenna_type = gr.Dropdown(["Microstrip Patch", "Dipole"], label="Select Antenna Type")
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)")
 
161
  outputs=[output_text, s11_plot, directivity_gain_plot, radiation_pattern_plot, antenna_3d_display]
162
  )
163
 
164
+ demo.launch()