概述
目录
MATLAB setup
matlab安装
matlab关联m文件代码
星座图的matlab仿真
MATLAB setup
matlab安装
很久没有用过matlab了~首先给出matlab2019的安装资料(matlab2019a安装)参考这个资料,应该比较轻松的就可以安装并破解matlab19了哈~
matlab关联m文件代码
(参考资料https://blog.csdn.net/myathappy/article/details/90404890)
function associateFiles(action, userExtList, fileStr)
% associateFiles(action, extList, fileStr)
%
% Makes a registry files that can be used to set correct file associantions on
% a windows platform. The following MATLAB file extensions are supported:
% .m, .mat, .fig, .mexw32, .mexw64, .p, .mdl, .mdlp, .slx, .mldatx, .req,
% .sldd, .slddc, .slxp, .sltx, .mn, .mu, .muphlp, .xvc, .xvz, .ssc, .mlapp,
% .mlappinstall, .mltbx, .mlpkginstall, .mlprj
%
% INPUT:
% action - optional string.
% * 'add' (default) adds/rewrites the MATLAB file association registry
% keys for this version.
% * 'delete' deletes the MATLAB file association registry entries for
% ALL versions of MATLAB (including "old style" ones)
% * 'deleteadd' is the same as 'delete' followed by 'add'
% extList - optional string or cell array of strings containing the file
% extensions that should be associated with this version. Default is
% all MATLAB file extension (see above).
% fileStr - optional string with the name of the registry file to be written
% (possibly including path). Default is the file
% 'MatlabFileAssocFix.reg' in the current directory.
%
% USAGE:
% 1) Run with desired options (see above). A registry file should have been
% created.
% 2) Exit all running instances of MATLAB.
% 3) Make a backup copy of the windows registry if you need to restore the
% changes, see https://support.microsoft.com/en-us/kb/322756
% 4) Double click on the created file (possibly need to enter a password) and
% confirm.
% 5) Restart Windows (or explorer.exe).
% 6) The MATLAB files should now be associated with the MATLAB version that the
% registry file was created in and e.g. m-files should be opened in an
% already running instance of MATLAB.
%
% EXAMPLES:
% * associateFiles('deleteadd') - Makes a registry files that deletes all
% previous MATLAB file association registry keys and write new ones that
% associates all MATLAB files with the MATLAB version that the registry file
% was created in.
% * associateFiles('', {'.m', '.mat', '.fig'}, 'myFile') - Makes a registry file
% "myFile.reg" that associates m-, mat- and fig-files with the MATLAB version
% that the registry file was created in.
%
% VERSION 1.0
% Defualt input
if (nargin < 1 || isempty(action))
action = 'add';
end
if (nargin < 2)
userExtList = {};
end
if (nargin < 3)
fileStr = '';
end
if (~iscell(userExtList))
if (isempty(userExtList))
userExtList = {};
else
userExtList = {userExtList};
end
end
% Sanity check
if (~ischar(action) || (~strcmpi(action, 'add') && ...
~strcmpi(action, 'delete') && ~strcmpi(action, 'deleteadd')))
error('The action to perform must be ''add'', ''delete'' or ''deleteadd''!')
end
if (~isempty(userExtList) && ~min(cellfun(@ischar, userExtList)))
error('The file extension list must be a string or a cell array of strings!')
end
if (~ischar(fileStr))
error('The file to write to must be a string!')
end
% Get the currently running MATLAB version
verStr = regexp(version, '(d*?.d*?.d*?).', 'tokens');
verStr = verStr{1}{1};
verNum = str2double(regexprep(verStr, '(d*?.d*)[x0000-xffff]*', '$1'));
verHex = sprintf('x', str2double(regexprep(verStr, ...
'(d*?).[x0000-xffff]*', '$1')), str2double(regexprep(verStr, ...
'd*?.(d*?).[x0000-xffff]*', '$1')));
% Get 32/64-bit
arch = computer;
switch arch
case 'PCWIN'
binFolder = 'win32';
case 'PCWIN64'
binFolder = 'win64';
end
binPath = fullfile(matlabroot, 'bin', binFolder);
% Known MATLAB files with possible DDE actions
fileExtCell = {...
'fig' , 'MATLAB Figure' , '-62' , ...
{'Open', 'uiopen(''%1'',1)'} , [] ; ...
'm' , 'MATLAB Code' , '-58' , ...
{'Open', 'uiopen(''%1'',1)'} , {'Run', 'run(''%1'')'} ; ...
'mat' , 'MATLAB Data' , '-59' , ...
{'Load', 'load(''%1'')' } , {'Open', 'uiimport(''%1'')'}; ...
'mdl' , 'Simulink Model' , '-61' , ...
{'Load', 'uiopen(''%1'',1)'} , [] ; ...
'mdlp' , 'Simulink Protected Model' , '-72' , ...
[] , [] ; ...
'mexw32', 'MATLAB MEX' , '-63' , ...
[] , [] ; ...
'mexw64', 'MATLAB MEX' , '-63' , ...
[] , [] ; ...
'mn' , 'MuPAD Notebook' , '-66' , ...
{'Open', 'mupad(''%1'')'} , [] ; ...
'mu' , 'MuPAD Code' , '-67' , ...
{'Open', 'uiopen(''%1'',1)'} , [] ; ...
'muphlp', 'MuPAD Help' , '-68' , ...
{'Open', 'doc(symengine, ''%1'')'} , [] ; ...
'p' , 'MATLAB P-code' , '-60' , ...
[] , [] ; ...
'slx' , 'Simulink Model (SLX format)', '-73' , ...
{'Open', 'uiopen(''%1'',1)'} , [] ; ...
'ssc' , 'Simscape Model' , '-65' , ...
{'Open', 'uiopen(''%1'',1)'} , [] ; ...
'xvc' , 'MuPAD Graphics' , '-69' , ...
{'Open', 'mupad(''%1'')'} , [] ; ...
'xvz' , 'MuPAD Graphics' , '-70' , ...
{'Open', 'mupad(''%1'')'} , [] ; ...
'mlapp' , 'MATLAB Application' , [] , [], [] ; ...
'mltbx' , 'MATLAB Toolbox' , [] , [], [] ; ...
'mldatx' , 'Simulink Scenario' , [] , [], [] ; ...
'req' , 'Simulink Requirements Link' , [] , [], [] ; ...
'sldd' , 'Simulink Dictionary' , [] , [], [] ; ...
'slddc' , 'Simulink Dictionary' , [] , [], [] ; ...
'mlappinstall', 'MATLAB Application' , [] , [], [] ; ...
'mlpkginstall', 'MATLAB Support Package' , [] , [], [] ; ...
'slxp' , 'Simulink Protected Model Package', [] , [], [] ; ...
'sltx' , 'Simulink Template' , [] , [], [] ; ...
'mlprj' , 'MATLAB Project' , [] , [], []};
% Possibly trim list
if (~isempty(userExtList))
fileExtCell = fileExtCell(ismember(fileExtCell(:, 1), ...
regexprep(userExtList, '.', '')), :);
end
% Make registry file
if (~isempty(fileStr))
% Possibly add file extension
[~, ~, tmp] = fileparts(fileStr);
if (isempty(tmp))
fileStr = [fileStr, '.reg'];
end
fid = fopen(fileStr, 'w');
else
fid = fopen('MatlabFileAssocFix.reg', 'w');
end
if (fid == -1)
error('Failed to create registry file')
end
% Write intial lines
fprintf(fid, '%srnrn', 'Windows Registry Editor Version 5.00');
fprintf(fid, '%srnrn', ';FIXES MATLAB FILE ASSOCIATIONS');
% REMOVE OLD KEYS
explorerKey = ['HKEY_CURRENT_USERSoftwareMicrosoftWindows', ...
'CurrentVersionExplorerFileExts'];
% Iterate over file extensions
for fileExtNo = 1 : size(fileExtCell, 1)
rmKeys = {};
fileExt = fileExtCell{fileExtNo, 1};
% File extension keys
[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f .', fileExt, ...
' /k /e']);
if (~status)
keys = regexp(result, '(HKEY_CLASSES_ROOT[x0000-xffff]*?)n', 'tokens');
rmKeys = [rmKeys, keys{:}];
end
% Old style keys without version numbers
if (~strcmpi(fileExt, 'mexw64'))
% Uses single DDE key for mex files
if (strcmpi(fileExt, 'mexw32'))
fileExtTmp = 'mex';
else
fileExtTmp = fileExt;
end
[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f ', ...
fileExtTmp, 'file /k /e']);
if (~status)
keys = regexp(result, '(HKEY_CLASSES_ROOT[x0000-xffff]*?)n', ...
'tokens');
rmKeys = [rmKeys, keys{:}];
end
end
% New style keys with version number
if (strcmpi(action, 'add'))
% Only remove keys related to this version
[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f MATLAB.', ...
fileExt, '.', verStr ' /k']);
else
% Remove keys related to ALL version
[status, result] = dos(['reg query HKEY_CLASSES_ROOT /f MATLAB.', ...
fileExt, '. /k']);
end
if (~status)
keys = regexp(result, '(HKEY_CLASSES_ROOT[x0000-xffff]*?)n', 'tokens');
rmKeys = [rmKeys, keys{:}];
end
% Explorer keys
[status, result] = dos(['reg query ', explorerKey, ' /f .', fileExt, ...
' /k /e']);
if (~status)
keys = regexp(result, '(HKEY_CURRENT_USER[x0000-xffff]*?)n', 'tokens');
rmKeys = [rmKeys, keys{:}];
end
% Write to file
if (~isempty(rmKeys))
fprintf(fid, '%srnrn', [';REMOVES ', upper(fileExt), ...
' FILE ASSOCIATIONS']);
for keyNo = 1 : length(rmKeys)
key = rmKeys{keyNo};
fprintf(fid, '%srnrn', ['[-', key, ']']);
end
end
end
% ADD KEYS
if (~strcmpi(action, 'delete'))
% Get text Persistent Handler
[status, result] = dos(...
'reg query HKEY_CLASSES_ROOT.txtPersistentHandler /ve');
if (~status)
PersistentHandler = regexp(result, '{[x0000-xffff]*?}', 'match');
PersistentHandler = PersistentHandler{1};
else
PersistentHandler = '';
end
% DDE call
ddeCall = 'ShellVerbs.Matlab';
if (verNum > 8)
% Changed from R2013a
ddeCall = [ddeCall, '.', verStr];
end
% Default icon
defIcon = 'm';
if (~exist(fullfile(binPath, 'm.ico'), 'file'))
defIcon = '';
end
% Path to MATLAB binary directory with \
binPathStr = regexprep(binPath, '\', '\\');
% Write Shell Open key
key = ['[HKEY_CLASSES_ROOTApplicationsMATLAB.exeshellopen', ...
'command]%r', '@=""', binPathStr, '\MATLAB.exe" "%1""%r%r'];
fprintf(fid, '%srnrn', ';ADD SHELL OPEN');
lines = regexp(key, '([x0000-xffff]*?)%r', 'tokens');
for lineNo = 1 : length(lines)
fprintf(fid, '%srn', lines{lineNo}{1});
end
% Iterate over file types
for fileExtNo = 1 : size(fileExtCell, 1)
fileExt = fileExtCell{fileExtNo, 1};
% File extension keys
key = ['[HKEY_CLASSES_ROOT.', fileExt, ']%r@="MATLAB.', fileExt, '.', ...
verStr, '"%r'];
if (strcmpi(fileExt, 'm') && ~isempty(PersistentHandler))
% Add some values
key = [key, '"Content Type"="text/plain"%r', ...
'"PerceivedType"="Text"%r'];
end
key = [key, '%r'];
key = [key, '[HKEY_CLASSES_ROOT.', fileExt, ...
'OpenWithProgids]%r"MATLAB.', fileExt, '.', verStr, '"=""%r%r'];
if (strcmpi(fileExt, 'm') && ~isempty(PersistentHandler))
key = [key, '[HKEY_CLASSES_ROOT.', fileExt, ...
'PersistentHandler]%r@="', PersistentHandler, '"%r%r'];
end
key = [key, '[HKEY_CLASSES_ROOT.', fileExt, ...
'VersionsMATLAB.', fileExt, '.' verStr, ']%r"FileVersionMS"=dword:', ...
verHex, '%r"FileVersionLS"=dword:00000000%r%r'];
% DDE keys
ddeData = fileExtCell(ismember(fileExtCell(:, 1), fileExt), :);
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
']%r@="', ddeData{2}, '"%r'];
if (~isempty(ddeData{3}))
key = [key, '"FriendlyTypeName"="@', binPathStr, '\matlab.exe', ...
',', ddeData{3}, '"%r'];
end
key = [key, '%r'];
% Icon
icon = fileExt;
if (~exist(fullfile(binPath, [icon, '.ico']), 'file'))
icon = defIcon;
end
if (~isempty(icon))
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
'DefaultIcon]%r@="', binPathStr, '\', icon, '.ico,0"%r%r'];
end
% Shell actions
for shellActionNo = 4:5
ddePar = ddeData{shellActionNo};
if (~isempty(ddePar))
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
'Shell', ddePar{1}, ']%r@="', ddePar{1}, '"%r%r'];
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
'Shell', ddePar{1}, 'command]%r@=""', binPathStr, ...
'\matlab.exe""%r%r'];
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
'Shell', ddePar{1}, 'ddeexec]%r@="', ddePar{2}, '"%r%r'];
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
'Shell', ddePar{1},'ddeexecapplication]%r@="', ...
ddeCall, '"%r%r'];
key = [key, '[HKEY_CLASSES_ROOTMATLAB.', fileExt, '.' verStr, ...
'Shell', ddePar{1},'ddeexectopic]%r@="system"%r%r'];
end
end
% Explorer keys
key = [key, '[', explorerKey, '.', fileExt, 'OpenWithProgids]%r'];
if (strcmpi(fileExt, 'm'))
key = [key, '"m_auto_file"=hex(0):%r'];
end
key = [key, '"MATLAB.', fileExt, '.', verStr, '"=hex(0):%r%r'];
if (~isempty(ddeData{4}))
% Add key
key = [key, '[', explorerKey, '.', fileExt, ...
'OpenWithList]%r"a"="MATLAB.exe"%r"MRUList"="a"%r%r'];
else
key = [key, '[', explorerKey, '.', fileExt, 'OpenWithList]%r%r'];
end
% Write to file
fprintf(fid, '%srnrn', [';ADD ', upper(fileExt), ...
' FILE ASSOCIATIONS']);
lines = regexp(key, '([x0000-xffff]*?)%r', 'tokens');
for lineNo = 1 : length(lines)
fprintf(fid, '%srn', lines{lineNo}{1});
end
end
end
% Cloese file
fclose(fid);
正常情况下,.m文件的图标应该是这样的:
好,配置完matlab文件,下面进入正文
星座图的matlab仿真
星座图仿真代码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%下面的部分是计算传输信道的脉冲响应h(t)%%%%%%
theta = 70; %半功率点半角
c = 3e8; %光速
m = -log10(2)/log10(cosd(theta)); %朗伯发射级数
P_total = 20; %单个LED的功率(单位为W)
Adet = 1e-4; %PD的接受面面积
index = 1.5;
FOV = 60*pi/180; %接受场视角
G_Gon = (index^2)/sin(FOV); %集光器增益
lx = 5;ly = 5;lz = 3; %房屋尺寸
h = 2.15; %源与接受平面之间的距离
XT = 0; YT = 0; %LED位置
XR = 1.25; YR = 1.25; %我们先假设只有一个接收器
D1 = sqrt((XR - XT(1,1)).^2 + (YR - YT(1,1)).^2+h.^2); %就是接收器到源的距离矢量
cosphi_Al = h./D1; %角度矢量
H_Al = (m + 1)*Adet.*cosphi_Al.^(m+1)./(2*pi.*D1.^2); %计算直流增益/信道的衰减因子
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rb = 1; %%%%%%%%%%归一化比特速率,
fc = Rb*5; %载波频率(更高的频率)
Tb = 1/Rb; %比特宽度,每个bit持续的时间长度
fsamp = fc * 10; %采样速率,以10倍载波频率来采样
nsamp = fsamp/Rb; %每个bit的采样数
Tsamp = Tb/nsamp; %采样时刻
N_data_symbol = 10000; %符号数(比特数),一共传输了10000个bits
t = Tsamp:Tsamp:Tb*N_data_symbol;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16QAM调制
M = 16; %可选调制方式M=4表示QPSK,M=8,16,32,64表示mQAM
tx_bits = randi([0,M-1],1,N_data_symbol); %生成随机信号.[0,1]分布的随机变量,10000个bits
tx_bits_mod = qammod(tx_bits, M); %产生QAM调制信号
scatterplot(tx_bits_mod);%绘制散点图
title('原始信号星座')
%************LED响应******************
wc=6e6; %led截止频率(3M,算上采样率就是6M)
b=1;a=[1,wc]; %模拟滤波器系数
[bd,ad]=bilinear(b,a,fsamp); %模拟滤波器双线性变换为数字滤波器
[Hd,wd]=freqz(bd,ad);%%%%%%%%滤波器频率响应函数
bd1=bd/(max(abs(Hd))); %数字滤波器幅度归一化
SNR = 30;%%%30 dB
tx_signal = rectpulse(tx_bits_mod,nsamp); %矩形脉冲成形
rr = filter(bd1,ad,tx_signal); %通过滤波器(模拟LED)
rr1=awgn(rr,SNR,'measured');
y1=downsample(rr1,nsamp,nsamp-1); %降采样
scatterplot(y1);
title('接受信号的星座图');
改进后代码如下
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%下面的部分是计算传输信道的脉冲响应h(t)以及信噪比SNR%%%%%%
Incidence = 60*pi/180; %入射范围
theta = 70; %半功率点半角
RX_FOV = 90; %接受场视角
R = 1;
Adet = 1e-4; %PD的接受面面积
Rb = 1; %%%%%%%%%%归一化比特速率,
lamp = 5e-12; %放大器电流
q = 1.6e-19; %电子数
Bn = 50e6; %噪声带宽
l2 = 0.562; %噪声带宽因子
PLED = 0.5; %LED的功率,单位:W(一般的单个LED功率都是0.几W)
index = 1.5; %PD用透镜的折射率
HLED = 1;
D = 3; %点对点传输,LED与接收器的距离
cosphi_AL = 1; %由于LED与接收器在同一直线上,所以角度矢量为1
m = -log10(2)/log10(cosd(theta)); %朗伯发射级数
H_Al = (m+1) * Adet.* cosphi_AL.^(m+1)./(2*pi*D.^2); %直流增益
R0 = ((m+1)/(2*pi)).*cosphi_AL^m; %朗伯辐射强度
Ptx = PLED.*R0; %LED发射功率
Prx = H_Al.*Ptx; %接受功率;
%下面计算系统中的噪声:
Bs = Rb * l2;
Pn = lamp/Rb;
Ptotal = Prx + Pn; %总功率
new_shot = 2*q*Ptotal*Bs;
new_amp = lamp^2*Bn;
new_total = new_shot + new_amp;
SNRl = (R.*Prx).^2/ new_total;
SNRdb = 10*log10(SNRl);
SNRdb
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fc = Rb * 5; %载波频率
Tb = 1/Rb; %比特宽度,每个bit持续的时间长度
fsamp = fc * 10; %采样速率,以10倍载波频率来采样
nsamp = fsamp/Rb; %每个bit的采样数
Tsamp = Tb/nsamp; %采样时刻
N_data_symbol = 10000; %符号数(比特数),一共传输了10000个bits
t = Tsamp:Tsamp:Tb*N_data_symbol;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16QAM调制
M = 16; %可选调制方式M=4表示QPSK,M=8,16,32,64表示mQAM
tx_bits = randi([0,M-1],1,N_data_symbol); %生成随机信号,10000个bits
tx_bits_mod = qammod(tx_bits, M); %产生QAM调制信号
scatterplot(tx_bits_mod); %绘制散点图
title('原始信号星座')
%************LED响应******************
wc=6e6; %led截止频率(3M,算上采样率就是6M)
b=1;a=[1,wc]; %模拟滤波器系数
[bd,ad]=bilinear(b,a,fsamp); %模拟滤波器双线性变换为数字滤波器
[Hd,wd]=freqz(bd,ad);
bd1=bd/(max(abs(Hd))); %数字滤波器幅度归一化
tx_signal = rectpulse(tx_bits_mod,nsamp); %矩形脉冲成形
rr = filter(bd1,ad,tx_signal); %通过滤波器(模拟LED)
rr1=awgn(rr,SNRdb,'measured');
scatterplot(rr1);
title('解调之前,经过信道传输接收到的星座图');
demod_rr1 = qamdemod(rr1, M);
scatterplot(demod_rr1);
title('解调之后的星座图');
y1=downsample(demod_rr1,nsamp,nsamp-1); %降采样
scatterplot(y1);
title('接受信号的星座图');
结果图
最后
以上就是激情飞鸟为你收集整理的学习笔记之——基于matlab的星座图MATLAB setup星座图的matlab仿真的全部内容,希望文章能够帮你解决学习笔记之——基于matlab的星座图MATLAB setup星座图的matlab仿真所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复