Matlab示例-Examine 16-QAM Using MATLAB学习笔记

​工作之余学习16-QAM

写在前面

网上看到许多示例,但一般都比较难以跑通。所以,还是老方法,先将matlab自带的例子研究下。
Examine 16-QAM Using MATLAB

Examine 16-QAM Using MATLAB

或者,在matlab中,键入:

openExample(‘comm/Examine16QAMUsingMATLABExample’)

会打开:

~\Document\MATLAB\Examples\R2022b\comm\Examine16QAMUsingMATLABExample

不得不感叹,WathWorks公司,依然在飞速的进步,其文档代码一体化能力,已经非常强了。
要注意有梯子之后,这个例子,可以直接在浏览器中运行和单步Trace.
在这里插入图片描述在这里插入图片描述不由得有些哀叹。软件这东西怎么说呢,越落后,就越落后。因为人家是在加速,我们则永远在零和搞一年就放弃归零的循环中。

我们能想象,如果MathWorks是中国公司,当你和老板说,我们也开发个网页版的调试器后,老板第一件事就问你这有用吗?这耽误我们挣钱吗?好吧,这玩意真的没什么用处,但真的是太cool了。
而且,下面就是有用的地方:

【注意】Matlab的示例,网页中的一般是最新的,而我们安装好的matlab所带的例子,往往,存在一些小的缺陷,并没有得到修正。

所以,当发生怀疑是不是哪里出错的时候,可以将被怀疑的代码段,与网页版的代码section 进行下比较。

比如当前的这个例子,的最后一段:

网页版是:

scatterplot(symgray,1,0,'b*');
for k = 1:Mtext(real(symgray(k)) - 0.0,imag(symgray(k)) + 0.3, ...dec2base(x(k),2,4),'Color',[0 1 0]);text(real(symgray(k)) - 0.5,imag(symgray(k)) + 0.3, ...num2str(x(k)),'Color',[0 1 0]);text(real(symbin(k)) - 0.0,imag(symbin(k)) - 0.3, ...dec2base(x(k),2,4),'Color',[1 0 0]);text(real(symbin(k)) - 0.5,imag(symbin(k)) - 0.3, ...num2str(x(k)),'Color',[1 0 0]);
end
title('16-QAM Symbol Mapping')
axis([-4 4 -4 4])

可是matlab中:

scatterplot(symgray,1,0,'b*');
for k = 1:Mtext(real(symgray(k)) - 0.0,imag(symgray(k)) + 0.3, ...dec2base(x(k),2,4));text(real(symgray(k)) - 0.5,imag(symgray(k)) + 0.3, ...num2str(x(k)));text(real(symbin(k)) - 0.0,imag(symbin(k)) - 0.3, ...dec2base(x(k),2,4),'Color',[1 0 0]);text(real(symbin(k)) - 0.5,imag(symbin(k)) - 0.3, ...num2str(x(k)),'Color',[1 0 0]);
end
title('16-QAM Symbol Mapping')
axis([-4 4 -4 4])

​要注意,matlab中的代码,for循环中,少了一小段:
dec2base(x(k),2,4),‘Color’,[0 1 0]);
少了的这段Color,对我这样的学习的人,还是造成了一定的困扰。
初学者,在实操时,往往同时面对几个到十几个知识要学习,难以确定自己哪里是可以确认的。
正确的图像是这样的(在Web Cloud版跑出来的):
在这里插入图片描述
下面不对的是这样的:
在这里插入图片描述
所以,我很久都没有看懂——因为这张图。
看原图,很清楚是想让我们了解自然码与Gray Code的区别。

修改第一部分代码

这个示例的第一段是准备数据。

dataIn = randi([0 1],n,1); % Generate vector of binary data

但这一段,对于我来说,是不太喜欢的。因为作为初学者,要可控。
所以,我打算将数据进行变换,变换成为标准的0,1,2,3,…,15的样子。
所以,这是我第一步要做的。
在与ChatGPT进行了一番不对等的沟通之后,大致改好了,事实上,我花了不少时间。。。

