2011-06-12 77 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