JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
16 days ago1 views
👨‍💻Programming

Untitled Page

import numpy as np
import matplotlib.pyplot as plt

# Parameters
N = 20
symbol_rate = 1000
sampling_rate = 4000
samples_per_symbol = sampling_rate // symbol_rate

# Generate random binary data
bits = np.random.randint(0, 2, N)

# ASK/OOK mapping: 0 -> 0, 1 -> 1
symbols = bits.astype(float)

# Generate rectangular NRZ pulses
ask_signal = np.repeat(symbols, samples_per_symbol)

# Display transmitted bits
print("Input bits:")
print(bits)

# Plot ASK/OOK signal
plt.figure(figsize=(10, 4))
plt.step(np.arange(len(ask_signal)), ask_signal, where="post")
plt.title("Binary ASK/OOK Baseband Signal")
plt.xlabel("Sample Index")
plt.ylabel("Amplitude")
plt.ylim(-0.2, 1.2)
plt.grid(True)
plt.show()


import numpy as np
import matplotlib.pyplot as plt

# Parameters
N = 100000
symbol_rate = 1000
sampling_rate = 4000
samples_per_symbol = sampling_rate // symbol_rate
noise_variance = 0.5

# Generate random bits
bits = np.random.randint(0, 2, N)

# ASK/OOK mapping
symbols = bits.astype(float)

# Generate rectangular pulses
tx_signal = np.repeat(symbols, samples_per_symbol)

# Add Gaussian noise
noise = np.random.normal(
    0, np.sqrt(noise_variance), len(tx_signal)
)
rx_signal = tx_signal + noise

# Matched-filter operation: average each group of 4 samples
rx_symbols = rx_signal.reshape(
    N, samples_per_symbol
).mean(axis=1)

# Decision threshold
detected_bits = (rx_symbols > 0.5).astype(int)

# Calculate BER
errors = np.sum(bits != detected_bits)
ber = errors / N

# Display results
print("BER Analysis of ASK/OOK")
print("-----------------------")
print("Total bits:", N)
print("Noise variance:", noise_variance)
print("Number of errors:", errors)
print("BER:", ber)

# Plot transmitted and detected bits
plt.figure(figsize=(10, 4))
plt.step(np.arange(20), bits[:20], where="post",
         label="Transmitted bits")
plt.step(np.arange(20), detected_bits[:20], where="post",
         label="Detected bits", linestyle="--")
plt.title("Transmitted vs Detected Bits")
plt.xlabel("Bit Index")
plt.ylabel("Bit Value")
plt.legend()
plt.grid(True)
plt.show()

⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.

← Back to timeline