完成2FSK/2ASK仿真。
时间: 2023-07-29 16:09:13 浏览: 107
matlab_2ask、2fsk、2psk仿真_
5星 · 资源好评率100%
以下是一个简单的MATLAB代码,用于模拟2FSK / 2ASK的调制和解调,并绘制误码率曲线:
```
clear all;
close all;
N = 10^6; % 符号数
Eb = 1; % 符号能量
SNRdB = 0:2:16; % 信噪比范围
fs = 100; % 采样频率
fc = 10; % 载波频率
fdev = 5; % 频偏
% 产生随机数据
data = randi([0 1], N, 1);
% 2FSK调制
f1 = fc - fdev;
f2 = fc + fdev;
modSignal1 = sqrt(2 * Eb) * cos(2 * pi * f1 / fs * [0:N-1]' + pi * data);
modSignal2 = sqrt(2 * Eb) * cos(2 * pi * f2 / fs * [0:N-1]' + pi * (1 - data));
modSignal = modSignal1 .* data + modSignal2 .* (1 - data);
% 2ASK调制
modSignal = sqrt(2 * Eb * data) - sqrt(2 * Eb * (1 - data));
for n = 1:length(SNRdB)
% 添加高斯白噪声
SNR = 10^(SNRdB(n)/10);
noiseVar = Eb / SNR;
noise = sqrt(noiseVar) * randn(N, 1);
receivedSignal = modSignal + noise;
% 2FSK解调
demodSignal1 = abs(hilbert(receivedSignal) .* cos(2 * pi * f1 / fs * [0:N-1]' + pi));
demodSignal2 = abs(hilbert(receivedSignal) .* cos(2 * pi * f2 / fs * [0:N-1]' + pi));
demodSignal = demodSignal2 - demodSignal1;
demodSignal(demodSignal < 0) = 0;
demodSignal(demodSignal > 0) = 1;
% 2ASK解调
demodSignal = receivedSignal >= 0.5 * Eb;
% 计算误码率
numErrs = sum(data ~= demodSignal);
BER_FSK(n) = numErrs / N;
BER_ASK(n) = numErrs / N;
end
% 绘制误码率曲线
figure;
semilogy(SNRdB, BER_FSK, 'b-o', 'LineWidth', 2, 'MarkerSize', 8);
hold on;
semilogy(SNRdB, BER_ASK, 'r-*', 'LineWidth', 2, 'MarkerSize', 8);
grid on;
xlabel('SNR (dB)');
ylabel('BER');
title('2FSK和2ASK误码率曲线');
legend('2FSK', '2ASK');
```
您可以使用此代码进行仿真比较,并根据需要进行调整和优化。希望这能对您有所帮助!
阅读全文