import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter
def gfsk_cpm_modulation(data, symbol_rate, bit_rate, modulation_index):
time = np.arange(0, len(data) / bit_rate, 1 / symbol_rate)
modulated_signal = np.zeros_like(time)
phi = 0
for i in range(len(data)):
phi += 2 * np.pi * (bit_rate / symbol_rate) * modulation_index * (data[i] - 0.5)
modulated_signal[i] = np.cos(phi)
return time, modulated_signal
def apply_gaussian_filter(signal, filter_order, cutoff_frequency):
# Design a digital Butterworth low-pass filter
nyquist = 0.5
normal_cutoff = cutoff_frequency / nyquist
b, a = butter(filter_order, normal_cutoff, btype='low', analog=False, output='ba')
# Apply the digital filter
filtered_signal = lfilter(b, a, signal)
return filtered_signal
def main():
# Modulation Parameters
symbol_rate = 1000 # Symbol rate in symbols per second
bit_rate = 1000 # Bit rate in bits per second
modulation_index = 0.5
# Generate random binary data
np.random.seed(42) # For reproducibility
data = np.random.randint(0, 2, size=100)
# Digital filter parameters
filter_order = 8 # Adjust as needed
cutoff_frequency = 0.1 # Adjust as needed (normalized cutoff frequency)
# GFSK-CPM Modulation without Digital filter
time, modulated_signal_before_filter = gfsk_cpm_modulation(data, symbol_rate, bit_rate, modulation_index)
# Apply Digital filter
modulated_signal_after_filter = apply_gaussian_filter(modulated_signal_before_filter, filter_order, cutoff_frequency)
# Plot the GFSK-CPM modulated signals
plt.plot(time, modulated_signal_before_filter, color='blue', label='Before Filter')
plt.plot(time, modulated_signal_after_filter, color='red', label='After Filter (Digital)')
plt.title('GFSK-CPM Modulation with Digital Filter')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.legend()
plt.show()
if __name__ == "__main__":
main()
|