2011-06-12 78 views
0

我需要建模一个电整流器,并用MATLAB绘制输入和输出信号。整流器由一个RC电路组成,其充电速度与电压增加一样快,但放电速度较慢,因此输出信号或多或少平坦。它应该看起来像这样:用MATLAB不精确绘图

rectifier from wikipedia

我试图在MATLAB上编码,我得到了这个(我的电路整流负电压,但原理相同): my figure

为了得到和维基百科一样的数字,我尝试计算下降的exp曲线(红色)和上升的窦性曲线(蓝色)之间的交集,所以我只需要添加一条正弦曲线和一条下降的exp曲线以适当的间隔获取输出信号。 这里是我的代码:

[email protected](x)sin(2*pi*250000*x+pi/2);%oscillateur de référence 
[email protected](x)sin(2*pi*250000*x); 
[email protected](x)exp(-x*10^4);%décharge du détecteur de crête 
[email protected](x)f(x)-g(x);%intersection des deux fonctions 

format long; 
inter=fzero(h,[3.82*10^-6,3.90*10^-6]); 

y1=g(0:10^-12:inter); 
y2=f(inter:10^-12:4*10^-6); 
y3=sin(2*pi*250000*(0:10^-12:1*10^-6)); 

y=-[y3 y1 y2 y1 y2]; 

y4=-f1(linspace(0,8*10^-6,length(y))); 

x=linspace(0,10*10^-6,length(y));%abscisse 

plot(x,y,x,y4); 

但为什么会出现在我的身材曲线之间的差距?

回答

1

你真的不需要找到交点。您可以使用一系列嵌套的max()调用和逻辑操作来重现相同的曲线。这里有一个例子:

[email protected](x)sin(2*pi*250000*x); 
discharge=1e-6; %# quarter period when discharge begins 
[email protected](x)exp(-rem(x-discharge,(1e-5)/2.5)*10^5); %#modulo over the period to repeat. 
[email protected](x)max(f(x).*(x<discharge),max(f(x),g(x)).*(x>=discharge)); %# the rectified signal 

y=linspace(0,1e-5,1e4); 
plot(y,f(y),y,h(y)) 

enter image description here

+0

非常感谢尤达! – snickers 2011-06-13 07:09:50