I need to model an electric rectifier and to plot both in and out signals with MATLAB. The rectifier is made of a RC circuit which charge as fast as the voltage increases but discharges way slower so the out signal is more or less flat. It’s supposed to look like that:
.
I tried to code it on MATLAB and I got this (my circuit rectifies negative voltage but same principle):
.
To get the same figure as the one from wikipedia I tried to compute the intersection between the downing exp curve (red) and the rising sinus curve (blue) so I just had to add a sin curve and a downing exp curve at right intervals to get the out signal.
Here is my code:
f=@(x)sin(2*pi*250000*x+pi/2);%oscillateur de référence
f1=@(x)sin(2*pi*250000*x);
g=@(x)exp(-x*10^4);%décharge du détecteur de crête
h=@(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);
But why is there a gap between the curves on my figure ?
You really don’t need to find the intersection points. You can reproduce the same curve with a series of nested
max()calls and logical operations. Here’s an example: