4ask调制某数字系统传输数字序列01101011,基于MATLAB的代码
时间: 2024-02-19 09:03:33 浏览: 33
以下是基于MATLAB的4ASK调制和解调代码,用于传输数字序列“01101011”:
```matlab
% 4ASK调制和解调代码
clc;
clear all;
close all;
% 定义参数
N = 100; % 采样点数
fc = 5; % 载波频率
Tb = 1; % 每个比特的时间
fs = N / Tb; % 采样频率
t = 0 : 1/fs : Tb-1/fs; % 时间向量
A = 1; % 载波振幅
bits = [0 1 1 0 1 0 1 1]; % 待传输的数字序列
L = length(bits); % 序列长度
SNR_dB = 10; % 信噪比
% 4ASK调制
ask = zeros(1, N*L);
for i = 0 : L-1
if bits(i+1) == 0 && bits(i+2) == 0
ask(i*N+1 : (i+1)*N) = A * sin(2*pi*fc*t); % 00
elseif bits(i+1) == 0 && bits(i+2) == 1
ask(i*N+1 : (i+1)*N) = A * sin(2*pi*fc*t + pi/2); % 01
elseif bits(i+1) == 1 && bits(i+2) == 0
ask(i*N+1 : (i+1)*N) = A * sin(2*pi*fc*t + pi); % 10
else
ask(i*N+1 : (i+1)*N) = A * sin(2*pi*fc*t + 3*pi/2); % 11
end
end
% 加入噪声
SNR = 10^(SNR_dB/10);
noise_power = A^2 / SNR;
noise = sqrt(noise_power) * randn(1, length(ask));
ask_noise = ask + noise;
% 绘制4ASK调制信号
figure;
plot(ask_noise);
title('4ASK调制信号');
% 4ASK解调
bits_recv = zeros(1, L);
for i = 0 : L-1
y = ask_noise(i*N+1 : (i+1)*N);
% 计算4个等级的能量
E00 = sum((A*sin(2*pi*fc*t)).^2);
E01 = sum((A*sin(2*pi*fc*t + pi/2)).^2);
E10 = sum((A*sin(2*pi*fc*t + pi)).^2);
E11 = sum((A*sin(2*pi*fc*t + 3*pi/2)).^2);
% 计算接收到的信号与4个等级之间的欧氏距离
d00 = norm(y - A*sin(2*pi*fc*t));
d01 = norm(y - A*sin(2*pi*fc*t + pi/2));
d10 = norm(y - A*sin(2*pi*fc*t + pi));
d11 = norm(y - A*sin(2*pi*fc*t + 3*pi/2));
% 根据欧氏距离选择最可能的等级
if d00 < d01 && d00 < d10 && d00 < d11
bits_recv(i+1) = 0;
bits_recv(i+2) = 0;
elseif d01 < d00 && d01 < d10 && d01 < d11
bits_recv(i+1) = 0;
bits_recv(i+2) = 1;
elseif d10 < d00 && d10 < d01 && d10 < d11
bits_recv(i+1) = 1;
bits_recv(i+2) = 0;
else
bits_recv(i+1) = 1;
bits_recv(i+2) = 1;
end
end
% 绘制4ASK解调结果
figure;
stem(bits_recv);
title('4ASK解调结果');
xlabel('位数');
ylabel('数字');
```
以上代码将数字序列“01101011”进行4ASK调制,并模拟加入了一定的噪声。然后对接收到的信号进行4ASK解调,得到了最终的解调结果。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)