matlab锁相放大器源码_matlab仿真放大电路

hacker|
97

文章目录:

在Matlab中怎么实现一个锁相放大器的仿真模型

用与待测信号同频率的参考信号 与 待测信号相乘, 将得到一个直流成分,低通滤波或积分,即得到直流输出,检测出待测信号幅度。

具体数学方法以及数量关系根据仿真结果 做归一化处理吧。

matlab源代码

hrollfcoef这个函数不是matlab自带的

function [xh] = hrollfcoef(irfn,ipoint,sr,alfs,ncc)

%****************** variables *************************

% irfn : Number of symbols to use filtering

% ipoint : Number of samples in one symbol

% sr : symbol rate

% alfs : rolloff coeficiense

% ncc : 1 -- transmitting filter 0 -- receiving filter

% *****************************************************

xi=zeros(1,irfn*ipoint+1);

xq=zeros(1,irfn*ipoint+1);

point = ipoint;

tr = sr ;

tstp = 1.0 ./ tr ./ ipoint;

n = ipoint .* irfn;

mid = ( n ./ 2 ) + 1;

sub1 = 4.0 .* alfs .* tr; % 4*alpha*R_s

for i = 1 : n

icon = i - mid;

ym = icon;

if icon == 0.0

xt = (1.0-alfs+4.0.*alfs./pi).* tr; % h(0)

else

sub2 =16.0.*alfs.*alfs.*ym.*ym./ipoint./ipoint;

if sub2 ~= 1.0

x1=sin(pi*(1.0-alfs)/ipoint*ym)./pi./(1.0-sub2)./ym./tstp;

x2=cos(pi*(1.0+alfs)/ipoint*ym)./pi.*sub1./(1.0-sub2);

xt = x1 + x2; % h(t) plot((1:length(xh)),xh)

else % (4alphaRst)^2 = 1plot((1:length(xh)),xh)

xt = alfs.*tr.*((1.0-2.0/pi).*cos(pi/4.0/alfs)+(1.0+2.0./pi).*sin(pi/4.0/alfs))./sqrt(2.0);

end % if sub2 ~= 1.0

end % if icon == 0.0

if ncc == 0 % in the case of receiver

xh( i ) = xt ./ ipoint ./ tr; % normalization

elseif ncc == 1 % in the case of transmitter

xh( i ) = xt ./ tr; % normalization

else

error('ncc error');

end % if ncc == 0

end % for i = 1 : n

%******************** end of file ***************************

网上找的,你看看能不能拼到你那个程序里去

matlab源码运行

晕,你这是个函数啊,不能直接运行函数本身,你需要在命令行或者在其他.m文件中调用此函数

你直接运行的话,函数的输入参数没有赋值,当然会出错。

补充:C++里面怎么调用,这个是类似的。你可以先在命令行里把两个输入参数定义好,也就是指定imf = xxx,immul = xxx,然后再

执行 这个语句就行了 analysefusion(imf,immul)

你问一下你周围的人,应该马上就明白了

怎样查看matlab中SVD的源码

自带的有加密看不了,看看mathworks公司网站上会员分享的:

==========================================================

function [u,s,v] = svdsim(a,tol)

%SVDSIM simple SVD program

%

% A simple program that demonstrates how to use the

% QR decomposition to perform the SVD of a matrix.

% A may be rectangular and complex.

%

% usage: [U,S,V]= SVDSIM(A)

% or S = SVDSIM(A)

%

% with A = U*S*V' , S=0 , U'*U = Iu , and V'*V = Iv

%

% The idea is to use the QR decomposition on A to gradually "pull" U out from

% the left and then use QR on A transposed to "pull" V out from the right.

% This process makes A lower triangular and then upper triangular alternately.

% Eventually, A becomes both upper and lower triangular at the same time,

% (i.e. Diagonal) with the singular values on the diagonal.

%

% Matlab's own SVD routine should always be the first choice to use,

% but this routine provides a simple "algorithmic alternative"

% depending on the users' needs.

%

%see also: SVD, EIG, QR, BIDIAG, HESS

%

% Paul Godfrey

% October 23, 2006

if ~exist('tol','var')

tol=eps*1024;

end

%reserve space in advance

sizea=size(a);

loopmax=100*max(sizea);

loopcount=0;

% or use Bidiag(A) to initialize U, S, and V

u=eye(sizea(1));

s=a';

v=eye(sizea(2));

Err=realmax;

while Errtol loopcountloopmax ;

% log10([Err tol loopcount loopmax]); pause

[q,s]=qr(s'); u=u*q;

[q,s]=qr(s'); v=v*q;

% exit when we get "close"

e=triu(s,1);

E=norm(e(:));

F=norm(diag(s));

if F==0, F=1;end

Err=E/F;

loopcount=loopcount+1;

end

% [Err/tol loopcount/loopmax]

%fix the signs in S

ss=diag(s);

s=zeros(sizea);

for n=1:length(ss)

ssn=ss(n);

s(n,n)=abs(ssn);

if ssn0

u(:,n)=-u(:,n);

end

end

if nargout=1

u=diag(s);

end

return

在matlab中,simulink里的s-function,我添加到仿真中,在网上找了一段相当于放大器的代码,如下

关于s-function的调用,个人建议在matlab的work文件夹下新建一个m文件,修改好名字,比如test.m,将上述代码粘贴入test.m里面,然后在s-function模块的Parameters对话框内填入所需调用的名字:test,点击edit测试一下,如果能打开test.m,表明连接成功了。如果有参数传递的,可以在对话框里面填入参数名称,中间用英文逗号“,”隔开。如果感觉不方便放入work文件夹里面,可以放在仿真程序mdl同一个文件夹下,注意在matlab主界面里面,要将Current Directory调整到这个文件夹,否则会出现找不到s-function文件的提示。

设置参数gain:从上述程序看出,参数gain是从外界传递进入s-function的,所以在s-function模块对话框内下面那个填入:gain,然后点击ok。在s-function模块上面点击右键,选择edit Mask ,打开封装对话框,选择Parameters,添加一行,设置好名称和变量名:gain,最后点击ok。然后双击s-function模块,会弹出参数输入对话框,在这里输入gain的值即可,就如同普通的simulink模块一样的。

怎么调出matlab源代码

例如:假如你要查看sin(x)的源码,就在控制台输入: type sin

注意,其中sin是你要查看函数的名称;一些系统嵌入的基本函数你是看不到的。

你说的这是不可能的,因为神经网络训练好的变量是使用MATLAB内嵌函数写成的。你要想使用该网络,除非你使用MATLAB和VC++的接口程序,即启动MATLAB引擎。详见“MATLAB Engine”

1条大神的评论

  • avatar
    访客 2022-10-18 上午 09:43:41

    tstp = 1.0 ./ tr ./ ipoint;n = ipoint .* irfn;mid = ( n ./ 2 ) + 1;sub1 = 4.0 .*

发表评论