clc;
clear all;
close all;M = 16; % Modulation order (alphabet size or number of points in signal constellation)
k = log2(M); % Number of bits per symbol
n = 256; % Number of bits to process
sps = 1; % Number of samples per symbol (oversampling factor)

上面的代码是将总binary长度,减为256

array_length=n/4% Create an array named input_data and fill it cyclically with numbers from 0 to 15
decimalArray = mod(0:array_length-1, 16);% Convert decimal array to binary array
binaryArray = dec2bin(decimalArray) - '0';
%swap columns
swappedBinaryArray = binaryArray(:, [4 3 2 1]);% Concatenate each line of binaryArray
%onerow_binaryArray = binaryArray_pose(:);
onerow_binaryArray = swappedBinaryArray(:);% Transpose the binary array to a column vector
%transposedBinaryArray = onerow_binaryArray.';dataIn = onerow_binaryArray;

这段花了不少时间,是因为这里面的矩阵的变换自己不是不熟,是完全不知道如何操作。。。
这一次是学明白了。

这段是为了得到可控的输出
在这里插入图片描述

在这里插入图片描述
然后我们直接到调制

Modulate Using 16-QAM
Use the qammod function to apply 16-QAM modulation to the dataSymbolsIn column vector for natural-encoded and Gray-encoded binary bit-to-symbol mappings.

dataMod = qammod(dataSymbolsIn,M,'bin'); % Binary coding with phase offset of zero
dataModG = qammod(dataSymbolsIn,M); % Gray coding with phase offset of zero

然后是开始Trace这个函数
在跟踪之前,不得不先学习格雷码。
关于格雷码(Gray Code),最好的文章是wikipedia的内容:https://en.wikipedia.org/wiki/Gray_code

还有一篇也不错:
QAM格雷码映射的规则(Gray Code Mapping in QAM)
自己biying

这句是得到自然码的调制后编码,
dataMod = qammod(dataSymbolsIn,M,‘bin’); % Binary coding with phase offset of zero

然后,下面这句是得到Gray的编码
dataModG = qammod(dataSymbolsIn,M); % Gray coding with phase offset of zero
汇总后见下图:
在这里插入图片描述
然后,进入matlab的qammod函数:
在这里插入图片描述从这里

    [y, const] = comm.internal.qam.modulate(x, M, symbolOrder, symbolOrderVector, ...bitInput, unitAveragePower, outputDataType);
function y = processIntInput(x, M, symbolOrder, symbolOrderVector, const)msg = processSymbols(x, M, symbolOrder, symbolOrderVector);y = lookupTable(const, msg);
end
function [y, const] = modulate(x, M, symbolOrderStr, ...symbolOrderVector, bitInput, unitAveragePower, outputDataType)y = processIntInput(x, Mnew, symbolOrderStr, symbolOrderVector, newConst);
end

重点是这句:
y = lookupTable(const, msg);


function y = lookupTable(table, x)y = coder.nullcopy(zeros(size(x),'like',table));y(:) = table(x + cast(1,'like',x));
end

重点是这句:

 y(:) = table(x + cast(1,'like',x));

  1. cast(1,'like',x): This part casts the value 1 to the same data type as the input variable x. This is necessary to ensure that the indexing operation doesn’t cause any type mismatches.

  2. x + cast(1,'like',x): This adds 1 to each element of the input vector x.

  3. table(x + cast(1,'like',x)): This indexes the table array using the modified values of x + cast(1,'like',x). It effectively looks up values in the table corresponding to the modified indices.

  4. y(:) = table(x + cast(1,'like',x));: This assigns the values obtained from the lookup to the entire vector y. The (:) syntax is used to linearize y into a column vector.

