Qpsk
Mon Nov 18 2024 17:28:49 GMT+0000 (Coordinated Universal Time)
Saved by @lord
% Clear workspace, close figures, clear command window clear all; close all; clc; % Parameters n = 10; % Number of symbols m = 4; % QPSK has 4 symbols (0, 1, 2, 3) snr = 20; % Signal-to-Noise Ratio (dB) bit_rate = 10^3; % Bit rate in bits per second f = bit_rate; % Carrier frequency tb = 1 / bit_rate; % Bit duration t = 0:(tb/1000):tb; % Time vector for one symbol % Generate random data data = randi([0 m-1], 1, n); % Random symbols (0, 1, 2, 3) % Perform QPSK modulation s = exp(1j * (2 * pi * data / m + pi/4)); % QPSK symbols with phase offset of pi/4 % Generate the transmitted QPSK signal txsig = []; % Initialize transmitted signal for l = 1:length(data) % Modulate using I and Q components tx = real(s(l)) * cos(2 * pi * f * t) - imag(s(l)) * sin(2 * pi * f * t); txsig = [txsig tx]; % Append the modulated signal for the current symbol end % Add noise to the transmitted signal (Noisy QPSK signal) rxsig = txsig + sqrt(0.5 / (10^(snr/10))) * randn(size(txsig)); % Add noise to the real part % Add noise to QPSK symbols for constellation diagram r = s + sqrt(0.5 / (10^(snr/10))) * (randn(size(s)) + 1j * randn(size(s))); % Plot results figure; % Plot message signal (original symbols) subplot(3, 1, 1); stairs(data, 'LineWidth', 1.5); % Staircase plot for message symbols grid minor; ylim([-0.5, m-0.5]); xlim([0, n]); title('Message Signal (Symbols)'); xlabel('Symbol Index'); ylabel('Symbol Value'); % Plot QPSK modulated signal subplot(3, 1, 2); plot(txsig, 'LineWidth', 1.5); grid minor; title('QPSK Modulated Signal'); xlabel('Time (samples)'); ylabel('Amplitude'); ylim([-1.5, 1.5]); xlim([0, length(txsig)]); % Plot noisy QPSK modulated signal subplot(3, 1, 3); plot(rxsig, 'LineWidth', 1.5); grid minor; title('Noisy QPSK Signal (AWGN Added)'); xlabel('Time (samples)'); ylabel('Amplitude'); xlim([0, length(rxsig)]); % Constellation diagram figure; scatter(real(r), imag(r), 'filled'); % Scatter plot of noisy received symbols grid minor; title('Constellation Diagram of QPSK'); xlabel('In-phase (I)'); ylabel('Quadrature (Q)'); axis([-2 2 -2 2]); % Set axis limits for clarity
Comments