matlab and python QPSK
matlab and python QPSK
matlab and python QPSK
主程式
clear;clc;
close all;
N=10000;
EbN0dB = -4:2:10;
fc=100;
OF =8;
[s,t] = qpsk_mod(a,fc,OF);
N0= Eb/EbN0lin(i);
r= s+ n;
a_cap=qpsk_demod(r,fc,OF);
end
theoreticalBER =0.5*erfc(sqrt(EbN0lin));
子程式1:
L = 2 * OF;
ak = 2 * a - 1;
I = ak(1:2:end);
Q = ak(2:2:end);
I = repmat(I, 1, L).';
Q = repmat(Q, 1, L).';
I = I(:).';
Q = Q(:).';
fs = OF * fc;
t = 0:1/fs:(length(I) - 1) / fs;
s = iChannel + qChannel;
doPlot = 1;
if doPlot == 1
figure;
end
end
子程式2:
fs = OF * fc;
L = 2 * OF;
t = 0:1/fs:(length(r) - 1) / fs;
x = r .* cos(2 * pi * fc * t);
y = -r .* sin(2 * pi * fc * t);
x = conv(x, ones(1, L));
x = x(L:L:end);
y = y(L:L:end);
doPlot = 1;
if doPlot == 1
end
end
結果圖:
Python
theoreticalBER = 0.5*erfc(np.sqrt(10**(EbN0dB/10)))
axs.semilogy(EbN0dB,BER,'k*',label='Simulated')
axs.semilogy(EbN0dB,theoreticalBER,'r-',label='Theoretical')
axs.set_xlabel(r'$E_b/N_0$ (dB)')
axs.legend();fig.show()
Discussion:In the QPSK modulation experiment, we generated the in-phase (I(t)I(t)) and quadrature-
phase (Q(t)Q(t)) components as baseband signals, representing the digital data to be transmitted.
These baseband signals were modulated using a carrier frequency; the I(t)I(t) component was
modulated with a cosine carrier, while the Q(t)Q(t) component was modulated with a sine carrier. The
combination of these modulated signals resulted in the QPSK signal s(t)s(t), which exhibited phase
changes corresponding to the digital input data. The bit error rate (BER) performance of the QPSK
modulation was evaluated by plotting the probability of bit error (Pb) against the energy per bit to
noise power spectral density ratio (Eb/N0). The BER curve, showing both simulated and theoretical
values, demonstrated a good agreement between the two. This alignment indicates that the
simulation accurately represents the theoretical performance of QPSK modulation. As expected, the
probability of bit error decreases as Eb/N0 increases, meaning that higher signal-to-noise ratios
(SNR) result in better performance and fewer errors. The results showed that QPSK modulation
maintains signal integrity even at relatively low SNRs, which is critical for reliable digital
communication. Overall, the experiment confirms the robustness and efficiency of QPSK modulation
in digital communication systems. The close match between the simulated and theoretical BER
curves validates the effectiveness of QPSK in reducing bit errors and maintaining data integrity,
making it a suitable choice for various communication applications where bandwidth efficiency and
signal reliability are essential.