从零开始学可见光通信,从开始到绝望…………………………

几点说明。

1. 一般在仿真的时候,大家都喜欢直接做等效基带仿真(类似于星座点的仿真)。

但实际要传,还是要传频带的波形信号。

2. 为了模拟真实的环境,先把基带信号经过一个自定义的信道,然后再做脉冲成型,上变频,加一点噪声AWGN进去。

3. 为了模拟同步,应该用专用的同步算法。但是这里的重点不在同步。所以用了很简单粗暴的办法。假装直接同步上了。

4. 为了造出不同步的结果,可以这样写 x_未同步 = [x(300:end); x; x]; 相当于循环发送,循环接收。

这是仿真。

Main

%%

% 单载波QPSK 接收端

% 2017年5月17日18:02:56

clear;

close all;

clc

rand_seed = 0;

rand('seed',rand_seed);

randn('seed',rand_seed);

%%

% Set up parameters and signals.

M = 4; % Alphabet size for modulation

baud_rate = 100; % Baud rate

f_carrier1 = 75; % Carrier frequency

Nsym = 10000; % Number of symbols

msg = randi([0 M-1],Nsym,1); % Random message

hMod = comm.RectangularQAMModulator(M);

modmsg = step(hMod,msg); % Modulate using QAM. % 映射后的基带信号

trainlen = 1000; % Length of training sequence

rolloff = .3; % 滚降因子

span = 20 ; % 截断长度

sps = 10;  % Samples per symbol

rrcFilter=rcosdesign(rolloff,span,sps,'sqrt'); %根升余弦滚降滤波器,‘sqrt’均方根升余弦;‘normal’升余弦

fs = baud_rate*sps; % 时间采样率,时间采样间隔为 1/fs 秒

Tsymbol=1/baud_rate;

% 2. 脉冲成型

% txSig = upfirdn(modmsg, rrcFilter, sps);  % 发送端的基带复波形信号

% chan = [1; .001];

chan = [.986; .845; .237; .123+.31i]; % Channel coefficients

% chan = [1 0.45 0.3+0.2i]; % Channel coefficients

filtmsg = filter(chan,1,modmsg); % Introduce channel distortion.(已经经过信道的畸变的基带复信号,星座点)

txSig = upfirdn(filtmsg, rrcFilter, sps);  % 发送端的基带复波形信号

txSig = awgn(txSig,20,'measured'); % Add AWGN

t = (0:1/fs:((length(txSig)-1)/fs)).';

T = t(end)+1/fs;

df = 1/T;

freq = -fs/2:df:fs/2-df;

cos1 = cos(2*pi*f_carrier1 * t);

sin1 = sin(2*pi*f_carrier1 * t);

x_upconv = real(txSig).* cos1 + imag(txSig) .* sin1;

%% === 接收端

x_training_wave = x_upconv;

x_training_msg = msg;

rxSig = [x_upconv(300:end) ; x_upconv];

% 1. 同步

x_resampled = resample(rxSig,1,1);

x_sync = sync_two_signals( x_resampled,x_training_wave,0);

figure(2);

plot(freq,20*log10(abs(fftshift(fft(x_sync))/max(abs(fftshift(fft(x_sync)))))));

ylim([-100,10])

xlim([0,freq(end)])

grid on;

xlabel('频率(Hz)');

title('接收信号');

% 2. 下变频 + 匹配滤波

xi_dnconv = x_sync .* cos1;

xq_dnconv = x_sync .* sin1;

x_filtered = xi_dnconv + 1j * xq_dnconv;

rxFilt = upfirdn(x_filtered, rrcFilter, 1, sps);

rxFilt = rxFilt(span+1:end-span); % 这是接收端匹配滤波后的信号

% 3. 均衡

% eq1 = lineareq(6, lms(0.01)); % LMS

eq1 = lineareq(30, rls(0.99,0.01)); % Create an equalizer object. % 40 taps,RLS算法,步长0.99,自相关矩阵逆矩阵的初值InvCorrInit对角线上的元素