Let’s walk through an example:

  • Original x values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  • Modified indices: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
  • Values from the table corresponding to the modified indices: [-3 + 1i, -3 - 1i, -3 - 3i, -1 + 3i, -1 + 1i, -1 - 1i, -1 - 3i, 1 + 3i, 1 + 1i, 1 - 1i, 1 - 3i, 3 + 3i, 3 + 1i, 3 - 1i, 3 - 3i]

So, the resulting y would be the values obtained from the table using the modified indices. The purpose seems to be to perform a table lookup operation using the input vector x to generate the output vector y.


解调的部分

注意,条件检查的部分,我省略了,实际我也是详细看了的,写得很精妙!
Demodulate 16-QAM
Use the qamdemod function to demodulate the received data and output integer-valued data symbols.

dataSymbolsOut = qamdemod(receivedSignal,M,'bin');
dataSymbolsOutG = qamdemod(receivedSignalG,M);function x = qamdemod(y, M, varargin)   x = comm.internal.qam.demodulate(y, M, symbolOrderStr, symbolOrderVector, unitAveragePower, ...outputType, noiseVar);
end
function x = demodulate(y, M, symbolOrderStr, symbolOrderVector, ...unitAveragePower, outputType, noiseVar)intX = computeHardInt(y, Mnew);        

这里是关键函数


function z = computeHardInt(y, M)if isa(y,'single')z = coder.nullcopy(zeros(size(y), 'single'));elsez = coder.nullcopy(zeros(size(y), 'double'));endif mod(log2(M), 2) % Cross constellation, including M=2const = comm.internal.qam.getSquareConstellation(M);z(:) = genqamdemod(y,const);else % Square constellation, starting with M=4% Precompute for later usesqrtM = sqrt(M);% Inphase/real rail% Move the real part of input signal; scale appropriately and round the% values to get index ideal constellation pointsrIdx = round( ((real(y) + (sqrtM-1)) ./ 2) );% clip values that are outside the valid rangerIdx(rIdx < 0) = 0;rIdx(rIdx > (sqrtM-1)) = sqrtM-1;% Quadrature/imaginary rail% Move the imaginary part of input signal; scale appropriately and round% the values to get index of ideal constellation pointsiIdx = round(((imag(y) + (sqrtM-1)) ./ 2));% clip values that are outside the valid rangeiIdx(iIdx < 0) = 0;iIdx(iIdx > (sqrtM-1)) = sqrtM-1;% compute output from indices of ideal constellation pointsz(:) = sqrtM-iIdx-1 +  sqrtM*rIdx;end
end

computeHardInt中,这两句是重点

        % Inphase/real rail% Move the real part of input signal; scale appropriately and round the% values to get index ideal constellation pointsrIdx = round( ((real(y) + (sqrtM-1)) ./ 2) );% Quadrature/imaginary rail% Move the imaginary part of input signal; scale appropriately and round% the values to get index of ideal constellation pointsiIdx = round(((imag(y) + (sqrtM-1)) ./ 2));

格雷码,并没有多大不同,调制是后处理,解调是前处理,将数据重新映射。
以上是所有的内容。
可惜这个例子只有基带的处理,没有信号的调制与解调。
是为遗憾。
希望再找个更全面的例子。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/221986.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C语言数据结构-二叉树的入门

文章目录 0 碎碎念1 二叉树的概念和结构1.1 概念和特点1.2 结构1.3 特殊的二叉树1.4 二叉树的存储与性质1.5 前序、中序和后序 2 简单二叉树的实现2.1 定义数据结构类型2.2 前序、中序和后序接口的实现2.3 二叉树中节点的个数2.4 叶子节点的个数 3 完整代码块3.1 BinaryTree.h3…

「神印王座」皓晨带伙伴参与伊老试炼,12魔神攻打震南关,高能

Hello,小伙伴们&#xff0c;我是拾荒君。 时光匆匆&#xff0c;国漫《神印王座》的第85集已经与大家如约而至。想必各位观众都已经迫不及待地观看了这一集&#xff0c;其中&#xff0c;龙皓晨向光之晨曦团的成员们揭示了永恒之塔的秘密&#xff0c;并带领他们深入其中。 永恒之…

