Question: fix matlab code % Define parameters M = [ 2 , 4 , 8 ] ; % Modulation orders num _ symbols = 1 e

fix matlab code
% Define parameters
M =[2,4,8]; % Modulation orders
num_symbols =1e6; % Number of symbols to simulate
SNR_db =-2:2:20; % SNR range in dB
EbN_db = SNR_db -10*log10(log2(M)); % Convert SNR to Eb/N in dB
% Initialize variables
theoretical_SER_psk = zeros(length(EbN_db),1);
theoretical_SER_mfsk = zeros(length(EbN_db),1);
simulated_SER = zeros(length(EbN_db), length(M));
% Loop through modulation schemes
for m =1:length(M)
% Loop through Eb/N values
for i =1:length(EbN_db)
% Generate random symbols
data_bits = randi(M, num_symbols, 1);
% Modulate symbols
if m ==1
modulated_signal = pskmod(data_bits, M);
else
modulated_signal = fskmod(data_bits, M,2);
end
% Add AWGN noise
received_signal = awgn(modulated_signal, EbN_db(i));
% Demodulate symbols
if m ==1
demodulated_data = pskdemod(received_signal, M);
else
demodulated_data = fskdemod(received_signal, M,2);
end
% Calculate symbol error rate
simulated_SER(i, m)= sum(data_bits ~= demodulated_data)/ num_symbols;
% Theoretical symbol error rate (MPSK)
theoretical_SER_psk(i)= qfunc(sqrt(2*10^(EbN_db(i)/10)));
% Theoretical symbol error rate (MFSK)
theoretical_SER_mfsk(i)=(1-1/M)* qfunc(sqrt(3/(M-1)*10^(EbN_db(i)/10)));
end
end
% Plot results
figure;
semilogy(EbN_db, theoretical_SER_psk,'b-', 'LineWidth', 2);
hold on;
semilogy(EbN_db, theoretical_SER_mfsk,'g-', 'LineWidth', 2);
for m =1:length(M)
semilogy(EbN_db, simulated_SER(:, m),'o-', 'MarkerSize', 8);
end
xlabel('Eb/N (dB)');
ylabel('Symbol Error Rate (SER)');
title('SER vs. Eb/N for MPSK and MFSK');
legend('MPSK Theory', 'MFSK Theory', 'M=2 Simulation', 'M=4 Simulation', 'M=8 Simulation');
grid on;
% Compare results
disp('Observations:');
for m =1:length(M)
disp(['For M=', num2str(M(m)),':']);
disp(['- Simulated SER generally agrees with theoretical SER for high Eb/N.']);
disp(['- At low Eb/N, simulated SER may deviate slightly due to simulation limitations.']);
end
Arrays have incompatible sizes for this operation.
Related documentation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!