eq1.SigConst = step(hMod,(0:M-1)')'; % Set signal constellation. % 标准星座图

[symbolest,~] = equalize(eq1,rxFilt,x_training_msg(1:trainlen)); % Equalize. % 均衡器obj,需要均衡的信号,训练序列

symbolest = symbolest ./ mean(abs(symbolest)) .* mean(abs(eq1.SigConst));

% Plot signals.

h = scatterplot(rxFilt,1,trainlen,'bx'); hold on;

scatterplot(symbolest,1,trainlen,'r.',h);

scatterplot(eq1.SigConst,1,0,'k*',h);

legend('Filtered signal','Equalized signal',...

'Ideal signal constellation');

hold off;

% Compute error rates with equalization.

hDemod = comm.RectangularQAMDemodulator(M);

demodmsg = step(hDemod,symbolest); % Demodulate detected signal from equalizer.

% Create ErrorRate Calculator System object

serVec = step(comm.ErrorRate,msg(trainlen+1:end),demodmsg(trainlen+1:end));

srate = serVec(1)

snum = serVec(2)

% Convert integers to bits

hIntToBit = comm.IntegerToBit(log2(M));

Tx_bit = step(hIntToBit, msg(trainlen+1:end));

Rx_bit = step(hIntToBit, demodmsg(trainlen+1:end));

% Calculate BER

berVec = step(comm.ErrorRate,Rx_bit,Tx_bit);

brate = berVec(1)

bnum = berVec(2)

%%

% 单载波QPSK 接收端

% 2017年5月17日18:02:56

clear;

close all;

clc

rand_seed = 0;

rand('seed',rand_seed);

randn('seed',rand_seed);

%%

% Set up parameters and signals.

M = 4; % Alphabet size for modulation

baud_rate = 100; % Baud rate

f_carrier1 = 75; % Carrier frequency

Nsym = 10000; % Number of symbols

msg = randi([0 M-1],Nsym,1); % Random message

hMod = comm.RectangularQAMModulator(M);

modmsg = step(hMod,msg); % Modulate using QAM. % 映射后的基带信号

trainlen = 1000; % Length of training sequence

rolloff = .3; % 滚降因子

span = 20 ; % 截断长度

sps = 10; % Samples per symbol

rrcFilter=rcosdesign(rolloff,span,sps,'sqrt'); %根升余弦滚降滤波器,‘sqrt’均方根升余弦;‘normal’升余弦

fs = baud_rate*sps; % 时间采样率,时间采样间隔为 1/fs 秒

Tsymbol=1/baud_rate;

% 2. 脉冲成型

% txSig = upfirdn(modmsg, rrcFilter, sps); % 发送端的基带复波形信号

% chan = [1; .001];

chan = [.986; .845; .237; .123+.31i]; % Channel coefficients

% chan = [1 0.45 0.3+0.2i]; % Channel coefficients

filtmsg = filter(chan,1,modmsg); % Introduce channel distortion.(已经经过信道的畸变的基带复信号,星座点)

txSig = upfirdn(filtmsg, rrcFilter, sps); % 发送端的基带复波形信号

txSig = awgn(txSig,20,'measured'); % Add AWGN

t = (0:1/fs:((length(txSig)-1)/fs)).';

T = t(end)+1/fs;

df = 1/T;

freq = -fs/2:df:fs/2-df;

cos1 = cos(2*pi*f_carrier1 * t);

sin1 = sin(2*pi*f_carrier1 * t);

x_upconv = real(txSig).* cos1 + imag(txSig) .* sin1;

%% === 接收端

x_training_wave = x_upconv;

x_training_msg = msg;

rxSig = [x_upconv(300:end) ; x_upconv];

% 1. 同步

x_resampled = resample(rxSig,1,1);

x_sync = sync_two_signals( x_resampled,x_training_wave,0);

figure(2);

plot(freq,20*log10(abs(fftshift(fft(x_sync))/max(abs(fftshift(fft(x_sync)))))));

ylim([-100,10])

xlim([0,freq(end)])

grid on;

xlabel('频率(Hz)');

title('接收信号');

% 2. 下变频 + 匹配滤波

xi_dnconv = x_sync .* cos1;

xq_dnconv = x_sync .* sin1;

x_filtered = xi_dnconv + 1j * xq_dnconv;

rxFilt = upfirdn(x_filtered, rrcFilter, 1, sps);

rxFilt = rxFilt(span+1:end-span); % 这是接收端匹配滤波后的信号

% 3. 均衡

% eq1 = lineareq(6, lms(0.01)); % LMS

eq1 = lineareq(30, rls(0.99,0.01)); % Create an equalizer object. % 40 taps,RLS算法,步长0.99,自相关矩阵逆矩阵的初值InvCorrInit对角线上的元素

eq1.SigConst = step(hMod,(0:M-1)')'; % Set signal constellation. % 标准星座图

[symbolest,~] = equalize(eq1,rxFilt,x_training_msg(1:trainlen)); % Equalize. % 均衡器obj,需要均衡的信号,训练序列

symbolest = symbolest ./ mean(abs(symbolest)) .* mean(abs(eq1.SigConst));

% Plot signals.

h = scatterplot(rxFilt,1,trainlen,'bx'); hold on;

scatterplot(symbolest,1,trainlen,'r.',h);

scatterplot(eq1.SigConst,1,0,'k*',h);

legend('Filtered signal','Equalized signal',...

'Ideal signal constellation');

hold off;

% Compute error rates with equalization.

hDemod = comm.RectangularQAMDemodulator(M);

demodmsg = step(hDemod,symbolest); % Demodulate detected signal from equalizer.

% Create ErrorRate Calculator System object

serVec = step(comm.ErrorRate,msg(trainlen+1:end),demodmsg(trainlen+1:end));

srate = serVec(1)

snum = serVec(2)

% Convert integers to bits

hIntToBit = comm.IntegerToBit(log2(M));

Tx_bit = step(hIntToBit, msg(trainlen+1:end));

Rx_bit = step(hIntToBit, demodmsg(trainlen+1:end));

% Calculate BER

berVec = step(comm.ErrorRate,Rx_bit,Tx_bit);

brate = berVec(1)

bnum = berVec(2)

同步的代码

function x_sync = sync_two_signals( x_resampled,x_training_wave,idx )

% sync_two_signals( x_resampled,x_training_wave,idx )

% x_resampled:收到的信号

% x_training_wave:用发送的信号

% idx:要找同步上的第几段。idx = 1,2,3,...

[hicorrI,lagsiI]=xcorr(x_resampled,x_training_wave);

[~,offsetindex]=max((hicorrI));

% offsetindex

for n = 2 : idx

% figure;plot(lagsiI,abs(hicorrI));

hicorrI(offsetindex) = -inf;

[~,offsetindex]=max(hicorrI);

end

% offsetindex

h=1;

x_sync=x_resampled(lagsiI(offsetindex)+h:lagsiI(offsetindex)+length(x_training_wave)+h-1);

end

function x_sync = sync_two_signals( x_resampled,x_training_wave,idx )

% sync_two_signals( x_resampled,x_training_wave,idx )

% x_resampled:收到的信号

% x_training_wave:用发送的信号

% idx:要找同步上的第几段。idx = 1,2,3,...

[hicorrI,lagsiI]=xcorr(x_resampled,x_training_wave);

[~,offsetindex]=max((hicorrI));

% offsetindex

for n = 2 : idx

% figure;plot(lagsiI,abs(hicorrI));

hicorrI(offsetindex) = -inf;

[~,offsetindex]=max(hicorrI);

end

% offsetindex

h=1;

x_sync=x_resampled(lagsiI(offsetindex)+h:lagsiI(offsetindex)+length(x_training_wave)+h-1);

end

误符号率

srate =  0.0041

错误符号数

snum =  37

误比特率

brate =  0.0021 错误比特数 bnum =  38

qpsk matlab仿真,QPSK 调制与解调(Matlab仿真)相关推荐

  1. 信号的调制与解调matlab仿真,基于MATLAB对信号调制与解调的仿真

    基于MATLAB对信号调制与解调的仿真 2.3 2PSK的基本原理和调制解调实现 数字相移键控,记作PSK(Phase shift-keying ),二进制相位键控记作2PSK. 2PSK就是根据基带 ...

  2. matlab dpsk,2DPSK调制与解调matlab(最新整理)

    <2DPSK调制与解调matlab(最新整理)>由会员分享,可在线阅读,更多相关<2DPSK调制与解调matlab(最新整理)(5页珍藏版)>请在人人文库网上搜索. 1.- 2 ...

  3. QPSK调制与解调-MATLAB基带仿真

    QPSK调制与解调-MATLAB基带仿真 仿真步骤 产生一定长度的值为0或1的随机序列 s ( t ) s(t) s(t). 将 s ( t ) s(t) s(t)映射到QPSK星座图上的星座点. 产 ...

  4. 16QAM调制与解调-MATLAB基带仿真

    16QAM调制与解调-MATLAB基带仿真 ---------------------------- 2020.05.14更新:---------------------------------- 有 ...

  5. matlab对信号进行AM调制与解调(仿真)

    matlab对信号进行AM调制与解调(仿真) 用matlab仿真AM模拟调制.解调过程 AM调制与解调过程 子函数程序 T2F 子函数程序 F2T 子函数程序 lpf 结果如下所示 用matlab仿真 ...

  6. fsk调制matlab 仿真,基于MATLAB对FSK信号调制与解调的仿真

    基于MATLAB对FSK信号调制与解调的仿真 基于 MATLAB 对 FSK 信号调制与解调的仿真摘要 Matlab 平台的著名仿真环境 Simulink 作为一种种专业和功能强大且操作简单的仿真工具 ...

  7. 【基于matlab的mqam调制与解调系统】

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.正交幅度调制原理 二.QAM的解调和判决 三.16QAM调制解调系统的实现与仿真 总结 前言 提示:这里可以添加本 ...

  8. 信号的解调与调制matlab,基于MATLAB常用数字信号调制与解调

    内容简介: 本科毕业设计 基于MATLAB常用数字信号调制与解调 数字通信|MATLAB|ASK|PSK|FSK|调制与解调|毕业设计 文件格式:word+PPT 本科毕业设计 基于MATLAB常用数 ...

  9. matlab显示2dpsk误码率,基于MATLAB的2DPSK调制与解调系统的分析.doc

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp计算机&nbsp>&nbspmatlab 基于MATLAB的2DPSK调制与解调系统的分析. ...

  10. fsk调制解调实验报告 matlab,基于MATLAB的-FSK调制与解调-通信原理实验

    <基于MATLAB的-FSK调制与解调-通信原理实验>由会员分享,可在线阅读,更多相关<基于MATLAB的-FSK调制与解调-通信原理实验(2页珍藏版)>请在人人文库网上搜索. ...

最新文章

  1. K8S的横向自动扩容的功能Horizontal Pod Autoscaling
  2. Linux下的softlink和hardlink(转)
  3. 读《程序员必读的职业规划书》
  4. 航院 1874 畅通工程续
  5. import json java_JAVA的JSON数据包装-博客园老牛大讲
  6. f2 柱状图滚动 钉钉小程序_详解钉钉小程序组件之自定义模态框(弹窗封装实现)...
  7. 政府 开源软件_为什么不是所有的政府软件都是开源的?
  8. 使用nginx为ArcGIS Server做反向代理
  9. linux内存平均值,linux下查看内存使用情况[转载]
  10. Latex排版图片样式
  11. keil优化等级影响STM32 GPIO速度变化
  12. Android 接收和收发短信
  13. 数据如何变成知识(2):数据湖和数据沼泽
  14. 【Houdini】使用Houdini的Karma渲染器渲染流体
  15. uniapp 上传图片 + 预览图片 + 删除图片
  16. 华硕主板设置完成通电开机,接上Wi-Fi智能插座,通电开机无效的原因???
  17. android模拟器如何正确安装HAXM加速器
  18. cad把图形切成两部分_转载一位CAD大神的学习笔记, 初学CAD的人可以看看
  19. 技术是可以量化的,稳定性性能和资产个数
  20. 2020年河南高考--各高校在河南录取分数线预测(本科二批——文科)

热门文章

  1. mysql数据库编程第六章试题_2016年计算机二级MySQL数据库试题及答案
  2. android foobar wifi,foobar2000安卓
  3. Activiti Explorer messages 国际化文件
  4. java properties native2ascii_使用native2ascii针对中文乱码,进行转码操作,用于native2ascii处理properties文件...
  5. Excel任务该如何在FineReader 12中设置
  6. 在VB中用DAO实现数据库编程Java教程
  7. 如何使用动软代码生成器连接oracle生成数据库设计文档
  8. GStreamer 简化 Linux 多媒体开发
  9. Redmi Book14 pro 通过软件控制风扇转速和噪音
  10. ask调制matlab实验,ASK调制的matlab代码