nginx服务前端访问查看无响应的问题

问题 nginx 启动之后&#xff0c;前端访问无数据&#xff0c;F12 查看&#xff0c;提示挂起。 以为是配置问题&#xff0c;查看配置文件&#xff0c;未发现配置的有问题。 原因 通过查看配置文件&#xff0c;发现转发的服务地址为127.0.0.1&#xff0c;手动ping 127.0.0.1&a…

如何部署Portainer容器管理工具+cpolar内网穿透实现公网访问管理界面

文章目录 前言1. 部署Portainer2. 本地访问Portainer3. Linux 安装cpolar4. 配置Portainer 公网访问地址5. 公网远程访问Portainer6. 固定Portainer公网地址 前言 本文主要介绍如何本地安装Portainer并结合内网穿透工具实现任意浏览器远程访问管理界面。Portainer 是一个轻量级…

Unity 关于Rigidbody刚体组件的理解

一、基本了解 刚体Rigidbody因具体物理相关的属性&#xff0c;使得实际应用中更有真实感。应用也多&#xff1a; Rigidbody它可以受到重力、碰撞或者力的作用&#xff0c;所以我们可以用它模拟物体的真实物理行为&#xff0c;如受到重力的作用、与其他刚体对象进行碰撞&#…

ChatGPT Plus重新开启订阅

12月14日凌晨&#xff0c;OpenAI首席执行官Sam Altman在社交平台宣布&#xff0c;终于找到了更多的GPU算力&#xff0c;重新开启订阅ChatGPT Plus。 上个月15日&#xff0c;OpenAI就因为算力不足&#xff0c;以及用户激增等原因暂停了ChatGPT Plus订阅。 Sam表示&#xff0c;在…

【九】python模板方法模式

9.1 模板方法模式概述 模板方法模式是一种行为设计模式&#xff0c;它使用一个抽象的基类定义了一个操作中的算法的骨架&#xff0c;而将一些步骤的实现延迟到子类中。模板方法模式允许子类在不改变算法结构的情况下重新定义算法中的某些步骤。 9.2 代码示例 在Python中使用…

【亚马逊云科技】通过高性能低延迟对象存储 S3实现网站资源托管

本篇文章授权活动官方亚马逊云科技文章转发、改写权&#xff0c;包括不限于在 亚马逊云科技开发者社区, 知乎&#xff0c;自媒体平台&#xff0c;第三方开发者媒体等亚马逊云科技官方渠道 文章目录 前言1 S3 介绍1.1 优点 2 使用步骤2.1 注册账户2.2 创建存储桶2.2.1 打开控制…

智能指针管理“newed对象”

为什么要有智能指针&#xff1f; 指针智能是管理管理动态内存分配对象的一种机制。它提供了自动管理内存&#xff0c;避免常见内存泄漏和悬空指针。 对于上述Func函数的操作&#xff0c;一不小心就会产生很多问题。 p1 new时候抛异常 什么都不做p2 new时候抛异常 p1需要被清理…

深入理解JVM虚拟机第三十篇:详解JVM当中栈帧的一些附加信息以及虚拟机栈的5个面试题

😉😉 欢迎加入我们的学习交流群呀: ✅✅1:这是孙哥suns给大家的福利! ✨✨2:我们免费分享Netty、Dubbo、k8s、Mybatis、Spring...应用和源码级别的视频资料 🥭🥭3:QQ群:583783824 📚📚 工作微信:BigTreeJava 拉你进微信群,免费领取! 🍎🍎4:本文章…

如何在Ubuntu的Linux系统上搭建nacos集群

官方给出的集群部署架构图 集群部署说明 (nacos.io)3个或3个以上nacos节点才能构成集群当前示例中包含3个nacos节点&#xff0c;同时一个负载均衡器代理3个nacos&#xff0c;本示例中负载均衡器可使用的是nginx 准备并安装好正常运行的nginx&#xff0c;本示例略准备并安装好正…

