Tuesday, 20 May 2025

Signal Interference Mesh Pattern using Python


import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

x = np.linspace(-10, 10, 200)

y = np.linspace(-10, 10, 200)

X, Y = np.meshgrid(x, y)

sources = [

    {'center': (-3, -3), 'freq': 2.5},

    {'center': (3, 3), 'freq': 3.0},

    {'center': (-3, 3), 'freq': 1.8},

]

Z = np.zeros_like(X)

for src in sources:

    dx = X - src['center'][0]

    dy = Y - src['center'][1]

    r = np.sqrt(dx**2 + dy**2) + 1e-6  

    Z += np.sin(src['freq'] * r) / r  

fig = plt.figure(figsize=(6, 8))

ax = fig.add_subplot(111, projection='3d')

ax.plot_wireframe(X, Y, Z, rstride=3, cstride=3, color='mediumblue', alpha=0.8, linewidth=0.5)

ax.set_title("Signal Interference Mesh", fontsize=16)

ax.set_xlabel("X")

ax.set_ylabel("Y")

ax.set_zlabel("Amplitude")

ax.set_box_aspect([1,1,0.5])

plt.tight_layout()

plt.show()

#source code --> clcoding.com

Code Explanation:

1. Importing Required Libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
Explanation:
numpy (as np) is used for efficient array manipulation and mathematical operations.
matplotlib.pyplot (as plt) is used for plotting 2D/3D graphs.
mpl_toolkits.mplot3d.Axes3D enables 3D plotting with Matplotlib.

2. Creating the Grid
x = np.linspace(-10, 10, 200)
y = np.linspace(-10, 10, 200)
X, Y = np.meshgrid(x, y)
Explanation:
np.linspace(-10, 10, 200) creates 200 evenly spaced points between -10 and 10 for both x and y.
np.meshgrid(x, y) creates 2D grid coordinates X and Y, representing the Cartesian plane over which signals will be calculated.

3. Defining Signal Sources
sources = [
    {'center': (-3, -3), 'freq': 2.5},
    {'center': (3, 3), 'freq': 3.0},
    {'center': (-3, 3), 'freq': 1.8},
]
Explanation:
This list defines 3 point sources, each with:
A center coordinate in 2D space (x, y)
A freq (frequency) value that affects the signal's oscillation

4. Calculating the Resulting Signal
Z = np.zeros_like(X)
for src in sources:
    dx = X - src['center'][0]
    dy = Y - src['center'][1]
    r = np.sqrt(dx**2 + dy**2) + 1e-6
    Z += np.sin(src['freq'] * r) / r
Explanation:
Z = np.zeros_like(X) initializes a 2D grid to accumulate the total signal amplitude at each point.
For each source:
dx, dy: distance in X and Y from the source center.
r: radial distance from the source to each grid point (with a small epsilon added to avoid division by zero).
np.sin(freq * r) / r: simulates a wave signal from a point source that decays with distance.
These signals are added together to simulate interference.

5. Plotting the 3D Wireframe
fig = plt.figure(figsize=(6, 8))
ax = fig.add_subplot(111, projection='3d')
Explanation:
A figure object is created with a specified size (6x8 inches).
add_subplot(111, projection='3d') creates a 3D axis for plotting.

6. Rendering the Mesh Plot
ax.plot_wireframe(X, Y, Z, rstride=3, cstride=3, color='mediumblue', alpha=0.8, linewidth=0.5)
Explanation:
plot_wireframe creates a mesh-style 3D plot showing how the signal amplitude varies.
rstride and cstride control mesh resolution.
color, alpha, and linewidth adjust aesthetics.

7. Setting Titles and Labels
ax.set_title("Signal Interference Mesh", fontsize=16)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Amplitude")
ax.set_box_aspect([1,1,0.5])
Explanation:
Adds a title and axis labels to explain what the axes represent.
set_box_aspect controls the 3D plot's aspect ratio for better visual balance.

8. Finalizing and Displaying the Plot
plt.tight_layout()
plt.show()
Explanation:
tight_layout() adjusts spacing to prevent clipping.
show() renders the final interactive 3D plot window.


 

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (118) AI (152) Android (25) AngularJS (1) Api (6) Assembly Language (2) aws (27) Azure (8) BI (10) Books (251) Bootcamp (1) C (78) C# (12) C++ (83) Course (84) Coursera (298) Cybersecurity (28) Data Analysis (24) Data Analytics (16) data management (15) Data Science (217) Data Strucures (13) Deep Learning (68) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (17) Finance (9) flask (3) flutter (1) FPL (17) Generative AI (47) Git (6) Google (47) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (186) Meta (24) MICHIGAN (5) microsoft (9) Nvidia (8) Pandas (11) PHP (20) Projects (32) Python (1218) Python Coding Challenge (884) Python Quiz (342) Python Tips (5) Questions (2) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (45) Udemy (17) UX Research (1) web application (11) Web development (7) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)