2psk和2DPSK误码率程序MATLAB
时间: 2024-02-21 17:00:52 浏览: 23
下面是2PSK和2DPSK误码率的MATLAB仿真程序。
2PSK误码率程序MATLAB:
```matlab
% 2-PSK bit error rate (BER) simulation
% Define the parameters
numBits = 1e6; % Number of bits to be transmitted
EbNo_Vec = 0:1:10; % Eb/No values to simulate (in dB)
M = 2; % Number of symbols in the constellation
k = log2(M); % Number of bits per symbol
numSamplesPerSymbol = 1; % Oversampling factor
% Generate a random bit stream
dataIn = randi([0 1],numBits,1);
% Modulate the data using 2-PSK
dataMod = pskmod(dataIn,M);
% Loop over different Eb/No values
for n = 1:length(EbNo_Vec)
% Convert Eb/No to SNR
snrdB(n) = EbNo_Vec(n) + 10*log10(k) - 10*log10(numSamplesPerSymbol);
noiseVar(n) = 1/(10^(snrdB(n)/10));
% Add Gaussian noise to the modulated signal
receivedSignal = awgn(dataMod,snrdB(n),'measured');
% Demodulate the received signal using 2-PSK
dataOut = pskdemod(receivedSignal,M);
% Calculate the bit error rate (BER)
bitErrRate(n) = sum(xor(dataIn,dataOut))/numBits;
end
% Plot the results
semilogy(EbNo_Vec,bitErrRate,'-*')
grid on
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
title('2-PSK Bit Error Rate')
```
2DPSK误码率程序MATLAB:
```matlab
% 2-DPSK bit error rate (BER) simulation
% Define the parameters
numBits = 1e6; % Number of bits to be transmitted
EbNo_Vec = 0:1:10; % Eb/No values to simulate (in dB)
M = 4; % Number of symbols in the constellation
k = log2(M); % Number of bits per symbol
numSamplesPerSymbol = 1; % Oversampling factor
% Generate a random bit stream
dataIn = randi([0 1],numBits,1);
% Modulate the data using 2-DPSK
dataMod = dpskmod(dataIn,M);
% Loop over different Eb/No values
for n = 1:length(EbNo_Vec)
% Convert Eb/No to SNR
snrdB(n) = EbNo_Vec(n) + 10*log10(k) - 10*log10(numSamplesPerSymbol);
noiseVar(n) = 1/(10^(snrdB(n)/10));
% Add Gaussian noise to the modulated signal
receivedSignal = awgn(dataMod,snrdB(n),'measured');
% Demodulate the received signal using 2-DPSK
dataOut = dpskdemod(receivedSignal,M);
% Calculate the bit error rate (BER)
bitErrRate(n) = sum(xor(dataIn,dataOut))/numBits;
end
% Plot the results
semilogy(EbNo_Vec,bitErrRate,'-*')
grid on
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
title('2-DPSK Bit Error Rate')
```
其中,pskmod和pskdemod是MATLAB中的2PSK调制和解调函数,dpskmod和dpskdemod是MATLAB中的2DPSK调制和解调函数。