Redis权限管理体系(一):客户端名及用户名

在Redis6之前的版本中&#xff0c;因安全认证的主要方式是使用Redis实例的密码进行基础控制&#xff0c;而无法按照不同的应用来源配置不同账号以及更细粒度的操作权限控制来管理。本文先从client list中的信息入手&#xff0c;逐步了解Redis的客户端名设置、用户设置及权限控制…

【Monitor, Maintenance Operation, Script code/prgramme】

Summary of M,M&O,Program JD) Monitor & M&O Symbio信必优) Job chance/opportunities on Dec 12th, 20231.1) Content 招聘JD job description:1.2) suggestions from Ms Liang/Winnie on Wechat app1.3) Java微服务是什么&#xff1f;1.3.1) [URL Java 微服务](…

京微齐力:基于H7的平衡控制系统(一、姿态解析)

目录 前言一、关于平衡控制系统二、实验效果三、硬件选择1、H7P20N0L176-M2H12、MPU6050 四、理论简述五、程序设计1、Cordic算法2、MPU6050采集数据3、fir&iir滤波4、姿态解算 六、资源消耗&工程获取七、总结 前言 很久之前&#xff0c;就想用纯FPGA做一套控制系统。可…

C++二维数组(2)

图形相似度 题目描述&#xff1a; 给出两幅相同大小的黑白图像&#xff08;用0-1矩阵&#xff09;表示&#xff0c;求它们的相似度。 说明&#xff1a;若两幅图像在相同位置上的像素点颜色相同&#xff0c;则称它们在该位置具有相同的像素点。 两幅图像的相似度定义为相同像素…

橘子学K8S01之容器中所谓的隔离

我们一直都在说容器就是一个沙盒&#xff0c;沙盒技术顾名思义就是像一个集装箱一样&#xff0c;把应用(服务&#xff0c;进程之类的)装起来的技术&#xff0c;这样每个进程在自己的沙盒中和其他的沙盒隔离开来&#xff0c;每个沙盒之间存在一个边界使得他们互不干扰&#xff0…

鸿鹄云商:Java商城引领商业模式的潮流,免费搭建多种商城模式

java SpringCloud版本b2b2c鸿鹄云商平台全套解决方案 使用技术&#xff1a; Spring CloudSpring BootMybatis微服务服务监控可视化运营 B2B2C平台&#xff1a; 平台管理端(包含自营) 商家平台端(多商户入驻) PC买家端、手机wap/公众号买家端 微服务&#xff08;30个通用…

用23种设计模式打造一个cocos creator的游戏框架----(十六)亨元模式

1、模式标准 模式名称&#xff1a;亨元模式 模式分类&#xff1a;结构型 模式意图&#xff1a;运用共享技术有效地支持大量细粒度的对象 结构图&#xff1a; 适用于&#xff1a; 1、一个应用程序使用了大量的对象. 2、完全由于使用大量的对象&#xff0c;造成很大的存储开…

铭飞CMS list 接口 SQL注入漏洞复现

0x01 产品简介 铭飞CMS是一款基于java开发的一套轻量级开源内容管理系统,铭飞CMS简洁、安全、开源、免费,可运行在Linux、Windows、MacOSX、Solaris等各种平台上,专注为公司企业、个人站长快速建站提供解决方案 0x02 漏洞概述 铭飞CMS在5.2.10版本以前list 接口处存在sql注入…

什么是CAS(比较并交换-乐观锁机制-锁自旋)

什么是 CAS&#xff08;比较并交换-乐观锁机制-锁自旋&#xff09; 概念及特性 CAS&#xff08;Compare And Swap/Set&#xff09;比较并交换&#xff0c;CAS 算法的过程是这样&#xff1a;它包含 3 个参数CAS(V,E,N)。V 表示要更新的变量(内存值)&#xff0c;E 表示预期值(旧…