this is the matlab code I'm working on to get the demodulated signal without adding any noise or considering the channel
% Adaptive CPFSK Modulation and Demodulation
% Parameters
bitrate = 1000; % Bit rate in bits per second
frequency_deviation = 50.0; % Peak frequency deviation in Hertz
bits = [1 1 1 0 0 0 0 0 0 0 1 0 1 1 1]; % Input binary data
% Initialize modulation parameters
initial_modulation_index = 0.5;
modulation_index = initial_modulation_index;
% Generate CPFSK signal with the chosen modulation index
[time, cpfsk_signal] = cpfsk_modulation(bits, bitrate, frequency_deviation, modulation_index);
% Simulate channel effects (you can replace this with your channel model)
received_signal = awgn(cpfsk_signal, 10); % Adding AWGN for demonstration
% Perform adaptive CPFSK demodulation
%%%%%%%%%%demodulated_bits = adaptive_cpfsk_demodulation(received_signal, bitrate, frequency_deviation);
% Assuming received_signal is the received CPFSK signal with AWGN
% Use the snr function to calculate the SNR
estimated_snr = snr(received_signal, cpfsk_signal);
% Estimate the noise power based on SNR
noise_power = var(cpfsk_signal) / (10^(estimated_snr/10));
% Remove the AWGN using the estimated noise power
clean_signal = received_signal - sqrt(noise_power) * randn(size(received_signal));
% Perform adaptive CPFSK demodulation on the clean signal
demodulated_bits = adaptive_cpfsk_demodulation(clean_signal, bitrate, frequency_deviation);
% Plot the constellation diagram
figure;
plot(cpfsk_signal(1:end-1), cpfsk_signal(2:end), 'o');
title('CPFSK Constellation Diagram');
xlabel('In-phase Component');
ylabel('Quadrature Component');
axis square;
grid on;
% Display the results
disp('Original Bits:');
disp(bits);
disp('Demodulated Bits:');
disp(demodulated_bits);
% Count bit errors
bit_errors = sum(bits ~= demodulated_bits);
% Calculate bit error rate (BER)
ber = bit_errors / length(bits);
% Display the results
disp(['Number of Bit Errors: ' num2str(bit_errors)]);
disp(['Bit Error Rate (BER): ' num2str(ber)]);
% Adaptive CPFSK demodulation function
function demodulated_bits = adaptive_cpfsk_demodulation(received_signal, bitrate, frequency_deviation)
% Implement adaptive CPFSK demodulation.
% You can implement an adaptive algorithm to estimate the modulation
% index based on the received signal characteristics.
% For simplicity, a fixed modulation index is used in this example.
% Fixed modulation index for demonstration
modulation_index = 0.5;
% Perform CPFSK demodulation
demodulated_bits = cpfsk_demodulation(received_signal, bitrate, frequency_deviation, modulation_index);
end
% CPFSK modulation function
function [time, cpfsk_signal] = cpfsk_modulation(bits, bitrate, frequency_deviation, modulation_index)
% Generate a Wideband Continuous Phase Frequency Shift Keying (CPFSK) signal.
% Time vector
time = 0:1/bitrate:(length(bits)-1)/bitrate;
% Generate the phase of the CPFSK signal
phase = 2 * pi * frequency_deviation / bitrate * time + ...
2 * pi * modulation_index * cumsum(bits) / bitrate;
% Create the CPFSK signal
cpfsk_signal = cos(phase);
end
% CPFSK demodulation function
function demodulated_bits = cpfsk_demodulation(received_signal, bitrate, frequency_deviation, modulation_index)
% Demodulate a CPFSK signal using a non-coherent approach.
% Time vector
time = 0:1/bitrate:(length(received_signal)-1)/bitrate;
% Compute the phase of the received signal
received_phase = 2 * pi * frequency_deviation / bitrate * time + ...
2 * pi * modulation_index * cumsum(received_signal) / bitrate;
% Perform non-coherent demodulation
demodulated_bits = diff(received_phase) > 0;
% Pad the demodulated bits to match the original length
demodulated_bits = [demodulated_bits(1), demodulated_bits];
end
here I have attached my complete code of modulation and demodulation. modulation function and demodulation are working fine but the bit stream at the output is not the same as the input bitstream. this is not adaptive CPFSK i need to convert it to adaptive CPFSK but it is not even simply demodulating my input stream. how can i do this using adaptive CFSK i.e. modulation index should be variable I want to get the correct input stream demodulated.