在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 4293|回复: 4

[求助] matlab simulink scaleABCD函数问题

[复制链接]
发表于 2016-12-27 16:29:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
如图所示,从matlab 网站上下载的函数库

蓝色部分是老的函数

红色部分是新的函数,运行的时候出现了如下问题

===========
??? Undefined function or variable 'rng'.
Error in ==> scaleABCD at 46
rng_state = rng;

===========
我的问题是: 新的函数如何运行才能通过,蓝色字体改为红色字体之后(不是我改的!!),对于scale有什么改善
谢谢

function [ABCDs,umax,S]=scaleABCD(ABCD,nlev,f,xlim,ymax,umax,N_sim,N0)
%[ABCDs,umax,S]=scaleABCD(ABCD,nlev=2,f=0,xlim=1,ymax=nlev+5,umax,N=1e5,N0=10)
%Scale the loop filter of a general delta-sigma modulator for dynamic range.
%
%ABCD The state-space description of the loop filter.
%nlev The number of levels in the quantizer.
%xlim A vector or scalar specifying the limit for each state variable.
%ymax The stability threshold. Inputs that yield quantizer inputs above ymax
%       are considered to be beyond the stable range of the modulator.
%umax The maximum allowable input amplitude. umax is calculated if it
% is not supplied.
%
%ABCDs The state-space description of the scaled loop filter.
%S The diagonal scaling matrix, ABCDs = [S*A*Sinv S*B; C*Sinv D];
% xs = S*x;
if nargin<1
    fprintf(1,'Error. scaleABCD needs at least one arguments.\n');
    return
end
% Handle the input arguments
parameters = {'ABCD' 'nlev' 'f' 'xlim' 'ymax' 'umax' 'N_sim' 'N0'};
defaults = { NaN 2 0 1 NaN NaN 1e5 10};
for i=1:length(defaults)
    parameter = char(parameters(i));
    if i>nargin | ( eval(['isnumeric(' parameter ') '])  &  ...
     eval(['any(isnan(' parameter ')) | isempty(' parameter ') ']) )
        eval([parameter '=defaults{i};'])
    end
end
if isnan(ymax)
   ymax=nlev+5;
end
order = size(ABCD,1)-1;
if length(xlim)==1
    xlim = xlim(ones(1,order)); % Convert scalar xlim to a vector
end
if isreal(ABCD)
    quadrature = 0;
else
    quadrature = 1;
end
% Make this function repeatable
%rng_state = rng;
%rng('default');

randn('seed',0);
% Envelope for smooth start-up
raised_cosine = 0.5*(1-cos(pi/N0*[0:N0-1]));
if isnan(umax)
    %Simulate the modulator with DC or sine wave inputs to detect its stable
    %input range.
    %First get a rough estimate of umax.
    ulist =(0.1:0.1:1.0) * (nlev-1);
    umax = nlev-1;
    N = 1e3;
    u0 = [ exp(2i*pi*f*[-N0:-1]) .* raised_cosine ...
           exp(2i*pi*f*[0:N-1]) ] + 0.01*[1 1i]*randn(2,N+N0);
    if ~quadrature
     u0 = real(u0);
    end
    for u = ulist
if ~quadrature
     [v x xmax y] = simulateDSM(u*u0,ABCD,nlev);
else
     [v x xmax y] = simulateQDSM(u*u0,ABCD,nlev);
end
if max(abs(y))>ymax
     umax = u; %umax is the smallest input found which causes 'instability'
     break
end
    end
    if umax == ulist(1)
msg = sprintf('Modulator is unstable even with an input amplitude of %.1f.',umax);
error(msg);
    end
end
   
%More detailed simulation
N = N_sim;
u0 = [ exp(2i*pi*f*[-N0:-1]) .* raised_cosine ...
       exp(2i*pi*f*[0:N-1]) ] + 0.01*[1 1i]*randn(2,N+N0);
if ~quadrature
u0 = real(u0);
end
maxima = zeros(1,order)-1;
ulist = linspace(0.7*umax,umax,10);
for u = ulist
if ~quadrature
  [v x xmax y] = simulateDSM(u*u0,ABCD,nlev);
else
  [v x xmax y] = simulateQDSM(u*u0,ABCD,nlev);
end
    if max(abs(y))>ymax
       break
    end
    % We need to do this at least once.
    umax = u; % umax is the largest input which keeps |y| < ymax
    maxima = max([maxima; xmax']);
end
%Scale the modulator so that all states are at most xlim.
scale = maxima ./ xlim;
S = diag(1./scale); Sinv = diag(scale); % xs = S * x;
[A B C D]= partitionABCD(ABCD);
ABCDs = [S*A*Sinv S*B; C*Sinv D];
%rng(rng_state);
发表于 2017-1-7 15:10:47 | 显示全部楼层
你matlab太老了吧 rng是新版本的随机数发生器
 楼主| 发表于 2017-1-25 11:04:41 | 显示全部楼层
回复 2# quantus


    谢谢。问题已经解决

   matlab版本问题

   解决方式:2010b更新2016a

   多谢
发表于 2020-6-15 15:00:37 | 显示全部楼层
求问贴主,这个问题有遇到过吗?怎么解决?他总提示我scaleABCD使用错误。
错误使用 scaleABCD (line 74)
Modulator is unstable even with an input amplitude of 0.1.

出错 ic_dsmod_coefficient (line 23)
[ABCDs,umax] = scaleABCD(ABCD,nlevel,f0,xlim);         %Scale the ABCD matrix so that the state maxima are less than a specified limit.

提示报错的代码对应为:
    if umax == ulist(1)
        msg = sprintf('Modulator is unstable even with an input amplitude of %.1f.',umax);
        error(msg);  %line 74
    end
end
   
发表于 2021-7-3 14:33:39 | 显示全部楼层


levintt 发表于 2020-6-15 15:00
求问贴主,这个问题有遇到过吗?怎么解决?他总提示我scaleABCD使用错误。
错误使用 scaleABCD (line 74)
M ...


请问最后你找到解决办法了吗


您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-7 07:45 , Processed in 0.025677 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表