---
jupytext:
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.13
    jupytext_version: 1.15.2
kernelspec:
  display_name: Python 3 (ipykernel)
  language: python
  name: python3
---
```{code-cell} python3
:tags: [thebe-remove-input-init, auto-execute-page]

%pip install ipympl==0.9.3
```

# Diodes

## Physics
### Semiconductor
Up till now, we have seen materials which were either a conductor or an
insulator for electrical current. There is another class of materials
which we call the “semi-conductors”, these are between the conductors
and the insulators. They consist of a crystalline material in which
impurities have been brought in (“doping”).

Silicon is widely used for this, but there are other
suitable materials. Silicon for semiconductors is made from purified
sand through a multistep refining process involving purification, chemical reduction, and melting at high temperature. 
From the resulting molten silicon, a crystalline rod of silicon is made ({numref}`fig:silicon_crystal`). This rod is cut into thin
discs which are the basis for the chip industry.

```{figure} images/images_5/in_book/Silicon_single_crystal.jpg
---
name: fig:silicon_crystal
width: 350px
align: center
---
Single crystal of silicon grown by the [Czochralski process](https://en.wikipedia.org/wiki/Czochralski_process) used to make
Integrated Circuits. <br>
Created by Massimiliano Lincetto, under CC BY-SA 4.0, [original link](https://commons.wikimedia.org/wiki/File:Silicon_single_crystal.jpg)
```

The crystalline material itself is an insulator, as there are no free
charge carriers in the material. In a process called doping, impurities
are brought in the material (implantation). Materials used for this
process are e.g. Phosphorus, Arsene, Boron, Gallium. These impurities will
disturb the crystalline structure of the silicon and create spots in the
crystal lattice with either a negative or positive charge.

The negative charge is due to extra (excess) electrons in the
(disturbed) crystal lattice, this material is called N-type material.
The impurity in the silicon is the donor of the electrons. Material with
a positive charge is doped with an acceptor, creating “holes” with a
positive charge, where an electron can be “absorbed”, this is called
P-type material. This is illustrated in {numref}`fig:silicon_lattice`. To be clear: The
electrons are mobile, a hole itself is not mobile, it is an “empty spot”
in the crystal lattice which can absorb and/or release an electron.

```{figure} images/images_5/in_book/Silicon_doping_-_Type_P_and_N.svg
---
name: fig:silicon_lattice
width: 1000px
align: center
---
Pure silicon crystal lattice, P-type doped silicon structure
and N-type doped silicon structure. <br>
Created by VectorVoyager, under CC BY-SA4.0, [original link](https://commons.wikimedia.org/wiki/File:Silicon_doping_-_Type_P_and_N.svg)
```

P-type or N-type semiconductor material can be used as such, for example
for sensors. Interesting applications arise when the P-type and N-type
materials are combined to one device. Something which is done in
Integrated Circuits (ICs), better known as (electronic) chips. By the
way, the reason they are called chips is because the ICs are made, by
the hundreds, on big disks of silicon which are later on diced to
individual circuits, a chip! Wafers, ready for dicing are shown in
{numref}`fig:silicon_wafers`.

```{figure} images/images_5/in_book/Wafer_2_Zoll_bis_8_Zoll_2.jpg
---
name: fig:silicon_wafers
width: 500px
align: center
---
Processed silicon wafers, containing Integrated Circuits. <br>
Created by Stahlkocher, under CC BY-SA 3.0, [original link]( https://commons.wikimedia.org/wiki/File:Wafer_2_Zoll_bis_8_Zoll_2.jpg)
```

### PN junction
The most basic form of a semiconductor device is called a diode, where a piece of N-type material
and P-type material are joined together, a PN-junction. The name diode
originates from the Greek “di” (two) and “ode” (path). The resulting component is a
two-terminal component, which (spoiler alert!) only conducts electric
current in one direction.

Let’s have a look at what happens when we join a rectangular piece of
N-type material and a rectangular piece of P-type material ({numref}`fig:junction_depletion`).
At the junction of the two materials, there will be a transfer of
charge. The free electrons will move to the empty, positively charged
positions, the holes. When these two charges combine, the net result is
zero. The recombination of electrons and the holes will create a neutral
charged area, and the excess electrons leave a non-charged area behind,
creating a non-charged zone which is known as the depletion zone. Thus the
two materials, N and P-type, which could conduct electricity, have now
created an insulated zone where the materials meet.

```{figure} images/images_5/in_book/p-n-junction.svg
---
name: fig:junction_depletion
width: 500px
align: center
---
P-type and N-type material combined, resulting in a depletion
region around the PN-junction.
```

We did join the materials to create an electronic component. Thus the
N-type and P-type material will be part of an electronic circuit in
which electrons will (hopefully) flow. Now when there will be extra
electrons supplied to the N-type material, they will flow towards the
depletion zone, and create negatively charged spots in the neutral area.
At the same time, electrons will be subtracted from the P-type material,
these electrons will leave a positively charged hole behind. In the end
the depletion zone will be reduced to zero, and the electrons can flow
through the diode, the diode is conducting! This is illustrated in
{numref}`fig:pn_junction`.

```{figure} images/images_5/in_book/pn-junction-bias.svg
---
name: fig:pn_junction
width: 700px
align: center
---
PN-junction connected to an external voltage source. Showing
the conduction of current on the left and the blocking of current on the
right.
```

What happens when we reverse the connections on the diode (PN-junction)?
Electrons will be supplied to the P-type material. They will enter the
material and recombine with the positively charged holes. In a similar
way, electrons will be extracted from the N-material, there will be less
free charge carriers (electrons) in the N-material. The depletion zone
will broaden and no electrons will pass through the diode. In conclusion,
this device will conduct current in one direction and block current in
the other direction.

### Non-ideal diode
In practice, this is not entirely accurate. In practice it is
possible that some charge carriers will still pass the neutral area
(depletion zone). These charge carriers will create a tiny leakage
current. This current depends on the type of device. For a normal diode
this current could be as small as a few pico-Amperes (pA), but depending on
the type of diode this could be higher (micro-Amperes, $\mu A$). As this current
depends on the mobility of charge carriers one can understand that this
current is temperature dependent as well. The higher the temperature,
the more mobile the electrons will be, thus the larger the leakage
current.

But there are other mechanisms which can create extra electrons for the
leakage current. The PN-junction is often very well shielded against
light. Light is an electro-magnetic wave, but also consists of photons, with a certain energy
content. When light hits the PN-junction (depletion zone) the energy can
be absorbed by the PN-junction and will be converted into a charge
carrier. As these charge carriers will then flow to the conductive areas
of the diode, the result will be an extra current flowing through the
diode. This principle is used in sensors, for example photo-sensitive
diodes. The same effect is used for converting optic energy (light) into
electricity, like in solar cells.

In this respect we should regard light as electro-magnetic waves in its
broadest sense. Thus nuclear radiation will have a similar effect on
PN-junctions. Therefore it is possible to construct a radio-activity
detector (“Geiger counter”) with diodes as well. Later on in this
chapter we will elaborate more on the use of PN-junctions for sensors.

When special care is taken to select the proper materials, it is possible
to generate EM-waves (light, IR, UV and visible) from diodes as well. As
the (quantum-)physics are quite complex for this, we will not elaborate
on this, but LEDs (Light Emitting Diodes) are diodes as well.

## The diode in electronics

In the first part of this chapter we discussed the diode from the
physical point of view. Now it is time to have a closer look on how the
diode behaves in an electronics circuit. Let’s first have a look at the
schematic symbol, shown in {numref}`fig:diode_symbol`.

```{figure} images/images_5/in_book/Diode-Symbol.svg
---
name: fig:diode_symbol
width: 500px
align: center
---
Diode-symbol, indicating the Anode and the Cathode.
```
### Anode and Cathode
The schematic symbol of a diode is arrow-shaped. This indicates in which
direction the *electric* current can pass. It is important here to
remember that the electric current is opposite to the direction in which
the electrons flow. This contradiction comes from the fact that people
learned about electric current, before acquiring more knowledge about
electrons. They first assumed that current consisted of positive
“particles” flowing, later they found out that these “particles” were
negatively charged. At that time the wrong direction of current was well
established and could not easily be changed.

The two connections of a diode are identified as the Anode and a
Cathode. Both originate from Greek:  
- the anode originates from “Ana”, which means “up”, and “hodos” which means
“way”, so the “way up”. It can be reasoned that it is the positive
electrode at which the electric current enters the device (electrons
leave the device).  
- the cathode originates from “kata” which means “down” and “hodos”, thus
the “way down”. For this it can be said that it is the point where
electric current leaves the device (electrons enter the device).

The current will thus flow from the Anode to the Cathode. The stripe in
the symbol can very be often be found on the physical package of a real
diode, indicating the cathode.

### Practical model
Based on the description given earlier an electrical characteristic of
the diode can be derived. This is the ideal diode characteristic as
shown below.

```{figure} images/images_5/in_book/ideal-diode-characteristic.svg
---
name: fig:ideal_diode
width: 1200px
align: center
---
Diode I-U characteristics, left for the ideal diode, in the middle a simplified model on the right a more practical model.
```

In {numref}`fig:ideal_diode`a, on the horizontal axis, we see the voltage over the diode, defined as the
potential between the anode and the cathode. When it has a positive
value, the diode will pass the current. When the potential is negative
the current will be blocked. When the diode is conducting it is called
forward biased, when it is not conducting it is called reverse biased.

In {numref}`fig:ideal_diode`b, in practice, there is a certain potential (thus energy) necessary for
the electrons, to overcome the depletion region of the PN-junction.
Which means that the diode does not start to conduct directly when the
anode-cathode potential is slightly positive. There is a
threshold-voltage which has to be overcome before the diode gets forward
biased. This can be seen in the second characteristic. A typical value
for this threshold voltage is $0.6 \sim 0.7 V$. Note that this voltage
depends on the type of diode, the materials used and even shows some
temperature dependency.

The behavior as described above can be regarded as if the device has
only two modes. Not-conducting current and, when the potential is above
the threshold, it is fully conducting. Unfortunately the behavior of a
diode is not so binary, it has a more smooth way of transitioning
between blocking and conducting current. This can be modeled in a
“linear” approach as shown in {numref}`fig:ideal_diode`c.

The real curve of a diode follows a curve which can be described with
the following formula:

$$ I = I_0 \left( e^{\frac{qU}{nkT}} - 1 \right) $$

Where:  
- $I$ = the current flowing through the diode  
- $I_0$ = the diode leakage current density in the absence of light
- $U$ = voltage across the terminals of the diode 
- $q$ = absolute value of electron charge  
- $k$ = Boltzmann's constant
- $T$ = absolute temperature ($K$)
- $n$ = ideality factor, n=1 for ideal diode, 1<n<2 for most silicon diodes

The current $I_0$ depends on the construction of the diode. Furthermore,
the value of $I_0$ increases when the temperature increases due to the
higher mobility of the electrons.

The real curve of a diode will look like more smooth, as shown in {numref}`fig:voltage_diode`.

```{figure} images/images_5/in_book/voltage_diode.svg
---
name: fig:voltage_diode
width: 500px
align: center
---
Voltage-current characteristic of a real diode.
```

In this curve we can also see that the reverse voltage of the diode
is limited. At a certain voltage, which can be as high as $1000 V$, the
depletion region (say the isolation) will break through and the diode
starts to conduct. When this happens, the electric field might cause a cascase of accelerating charge carriers which create even more carriers. This process is called avalanche breakdown, causing a sudden high current, resulting in exceeding the maximum dissipation or temperature which means the end of the
diode.

In the above formula we can define the thermal voltage as  $\frac{kT}{q} = 25.85 mV$, the "thermal voltage", at $300 K$.

Given this thermal voltage we can calculate the voltage over a diode at
a given current as well.

$$ U_D(I) = \ln\left(\frac{I}{I_S} + 1\right)\eta U_T$$

The voltage $U_T$ is the thermal voltage ($\sim 25mV$). The factor $\eta$ in the
equation depends on the construction of the diode as well. The value of
$\eta$ is between 1 and 2. $I_s$ is the tiny, pA or nA, reverse saturation current.

Have a closer look at the diode curve. When the diode is conducting we
can see that the line shows some resemblance with a resistor
characteristic, be it with an offset. The slope of this curve can be
modeled as a small signal resistance
($r_d$). With that resistance the model of a diode which is
conducting will look like a series circuit of a voltage source, and
ideal diode and a resistor.

```{figure} images/images_5/in_book/electrical_models.svg
---
name: fig:electrical_models
width: 800px
align: center
---
Electrical models of the diode.
```

How to use these different models? Which model to use depends a lot on
the circuit and the way you are analyzing the circuit. Sometimes it is
sufficient to know if the diode will conduct or not, in that case the
“ideal diode” model is okay to use. However, very often the voltage drop
over the diode has a significant impact on the voltages in the circuit.
In that case the “piecewise linear” model (diode + threshold voltage
source) can best be used. The models with the added series resistance
are absolutely useful, but once you need those models, you’re heading
towards becoming a real Electrical Engineer. So, let’s conclude that
chances are pretty small that you need that model, and you'll most likely stick to {numref}`fig:electrical_models`

### Special Diodes

The general principle of diodes has been described now, however, there
are a large number of special diodes, each optimized for specific
applications. A few special diodes,
which are broadly used will be discussed here:

- the Zener-diode
- the Light Emitting Diode (LED)
- the photodiode
- the photovoltaic diode (solar-cell)

#### The Zener-Diode

The normal diode has a forward threshold voltage of $0.6 \sim 0.7V$ and a
reverse breakdown voltage tens of volts till thousand volts. The
Zener-diode has a similar forward threshold voltage of $0.6 \sim 0.7V$ and a
very well defined (accurate) reverse breakdown voltage. This breakdown
voltage ranges is defined during manufacturing and ranges from about
$1.0V$ to approximately $33.0V$. 

Breakdown voltage below  approximately 5 V are mainly caused by the Zener effect. For higher voltages, avalanche breakdown becomes the dominant mechanism. 
Both effects may occur simultaneously and have opposite temperature dependence, and in practice the term *Zener diode* is used regardless of the main breakdown mechanism. 

This type of diode is generally used in reverse bias, such that the
voltage drop over the diode equals the accurately defined Zener-voltage.
The characteristic of a Zener-diode is shown in {numref}`fig:zener_char`.

```{figure} images/images_5/in_book/diode-diode.svg
---
name: fig:zener_char
width: 800px
align: center
---
Zener-diode characteristic. 
```

Something important to consider with Zener-diodes is the maximum current
and the maximum power-dissipation. When the Zener-diode breaks down the
current an increase rapidly, thus provisions should be made to limit the
current. Usually this is done by means of a resistor (more details will
follow in the “diode circuits” section). When the maximum current is
exceeded the diode is usually damaged (becomes a short circuit).

Similar, when the reverse current flows, there is a “considerable”
voltage drop over the Zener-diode as well. This means, there is energy
converted to heat (dissipated) in the diode. The amount of energy can be
calculated by multiplying the voltage over the diode, times the current
through the diode.

$$ P_{Zener} = U_{Zener} \cdot I_{Zener} $$

The maximum power-dissipation is mentioned in the data-sheet for a
certain type of Zener diode. Exceeding this power-dissipation will cause
the diode to become to hot and the heat will damage the diode.

By the way, all diodes will dissipate energy when forward biased.
However, the forward voltage drop is usually small, still, the power
dissipation will be equal to the threshold voltage times the current.

#### The Light Emitting Diode – LED

One of the most well known diodes is the Light Emitting Diode,
abbreviated to LED. LEDs are now widely used for lighting and signaling
applications.

The PN-junction in an LED is constructed in such a way that light will
be emitted when the diode is conducting, light emission is based on the
electroluminescence effect. The wavelength of the light is determined by
the bandgap of the PN-junction, which might be slightly influenced by adapting the doping; this implies that an LED
will only emit one wavelength (with a bandwidth of 10-20 nm). While this is generally true, the optical
spectrum is not very narrow, a spectrum or band centered around a
specific wavelength is emitted. The only exception are LASER-diodes,
which emit a narrow band. The light emitted by an LED can be in the
UV-range, visible range or IR-range.

```{figure} images/images_5/in_book/led_diagram.png
---
name: fig:led
width: 800px
align: center
---
Drawing of an LED, showing how the Anode and the Cathode can be identified, based on the characteristic internal structure. <br>
Created by Inductiveload, in public domain, [original link](https://commons.wikimedia.org/wiki/File:LED,_5mm,_green_(unlabelled).svg#/media/File:LED,_5mm,_green_(en).svg)
```

Due to the different materials used in the LED PN-junction the
electrical properties are slightly different compared to normal diodes.
The forward-voltage drop is considerable higher, compared to the
standard $0.7V$. The exact number depends on the color, but is very
often in the $1.6 \sim 2.5 V$ range. Furthermore, the maximum reverse
voltage is limited to approximately 5 Volts (compare this to the tens or
hundreds of Volts for normal diodes).

```{figure} images/images_5/in_book/led_voltage.svg
---
name: fig:led_voltage
width: 800px
align: center
---
Current to voltage curve of LEDs, given for different colors. 
```

#### Photovoltaic-Cell

Another special type of diode, specially made for energy-conversion, is
the Photovoltaic-cell. This PV-cell is more known under the name
“solar-cell”. These cells are based on PN-junctions as well.

Solar-cells will convert the radiation of the sun, mostly visible light
and IR in electrical energy. The radiation will free electrons in the
PN-junction, which in turn can power an external load. Getting most of
the power from a solar-cell involves some electronics, which are outside the scope of this book.

```{figure} images/images_5/in_book/solar-cell.svg
---
name: fig:solar_cell
width: 800px
align: center
---
The construction of a solar cell, showing the polarity of the photovoltaic voltage
```

How will the electric current flow in PV-cell circuit? Here we see
something interesting, as the diode will be the source in the circuit.
Have a look at the circuits in {numref}`fig:current_flow`.

```{figure} images/images_5/in_book/current-flow.svg
---
name: fig:current_flow
width: 1200px
align: center
---
Current flow (not electron-flow!) through a normal diode and a solar cell.
```

In {numref}`fig:current_flow` we see the electric current through a normal diode. On the
right we see the current flow when the diode is a PV-cell. What we see
is that the current flow is actually the wrong way around through the
diode?! However, let’s think about it for a second:

The light which hits the PN-junction will create free electrons in the
N-type and holes in the P-type. The energy from the light will start to
flood both regions, so there are a lot of charge carriers available.
Both will recombine in the depletion region, thus there is no current
flow through the diode itself this is what happens normally, however,
now we have an affluence of charge carriers., these have to go
somewhere! The only way the electrons can flow, is away from the diodes
N-region, through the load to the P-region, so they can recombine with
the holes there. So the external electron-current which starts to flow
will go from the cathode to the anode. Now remember that the electric
current is defined opposite to the electron flow. Then the picture on
the right, in {numref}`fig:current_flow` makes sense.

#### The Photo-Diode

Diodes are used for electronic circuits, and they can be used for
sensing applications. The PN-junction proves to be sensitive to
electro-magnetic energy which hits the PN-junction as well. You can
think of light (covering a large spectrum) and ionizing radiation.

To be clear, in principle every diode is sensitive to EM-radiation, but photodiodes are optimized for this application. This is done by creating a large sensitive area, which is exposed to the environment. In {numref}`fig:examples_photodiodes` you can see some examples of photodiodes. The exposed sensitive areas (bluish) are clearly visible.

```{figure} images/images_5/in_book/Fotodio.jpg
---
name: fig:examples_photodiodes
width: 400px
align: center
---
Examples of photodiodes. The bluish area is the photo-sensitive area. <br>
Created by Ulfbastel, under CC BY-SA 3.0, [original link](https://commons.wikimedia.org/wiki/File:Fotodio.jpg)
```

Photodiodes can be used in two different ways. It can be used as a
voltage source (PV-cell) or as a light dependent current source.

When it is used as a voltage source the behavior of the photo-diode is
highly non-linear. Advantage, the voltage will rise quickly with very
little light, so it is very sensitive. The disadvantage, it is not
usable as an accurate photo-detector, which is very often needed for
accurate light-intensity measurements (think about photo-luminescence
detectors, LUX-meters etc.)

When the diode is used with zero-bias (no voltage drop over the diode)
or in reverse bias, the current (blocking current!) is highly linear
with the light intensity.

How is it possible that the diode conducts when reverse biased? The
principle is similar to the PV-cell, the light which illuminates the
photo-diode will create charge carriers. When we do not bias the diode
in reverse, it starts to behave as a voltage source (PV-cell). However,
when we actively reverse bias the diode, the only way the electrons can
start to flow is through the depletion zone. This current is in the same
direction as the leakage current, named blocking-current as well.

```{figure} images/images_5/in_book/photodiodes.svg
---
name: fig:photodiode_char
width: 800px
align: center
---
Photodiode characteristics. 
```

In {numref}`fig:photodiode_char` we see the photodiode characteristics. The three lines show
the different light levels. The line closest to the horizontal axis is
the lowest light-intensity. When the light intensity increases, more
charge carriers are generated in the diode, hence the current increases,
but in the blocking direction. The lines look equally spaced in the blue
area of the graph, indicating the linear behavior with respect to the
light-intensity. When we follow the lines of light intensity to the
right, to the PV-region, we see that at a certain moment all lines will
(almost) come together, making it very hard to distinguish the various
intensity levels, hence the non-linear behavior, but the high
sensitivity.

When the reverse voltage is too high, the diode will break-down just
like normal diodes and/or Zener-diodes.

## Diode Circuits

Diodes are very versatile components and find their application in a
wide variety of circuits. In order to understand these circuits the
first step is usually to determine if a diode is conducting or blocking
current. For these two questions need to be answered:

- is at a certain moment in time the potential (voltage) on the Anode
higher then the voltage on the Cathode?
- is the potential difference above the threshold voltage (so higher
then $0.6 \sim 0.7V$)?

If both questions can be answered with “Yes” the diode is conducting and
can be “replaced” with a voltage source of $0.6 \sim 0.7V$. (Or with a
short-circuit when the diode is considered to be ideal).

When the situation in the circuit is changing (voltages are changing)
and one of the two, or both, questions cannot be answered with “Yes”,
the diode stops conducting, and the circuit will be open (no connection)
at the position of the diode.

### Half Wave Rectifier

One of the most basic circuits is the “half wave rectifier”, it consists
of an AC-source, a diode and a resistor to limit the current. The
diagram of this circuit is shown in {numref}`fig:half_wave_rect`.

```{figure} images/images_5/in_book/half_wave_rectifier.svg
---
name: fig:half_wave_rect
width: 800px
align: center
---
Half wave rectifier. The “-” of the AC-power source is often referenced to ground.
```

Assume the “-” connection of the AC source is at ground-potential. The
AC waveform is a sinewave. At $t = 0s$ the sinewave will be at $0$ Volt and
start to increase. At that moment the potential at the Anode will
increase, while the potential at the cathode remains at $0$ Volt.
Remember, when the anode voltage is below 0.6-0.7 V, there is no current flow; no current through the resistor
means a voltage drop of $0$ Volt.

After some time, the voltage at the Anode reaches the threshold voltage
of the diode ($0.6 \sim 0.7V$). From this moment on the diode starts to
conduct, and the voltage on the Cathode, will follow the voltage on the
Anode minus the threshold voltage. For example for an anode at 1 V and a cathode at 0.3 V. 

This will be the situation, till the voltage on the Anode drops below
the threshold voltage.

The source will lower its output to zero volts, then it starts on the
negative period of the sinewave. During this whole period, the voltage
on the Anode will be lower then the $0$ Volt potential of the Cathode.
This means the diode will block during the whole negative part of the
sinewave.

When the new cycle starts, the whole process/cycle will be repeated.

The result of this, is that only the positive parts of the sinewave will
be allowed to pass to the (load-)resistor. This is more or less
(remember the loss due to the threshold voltage) half the period. Hence
the name, half wave rectifier.

The AC-voltage and the resulting voltage over the (load-)resistor are
shown in {numref}`fig:ac_rect`.

Please note, that the voltage over the load is only positive. It is not
continuous, but the average voltage is positive, therefore it is said
that the voltage is rectified.

:::{figure-start} images/nothing.svg
:name: fig:ac_rect
:alt: Nothing
:align: center
The AC-voltage and the rectified voltage over the resistor.
:::

```{code-cell} python3
:tags: [hide-input, thebe-init]
import numpy as np
import matplotlib.pyplot as plt

# ====== Parameters ======
f = 50               # Signal frequency (Hz)
w = 2*np.pi*f
Upeak = 5            # Input peak voltage
Ud = 0.7             # Diode forward voltage drop
T = 1/f

t_max = 2/f

t = np.linspace(0, t_max, 2000)   # show two periods

Uin = Upeak * np.sin(w*t)       # input sinusoid
Uout = np.maximum(Uin - Ud, 0)  # half-wave rectified output


# ====== Plot ======
fig, ax = plt.subplots(figsize=(10, 4), dpi=150)

# Input waveform
ax.plot(t, Uin, color="blue", linewidth=2, label=r"$U_{in}$")

# Output (load) waveform
ax.plot(t, Uout, color="green", linewidth=2, label=r"$U_L$")

t_peak = T/4
y_top  = Upeak
y_bot  = max(Upeak - Ud, 0)

xM = t_peak + 0.1*T   # shift right of the peak (adjust as needed)

# Horizontal top line
ax.plot([xM - 0.075*T, xM + 0.025*T], [y_top, y_top], color="black", linewidth=1)

# Horizontal bottom line
ax.plot([xM - 0.075*T, xM + 0.025*T], [y_bot, y_bot], color="black", linewidth=1)

# Vertical arrow for the spacing
ax.annotate("", xy=(xM, y_top + 0.15), xytext=(xM, y_bot - 0.15), arrowprops=dict(arrowstyle="<->", lw=1.5, color="black"))

ax.text(xM + 0.03*T, 0.5*(y_top + y_bot), "0.7 volts", va="center", ha="left", fontsize=12)

# Axes config
ax.axhline(0, color="black", linewidth=1)
ax.text(t_max + 0.0002, 0, "t", va="center", ha="left", fontsize=12)
ax.set_xlabel("")
ax.set_ylabel("")
ax.set_xlim(0, 2/f)

ax.set_xticks([])
ax.set_yticks([])

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)

ax.legend(frameon=False)
plt.tight_layout()
plt.show()
```

:::{figure-end}
:::

### Peak-detector or Half-wave Rectifier with Buffer Capacitor

As seen with the half-wave rectifier, the resulting voltage is a pulsed
voltage. This voltage is not very suitable for powering circuits, as
these usually require a more constant voltage. For this purpose a
capacitor can be added to the circuit, which will “smooth” the resulting
voltage.

Have a look at the circuit-diagram in {numref}`fig:buffer_rect`, the capacitor is placed
in parallel with the (load-)resistor.

```{figure} images/images_5/in_book/half-wave-rectifier_plus_cap.svg
---
name: fig:buffer_rect
width: 800px
align: center
---
Half-wave rectifier with buffer-capacitor.
```

Let’s have a look on how this circuit is functioning. We assume the
voltage over the capacitor is $0V$ (capacitor is discharged) and the AC
source starts its first period of the sinewave. Again the voltage of the
sinewave has to increase above the threshold voltage of the diode. Once
it has reached the threshold voltage, the diode will conduct the
current. The current is now supplied to the capacitor and the
(load-)resistor. This current will charge the capacitor till the AC-peak
voltage minus the diode-threshold. Thus, when the amplitude is $10V$, and
the threshold voltage is $0.7V$, the capacitor will be charged till $10V - 0.7V = 9.3V$.

After the AC-source has reached its peak-value, the voltage will start
to drop. From this moment on the potential at the cathode will not
follow the AC-voltage, but it will remain “high”, as the potential at the
cathode will be too high for the diode to conduct. With other words, the
potential-drop over the diode ($U_{anode} – U_{cathode}$) will be below the
threshold voltage and will even become negative!

From this moment on, the diode will not conduct anymore. However, energy
will be supplied from the capacitor to the (load-)resistor, as the capacitor will discharge via the resistor. Due to this
drain of energy, the potential over the capacitor will start to drop. The capacitor will act as an electron supply. 

When looking at the negative part of the sinewave, the diode will not
conduct, just as in the half-wave rectifier without the capacitor.

When the next cycle of the AC-source starts, the
voltage at the Anode has to increase, till it is $0.6 \sim 0.7V$ above the
Cathode potential. But, the Cathode is now not at $0V$, but at the residual
potential supplied by the capacitor. Once the Anode is at the
capacitor-voltage plus the threshold voltage, the diode will start to
conduct again, and current is again supplied to the capacitor and the
(load-)resistor.

The voltage over the (load-)resistor and the capacitor will now increase
again to the peak-voltage of the source (minus the diode-threshold
voltage). From here on, the process will be repeated continuously. The
resulting waveforms are shown in {numref}`fig:waveforms_rect`.

:::{figure-start} images/nothing.svg
:name: fig:waveforms_rect
:alt: Nothing
:align: center
Waveforms of the half-wave rectifier with buffer-capacitor.
:::

```{code-cell} python3
:tags: [hide-input, thebe-init]

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

# ====== Parameters ======
f   = 50.0                 # mains frequency (Hz)
T   = 1.0 / f
w   = 2.0 * np.pi * f
Up  = 10.0                 # input peak voltage
Ud  = 0.7                  # diode drop (set 0.7 for silicon diode look)
tau = 2.5 * T              # RC time constant (bigger -> smaller ripple)

t = np.linspace(0, 3*T, 3000)
dt = t[1] - t[0]

Uin = Up * np.sin(w * t)                # AC input
Uin_env_hw = np.maximum(Uin - Ud, 0.0)  # half-wave rectified envelope (no capacitor)

# ======= Capacitor simulation (half-wave) =======
dU_est    = (Up - Ud) * (1.0 - np.exp(-T / tau))    # crude half-wave ripple estimate
Umean_est = (Up - Ud) - 0.5 * dU_est
U_cap     = max(Umean_est, 0.0)

Uout = np.zeros_like(t)
for i, ti in enumerate(t):
    Uin_d = Uin[i] - Ud
    if Uin_d > U_cap and Uin_d > 0:
        # Diode conducts -> capacitor charges quickly up to source
        U_cap = Uin_d
    else:
        # Diode off -> capacitor discharges through RL
        U_cap *= np.exp(-dt / tau)
    Uout[i] = U_cap

# ====== Figure ======
mpl.rcParams['svg.fonttype'] = 'none'   # keep text editable if you save SVG
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(9.5, 5.8), dpi=150, sharex=True)

# Top: input sine
ax1.plot(t, Uin, linewidth=2, color="#2f50ff", label="$U_{in}$")
ax1.axhline(0, color="black", linewidth=1)
ax1.set_ylabel("$U_{in}$", fontsize=14)
ax1.set_xlim(0, 3*T)
# ax1.set_ylim(0,)

# Bottom: output with capacitor
ax2.plot(t, Uout, linewidth=2, color="#2f50ff", label="$U_{out}$")
ax2.plot(t, Uin, linestyle="--", alpha=0.45, color="gray", label="Half-wave")
ax2.axhline(0, color="black", linewidth=1)
ax2.set_ylabel("$U_{out}$", fontsize=14)
ax2.set_xlabel("t (seconds)", fontsize=12)
ax2.set_xlim(0, 3*T)

mid_mask = (t > 1*T) & (t < 2*T)
tm  = t[mid_mask]
vm  = Uout[mid_mask]
vm_env = Uin_env_hw[mid_mask]

# charging
i_peak = np.argmax(vm) # where cap is recharged
t_peak = tm[i_peak]
U_peak = vm[i_peak]
ax2.annotate("Capacitor\ncharges", xy=(t_peak-0.1*T, U_peak-0.1*Up), xytext=(t_peak - 0.42*T, U_peak), arrowprops=dict(arrowstyle="->"))

# discharging
i_mid = min(i_peak + int(0.20*len(tm)), len(tm)-1)
ax2.annotate("Capacitor\ndischarges", xy=(tm[i_mid], vm[i_mid]), xytext=(tm[i_mid] + 0.12*T, vm[i_mid] + 0.10*Up), arrowprops=dict(arrowstyle="->"))

for ax in (ax1, ax2):
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    # ax.legend(frameon=True, loc="upper right")
    ax.set_yticks([])
ax1.set_xticks([])

plt.tight_layout()
plt.show()
```

:::{figure-end}
:::

From this it can be seen that the voltages approaches a more or less
constant DC-voltage. The amount of voltage lost, due to discharging of
the capacitor, depends on the amount of current (energy) which flows to
the (load-)resistor. When the load is using very little power, the
voltage will be at almost the same level, thus it remains at the
peak-voltage of the AC-voltage. Hence the name “peak-detector” is used
for this circuit as well.
This variation is called the “ripple-voltage”, the voltage is called $U_{rpp}$
in {numref}`fig:ripple_rect`.

Note that when this circuit is used for powering electronics, more current is
drained from the capacitor, giving a larger ripple voltage.

:::{figure-start} images/nothing.svg
:name: fig:ripple_rect
:alt: Nothing
:align: center
Ripple voltage of a half-wave rectifier.
:::

```{code-cell} python3
:tags: [hide-input, thebe-init]

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# ===== Parameters =====
f = 50                  # mains frequency (Hz)
T = 1.0 / f
w = 2.0 * np.pi * f
Up = 1.0                # normalized peak
tau = 3*T               # RC time constant (bigger -> smaller ripple)

# Warm up long, then show only the last 3 periods
T_warm   = 8 * T
N_total  = 16000
t_all    = np.linspace(0, T_warm, N_total)

def hw_env(tt):
    s = Up * np.sin(w * tt)
    return np.where(s > 0, s, 0.0)

U_env_all = hw_env(t_all)

# ===== Simulate charge/discharge (HALF-WAVE)=====
U_cap = 0.0
U_out_all = np.zeros_like(t_all)

for i in range(len(t_all)):
    U_in = U_env_all[i]
    if i > 0:
        dt = t_all[i] - t_all[i-1]
        if U_in > U_cap:           # fast recharge at peaks
            U_cap = U_in
        else:                      # exponential discharge through load
            U_cap *= np.exp(-dt / tau)
    U_out_all[i] = U_cap

# ===== Take steady-state window: last 3 periods =====
t0        = t_all[-1] - 3*T
mask_plot = t_all >= t0
t         = t_all[mask_plot] - t0        # start at 0 for nice axes
U_out     = U_out_all[mask_plot]
U_env     = U_env_all[mask_plot]

# ===== Stats + mid-period annotations (middle of the 3 periods) =====
Umean = float(np.mean(U_out))

mid_mask = (t >= 1*T) & (t <= 2*T)
tm  = t[mid_mask]
Um  = U_out[mid_mask]
t_peak = tm[np.argmax(Um)]
U_peak = Um.max()
t_val  = tm[np.argmin(Um)]
U_val  = Um.min()

# ===== Plot =====
fig, ax = plt.subplots(figsize=(11, 4.6), dpi=150)

ax.plot(t, U_out, linewidth=2, color="#2f5597", label="Filtered output")
ax.plot(t, U_env, linestyle=":", alpha=0.6, color="#e69138",
        label="Rectified input (envelope)")

# Reference lines
ax.axhline(Umean, linestyle="--", linewidth=1, alpha=0.9, color="#6d9eeb")
ax.axhline(Up, linestyle="-", linewidth=1, alpha=0.9, color="#3d85c6")
ax.axhline(U_val, linestyle="-", linewidth=1, alpha=0.9, color="#3d85c6")

ax.text(-0.03*T, Up, r"Peak, $U_p$", va="bottom", ha="right")
ax.text(-0.03*T, Umean, r"Mean, $U_{dc}$", va="bottom", ha="right")

ax.annotate("", xy=(t_peak, U_peak), xytext=(t_peak, U_val), arrowprops=dict(arrowstyle="<->", lw=1.5, color="black"))
ax.text(t_peak + 0.02*T, 0.5*(U_peak + U_val) - 0.03, r"Ripple voltage $\Delta U$", va="center", ha="left")

ax.annotate("Discharging\nperiod", xy=(t_peak - 0.4*T, U_peak), xytext=(t_peak - 0.4*T, Up*1.07), ha="center", arrowprops=dict(arrowstyle="->"))
ax.annotate("Charging\nperiod", xy=(t_peak - 0.08*T, U_peak), xytext=(t_peak - 0.08*T, Up*1.07), ha="center", arrowprops=dict(arrowstyle="->"))

x0, x1 = 1*T, 2*T
ax.annotate("", xy=(x0, 0.05), xytext=(x1, 0.05), arrowprops=dict(arrowstyle="<->", lw=1.4, color="black"))
ax.text((x0 + x1)/2, 0.075, "Period $T$", ha="center")

# Axes config
ax.set_xlim(0, 3*T)
ax.set_ylim(0, 1.15)
ax.set_xlabel("Time (seconds)")
ax.set_ylabel(r"$U_{rpp}$ (Volts)")
ax.set_yticks([]); ax.set_xticks([])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

plt.tight_layout()
plt.show()
```

:::{figure-end}
:::

In principle the capacitor could discharge till $0V$, if the next charging period does not start too soon. Discharging would occur according to an e-power,
thus:

$$ U_c = U_{peak}\cdot e^{-\frac{t}{RC}} $$

In practice, the capacitor will only be partially discharged. Its value is often chosen such that the ripple voltage is minimal. The charge
time, and discharge time depend on the amplitude of the ripple voltage.
The sum of the charge and discharge time are the period-time ($T$).

Because of the partial discharge, and the almost constant voltage over
the resistor, we can use a linear approximation for the ripple voltage.
The (almost) constant voltage over the resistor, draws a constant
current from the capacitor. Therefore we can use the formula for the
charge on the capacitor to approximate the ripple voltage.

$$dQ = C \cdot dU = I \cdot dt$$

In this case the dU is describing the voltage change over the capacitor,
thus the ripple voltage. As the current is defined by Ohm’s law, we can
calculate the current. The frequency of the AC-source is very often
known as well, and we assume that dt equals the period-time. In this
case we further assume that the charge-time is short compared to the
discharge time, so we can neglect the time for the charging.

$$dU = U_{ripple} = \frac{U_{cap}T}{RC}$$

With:
- $T$ = period-time $[s]$
- $U_{cap}$ = DC-voltage over the capacitor
- $R$ = (load-)resistor $[\Omega]$
- $C$ = capacitor-value $[F]$

### Bridge Rectifier

The rectifying circuit described before, only takes advantage of the
positive part of the sinewave. It is possible to build a circuit which
makes use of both the positive and negative part of the sinewave. This
circuit is known as the bridge-rectifier or “Graetz bridge”.

The circuit makes use of four diodes in total. The diodes conduct in
pairs, one pair for the positive part of the sinewave, the other pair
for the negative part. The diagram of the bridge-rectifier is shown in
{numref}`fig:bridge_rect`.

```{figure} images/images_5/in_book/Bridge-Rectifier-with-Smoothing-Capacitor.svg
---
name: fig:bridge_rect
width: 800px
align: center
---
Bridge rectifier circuit, with load-resistor and buffer (smoothing)capacitor.
```

As said the diodes will conduct in pairs. When the top side of the
voltage source is positive, the current will flow through D1, through
the capacitor and the resistor, through D2 back to the source. When the
bottom side of the source is positive compared to the top-side, the
current will flow from the source, through D4, the capacitor and the
resistor, through D3, back to the source. The current flow through the
capacitor and the resistor will be in the same direction in both
situations.

This can be seen in {numref}`fig:power_supply`. Here the voltage source is replaced by a
transformer. In most instruments this configuration is used. The
transformer steps down the mains-voltage ($230V$) to a lower voltage, then
this voltage is rectified by the bridge and smoothed by the capacitor.

```{figure} images/images_5/in_book/Full-Wave-Rectifier-Showing-Current-Flow.svg
---
name: fig:power_supply
width: 800px
align: center
---
Simple power supply circuit.
```

The resulting waveform is shown in {numref}`fig:double_rect`. From this we can see that
the capacitor is charged twice per period.

:::{figure-start} images/nothing.svg
:name: fig:double_rect
:alt: Nothing
:align: center
Double rectified AC-voltage waveform.
:::

```{code-cell} python3
:tags: [hide-input, thebe-init]

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams.update({'font.size': 12, 'axes.labelsize': 14})

# =========================
# Simulation Parameters
# =========================
f = 10              # AC frequency (Hz)
T = 1/f
t = np.linspace(0, 2*T, 2000)
t_ms = t * 1000

U_peak = 10.0
U_diode_drop = 0.7          # total forward drop per conduction path

U_ac_in = U_peak * np.abs(np.sin(2*np.pi*f*t))
U_rect = np.maximum(U_ac_in - U_diode_drop, 0.0)
U_rect_peak = np.max(U_rect)

# =========================
# Capacitor simulations
# =========================

# --- Case B: Light load ---
RC_B = 0.2
U_cap_B = np.zeros_like(t)
U_cap_B[0] = 0.85 * U_rect_peak

for i in range(1, len(t)):
    dt = t[i] - t[i-1]
    if U_rect[i] > U_cap_B[i-1]:
        U_cap_B[i] = U_rect[i]
    else:
        U_cap_B[i] = U_cap_B[i-1] * np.exp(-dt / RC_B)

# --- Case C: Heavy load ---
RC_C = 0.05
U_cap_C = np.zeros_like(t)
U_cap_C[0] = 0.70 * U_rect_peak

for i in range(1, len(t)):
    dt = t[i] - t[i-1]
    if U_rect[i] > U_cap_C[i-1]:
        U_cap_C[i] = U_rect[i]
    else:
        U_cap_C[i] = U_cap_C[i-1] * np.exp(-dt / RC_C)

# =========================
# Average and Max values
# =========================
U_dc_avg_noC = np.mean(U_rect)
U_dc_avg_B   = np.mean(U_cap_B)
U_dc_avg_C   = np.mean(U_cap_C)
U_max_B      = np.max(U_cap_B)
U_max_C      = np.max(U_cap_C)

# =========================
# Peak + valley detection
# =========================
def env_peaks_indices(U):
    Ur = np.array(U)
    return np.where((Ur[1:-1] > Ur[:-2]) & (Ur[1:-1] >= Ur[2:]))[0] + 1

def discharge_valleys_between_peaks(U_cap, peaks):
    valleys = []
    for a, b in zip(peaks[:-1], peaks[1:]):
        k = a + np.argmin(U_cap[a:b])
        valleys.append(k)
    return np.array(valleys, dtype=int)

peaks_idx = env_peaks_indices(U_rect)
i0, i1, i2 = peaks_idx[:3]

# B valleys
valleys_B = discharge_valleys_between_peaks(U_cap_B, peaks_idx)
val1_B, val2_B = valleys_B[:2]

# C valleys
valleys_C = discharge_valleys_between_peaks(U_cap_C, peaks_idx)
val1_C, val2_C = valleys_C[:2]

# Time markers
t1_B_start = t_ms[val1_B]
t1_B_end   = t_ms[i1]
t2_B_start = t_ms[i1]
t2_B_end   = t_ms[val2_B]

t1_C_start = t_ms[val1_C]
t1_C_end   = t_ms[i1]
t2_C_start = t_ms[i1]
t2_C_end   = t_ms[val2_C]

# =========================
# Plotting
# =========================
fig, axes = plt.subplots(3, 1, figsize=(10, 9))

y_min, y_max = 0, 1.1 * U_peak

# =========================
# PANEL 1 - No capacitor
# =========================
axes[0].plot(t_ms, U_ac_in, color='tab:orange', linestyle='-', linewidth=1.5)
axes[0].plot(t_ms, U_rect, color='#9B1FA8', linestyle='--', linewidth=2)

axes[0].axhline(U_dc_avg_noC, color='gray', lw=1, ls='--', alpha=0.7)
axes[0].axhline(U_rect_peak, color='gray', lw=1, ls='--')

axes[0].text(-2, U_rect_peak, '$U_{max}$', ha='right', va='center')
axes[0].text(-2, U_dc_avg_noC, '$U_{dc}$', ha='right', va='center')

# # Annotate diode drop region near peak
# gap_x = t_ms[i1]
# axes[0].annotate('', xy=(gap_x, U_ac_in[i1]), xytext=(gap_x, U_rect[i1]), arrowprops=dict(arrowstyle='<->', color='crimson', lw=1.4))
# axes[0].text(gap_x + 3.0, 0.5 * (U_ac_in[i1] + U_rect[i1]), '≈0.7 V gap', color='crimson', va='center')

axes[0].set_ylim(y_min, y_max)
axes[0].set_xlim(0, t_ms[-1])
axes[0].set_title("Full-wave output with no filter capacitor", loc='left')
axes[0].grid(alpha=0.3)

# =========================
# PANEL 2 - Light load
# =========================
axes[1].plot(t_ms, U_ac_in, color='tab:orange', linestyle='--', linewidth=1.5)
axes[1].plot(t_ms, U_rect, color='#9B1FA8', linestyle='--', linewidth=2)
axes[1].plot(t_ms, U_cap_B, color='tab:blue', linewidth=2)

axes[1].axhline(U_dc_avg_B, color='gray', lw=1, ls='--', alpha=0.7)
axes[1].axhline(U_max_B, color='gray', lw=1, ls='--')

axes[1].text(-2, U_max_B+0.02*U_peak, '$U_{max}$', ha='right')
axes[1].text(-2, U_dc_avg_B, '$U_{dc}$',  ha='right')

# t1
axes[1].axvline(t1_B_start, color='gray', lw=1.3)
axes[1].axvline(t1_B_end, color='gray', lw=1.3)
axes[1].annotate('', xy=(t1_B_end, 0.06*U_peak), xytext=(t1_B_start, 0.06*U_peak), arrowprops=dict(arrowstyle='<->', lw=1.2))
axes[1].text((t1_B_start+t1_B_end)/2, 0.1*U_peak, '$t_1$', ha='center')

# t2
axes[1].axvline(t2_B_end, color='gray', lw=1.3)
axes[1].annotate('', xy=(t2_B_end, 0.06*U_peak), xytext=(t2_B_start, 0.06*U_peak), arrowprops=dict(arrowstyle='<->', lw=1.2))
axes[1].text((t2_B_start+t2_B_end)/2, 0.1*U_peak, '$t_2$', ha='center')

axes[1].set_ylim(y_min, y_max)
axes[1].set_xlim(0, t_ms[-1])
axes[1].set_title("Filtered output across light load", loc='left')
axes[1].grid(alpha=0.3)

# =========================
# PANEL 3 - Heavy load
# =========================
axes[2].plot(t_ms, U_ac_in, color='tab:orange', linestyle='--', linewidth=1.5)
axes[2].plot(t_ms, U_rect, color='#9B1FA8', linestyle='--', linewidth=2)
axes[2].plot(t_ms, U_cap_C, color='tab:blue', linewidth=2)

axes[2].axhline(U_dc_avg_C, color='gray', lw=1, ls='--', alpha=0.7)
axes[2].axhline(U_max_C, color='gray', lw=1, ls='--')

axes[2].text(-2, U_max_C, '$U_{max}$', ha='right')
axes[2].text(-2, U_dc_avg_C,'$U_{dc}$',  ha='right')

# t1
axes[2].axvline(t1_C_start, color='gray', lw=1.3)
axes[2].axvline(t1_C_end, color='gray', lw=1.3)
axes[2].annotate('', xy=(t1_C_end, 0.06*U_peak), xytext=(t1_C_start, 0.06*U_peak), arrowprops=dict(arrowstyle='<->', lw=1.2))
axes[2].text((t1_C_start+t1_C_end)/2, 0.1*U_peak, '$t_1$', ha='center')

# t2
axes[2].axvline(t2_C_end, color='gray', lw=1.3)
axes[2].annotate('', xy=(t2_C_end, 0.06*U_peak), xytext=(t2_C_start, 0.06*U_peak), arrowprops=dict(arrowstyle='<->', lw=1.2))
axes[2].text((t2_C_start+t2_C_end)/2, 0.1*U_peak, '$t_2$', ha='center')

axes[2].set_ylim(y_min, y_max)
axes[2].set_xlim(0, t_ms[-1])
axes[2].set_title("Filtered output across heavy load", loc='left')
axes[2].set_xlabel("Time (ms)")
axes[2].grid(alpha=0.3)

# Remove ticks for clean look
for ax in axes:
    ax.set_yticks([])
    ax.set_xticks([])

plt.tight_layout()
plt.show()
```
:::{figure-end}
:::


As the time between the charging of the capacitor is half of the time of
a single sided rectifier, we can assume that the ripple voltage will be
smaller. With other words, with the same size of buffer-capacitor we
will have half the ripple voltage. We can divide the period-time by two,
this gives us the following formula for the ripple voltage:

$$
dU = U_{ripple} = \frac{U_{cap}T}{2RC} 
$$

A remark about the resulting voltage: As the current path is passing
through two diodes, we will lose two times the threshold voltage. The
rectified peak-voltage will thus be the AC-peak voltage minus two times
the diode-threshold voltage.

### Signal Circuits with Diodes

The previous applications of the diode, were more or less aimed at power
supply circuits, although they can be used for signal processing as
well. There are other diode circuits which are seen more often in
signal-processing circuits.

Diodes are for example used on (sensitive) inputs of instruments, in
order to protect these inputs from too high voltages or voltages with
the wrong polarity. The diodes can be used to limit these voltages too
safe values. It should be noted that usually a slightly higher or small
negative voltage can be allowed on an input.

As each circuit/instrument can have its own limits, a big variety of
circuits has been developed over the years. Here we will show some
examples, from these one should be able to analyze or design the
necessary circuits for a specific application.

### The Diode Clipper

In {numref}`fig:one_diode_clipper` one of the simplest clipper circuits is shown. It could be
used to protect an input from negative voltages.

```{figure} images/images_5/in_book/one_diode_clipper.svg
---
name: fig:one_diode_clipper
width: 800px
align: center
---
The one-diode clipper.
```

In the circuit we see a resistor $R_L$, which could be the input-impedance
of an amplifier. The signal Uin is an AC-source, giving both positive
and negative voltages. The negative parts should be removed (clipped)
before it enters the amplifier. By using a diode this can be done!

When the input-voltage is positive the potential on the Anode (at ground level, bottom of image) will be
lower then the potential on the Cathode (top of image). The diode
will block and no current will flow through the diode.

When the input-voltage is negative, the Anode will have a higher
potential compared to the Cathode, thus the diode will conduct. The
voltage is limited to the threshold voltage. Resistor R1 is added,
to limit the current through the circuit to an acceptable level. When
the R1 resistor would not be there, there would be a problem, as the
voltage-source will supply a voltage, while the voltage over the diode
is limited to the threshold voltage.

This circuit will cut off the negative portion of the signal. When we
would reverse the diode connections, the circuit will cut-off the
positive portion of the input-signal.

We can build a clipper with two diodes as well. Such a circuit is shown
in {numref}`fig:double_diode_clipper`.

```{figure} images/images_5/in_book/sim-circuit.svg
---
name: fig:double_diode_clipper
width: 800px
align: center
---
Double diode clipper.
```

The double diode clipper will limit the signal both for the positive and
the negative part. Let’s say the threshold voltage of the diode is
$0.7V$. In that case the voltage on the output of the circuit, thus $U_{out}$,
would be at highest $+0.7V$ and at its lowest $-0.7V$. Between these voltage
limits, the diodes will not conduct (so not influence the signal!) and
the signal will pass to the output. Such circuit can be used as a protective circuit, blocking too high voltages. 

### Clipper Circuits with Offset Voltage

In the previous circuits, the clipping voltage was defined by the
threshold voltage of the diode(s). These circuits are absolutely useful,
but very often some more flexibility is needed. In those situations
combinations can be made with fixed voltage sources and diodes. An
example is shown in {numref}`fig:double_diode_clipper_offset`.

```{figure} images/images_5/in_book/double_diode_clipper_offset.svg
---
name: fig:double_diode_clipper_offset
width: 800px
align: center
---
Double diode clipper with offset-voltage sources.
```

Two diodes are used to be able to clip the positive and the negative
voltages. Diode D1 is used for limiting the voltages with positive
polarity, diode D2 for the voltages with negative polarity.

When figuring out the working-principle of the circuit, one needs to
determine if the diode is conducting or not. For this example we assume
the threshold voltage over the diode is $0.7V$.

Let’s have a look at D1: The Cathode of this diode is at a potential of
$3$ Volt, due to the voltage source. The diode will only conduct when the
Anode is $0.7V$ higher compared to the Cathode, which will be $3.7V$ in this
specific case. When the diode is conducting the voltage will be held at
$3.7V$.

A similar reasoning can be followed for the negative voltage, due to the
offset voltage of $-5V$, the limit will be at $-5.7V$.

By adjusting the fixed voltage sources, a wide range of limits can be
set.

### Clipper Circuit with Zener-Diodes

Instead of using normal diodes, clippers can be made with zener-diodes
as well. Remember, a zener diode acts as a normal diode in one
direction, and will start conducting current in the opposite direction,
once the voltage reaches the zener-voltage.

In {numref}`fig:zener_clipper` we see two different clipper circuits using zener-diodes.
Both circuits will limit the voltage in both the positive polarity and
with the negative polarity.

```{figure} images/images_5/in_book/128_square_wave_signal.svg
---
name: fig:zener_clipper
width: 800px
align: center
---
Zener-diode clipper circuits.
```

In the example with the single zener-diode, we can see that the voltage
will be clipped at the threshold-voltage ($-0.7V$) when the voltage is
negative. The zener-diode starts to conduct with positive voltages once
the zener-voltage level is reached. The resistor will limit the current
to safe levels like in the previous circuits.

The circuit with the two zener diodes functions in a similar way, but:
Both diodes have to conduct before the circuit starts to limit the
voltage, which means that the actual clipping voltage is the threshold
voltage plus the zener-voltage of the other diode.

For positive voltages Dz1 has to conduct normally ($0.7V$) and Dz2 will
conduct once its zener-voltage is reached. For negative voltages, Dz2
will conduct normally ($0.7V$) and the zener-voltage of Dz1 has to be
reached.

Something to think about: Could a similar circuit be made with the two
zener-diodes in parallel? Like the circuit in {numref}`fig:double_diode_clipper`.

```{admonition} Answer
:class: dropdown
No, in that case the voltage will be limited by the threshold-voltage of the diodes ($0.7V$), as this voltage is lower than the zener-voltage.
```

### Clamper Circuits

Another category of diode-circuits are the “clampers”. Clampers are
circuits based on a diode in conjunction with a capacitor (and very
often some other components). These circuits will not limit the voltage
between certain values, but they are able to shift the DC-potential of a
signal. In this manner a sinewave which has positive and negative
periods, can be shifted upwards, such that the whole sinewave will be
above $0V$.

Again, there is a wide variety of clamper circuits. Here we will show
and explain an example, such that the principle will be clear. In {numref}`fig:clamper_circuit` we see a clamper circuit, this circuit will be further analyzed here.

```{figure} images/images_5/in_book/Diode-clamper-circuit-positive-biased.svg
---
name: fig:clamper_circuit
width: 800px
align: center
---
A clamper circuit which will shift an AC signal above ground-level.
```

In {numref}`fig:clamper_circuit` we see the clamper-circuit together with an input-signal
and its output-signal. The input is symmetrical around zero (a normal
sinewave). The output is a sinewave which has been shifted upwards (an
offset has been added). The addition of the offset could be done with a
DC-source, however, this is very often not practical or not possible.

In this case we use the capacitor as a replacement for the DC-source.
Remember that a charged capacitor will have a DC-voltage over its
terminals. When the charge/discharge over the capacitor is small, the
voltage will remain constant.

How will the capacitor be charged in this circuit? Let’s start with an
input voltage of $0 V$ (the sinewave is at $0V$) and assume the capacitor is
discharged. At that moment the Anode of the diode is at $+3V$, the cathode
of the diode will be at $0V$ (!). This will give a huge current through
the diode and the capacitor (only limited by some residual resistance
from the diode or wire). This will instantaneously charge the capacitor
to $2.3V$, $3V$ of the source, minus the threshold-voltage of the diode.

When the sinewave starts to move to the positive side, the diode will
block, because the voltage at the cathode will move from $+2.3$ to $+7.3V$.
Some charge will be lost in the $1M\Omega$ resistor, however, this can be
neglected because of the high RC time. When the sinewave moves towards its negative period, the
diode will start to conduct again. The negative peak-voltage of the
sinewave ($-5V$) will charge the capacitor to a total of $7.3V$. The “+” of
the capacitor will be at $+2.3V$, the negative side will be at $-5V$ giving
the total of $7.3V$.

In the next positive cycle this $7.3V$ is added to the the sinewave. This
means that when the sinewave is at its positive peak of $+5V$, the voltage
at the output (over R1) is $5V + 7.3V = 12.3V$.

When the sinewave is at its negative peak ($-5V$) the output voltage will
be $-5V + 7.3V = 2.3V$.

Here we can see that the circuit will always give a positive voltage
once the capacitor is charged.

## Practical Diodes

In practice there is a huge variety of diodes. There are diodes for small
signal (low-power) applications, but there are diodes for high-power
applications as well (diodes which can handle thousands of amps!). Nost often small diodes are used. These diodes come in similar
packages, some examples are shown in {numref}`fig:small_signal_diodes`.

```{figure} images/images_5/in_book/Diodes_updated.jpg
---
name: fig:small_signal_diodes
width: 600px
align: center
---
Some typical small-signal (low-power) diodes. <br>
Created by Omegatron, under CC BY-SA 3.0, [original file](https://commons.wikimedia.org/wiki/File:Diodes.jpg)
```

When looking at the diodes, one can see a ring or a dot on onde side of
the diodes. This mark is always placed at the Cathode of the diode.

Another type of diode we will probably use, is the LED. LEDs do exist in
a large number of shapes and colors. When using LEDs it is important to
identify the Cathode and the Anode as well.

```{figure} images/images_5/in_book/LED_diagram2.svg
---
name: fig:diode_led_orientation
height: 400px
align: center
---
Typical LED showing the orientation of the diode inside the LED. 
```

### Practical Diode Limitations

Each component has its limitations. To be sure, always check the
datasheet of that specific component. For that the type-number is
important.

Limitations for diodes are the maximum current it can handle
and the maximum reverse voltage.

For signal-diodes:

* Take into account the maximum forward current it can handle. It
usually ranges from $100mA$ to about $1A$.
* Pay attention to the maximum reverse voltage for small diodes this
can be in the order of $50V$, but can easily extend to $1000 V$ ($1 kV$!).

For LEDs:

* Take care not to exceed the maximum current through the LED. Typical
value is $20 mA$.
* The maximum reverse voltage of an LED is fairly low, usually around
$5V$. So actually they are pretty lousy diodes, however, they make good
optical indicators!

Zener-diodes:

* For zener-diodes always pay attention to the maximum
power-dissipation. The voltage drop over the diode times the current
passing through the diode will give you the power dissipated. This value
should never exceed the value mentioned in the data-sheet. For small
zener diodes this value ranges from $200mW$ to $1.5W$.

## Photodiode Applications

As addressed earlier, diodes are very often used in power-supplies (to
conver the AC to DC). However, nowadays we use the USB-port for power,
or we just buy a power-adapter. There are other, more intriguing,
applications of diodes.

Quite a number of bio-chemical measurements make use of optical
interfaces or chemical reactions where light-intensity is an important
parameter. Some examples are:

- bio-photo luminescence
- optical quenching  
- photon counters

In these applications some form of (bio-)chemical reaction takes place.
Due to this reaction photons are generated, or blocked. When these photons are
detected the parameters of a (bio-)chemical reaction can be determined.

For this we could use a chemical interface which is luminescent. This
interface can be applied directly on the photo-diode, creating a very
compact device.

### Colorimeter

A good example is the colorimeter or spectrophotometer. These
instruments are used a lot in chemical labs in order to measure the
optical absorbance of a liquid. This absorbance very often relates to
the concentration of substances in the liquid.

The Lambert-Beer law can be used to determine the concentration of
specific constituents. For this very often a calibration-curve has to be
derived. The general principle is shown in {numref}`fig:light_cuvette`.
<!-- #endraw -->

```{figure} images/images_5/in_book/Transmittance-Diagram.svg
---
name: fig:light_cuvette
width: 800px
align: center
---
Transmission of light through a sample in a cuvette, as used in a photospectrometer. 
```

The transmittance ($T$) of the light is expressed as the ratio between the
incoming ($I$) and the outgoing light intensity ($I_0$).

$$T = \frac{I}{I_0}$$

The principle of these instruments is fairly simple: A light source (at
a specific wavelength) is used to illuminate the sample. The light which
passes through the sample is received on the other side and detected
with a photo-detector. The (old) principle is shown in {numref}`fig:photospectrometer`. Here a
light bulb (with a wide photospectrum) is used as a source, the
wavelength is selected with a prisma. The light is detected with a
photo-detector (here a photoresistor, a resistor which changes
resistance based on the light-intensity).

```{figure} images/images_5/in_book/Spetrophotometer-en.svg
---
name: fig:photospectrometer
width: 800px
align: center
---
Principle of a photospectrometer. <br>
Created by YassineMrabet, under CC-BY-SA, [original link](https://commons.wikimedia.org/wiki/File:Spetrophotometer-en.svg)
```

Nowadays, the light-source is replaced with a (multi)color-LED, which
can illuminate the sample with a fixed number of wavelengths. For the
measurement of the light-intensity a photo-diode is used.

### Pulse-oximeter

Other interesting applications are the pulse-oximeters. In these the
heart-rate and oxygen saturation of a person can be determined. These
devices are found a lot in hospitals, ambulances and are used a lot by
sportsmen. In {numref}`fig:pulse_oximeter` the principle of the sensor is shown. 
The light-intensity is converted to a voltage and recorded by for example a
micro-controller. This micro-controller calculates the heart-rate and
oxygen-saturation.

```{figure} images/images_5/in_book/Working-principle-of-the-Pulse-oximeter-SpO2-35.svg
---
name: fig:pulse_oximeter
width: 800px
align: center
---
Principle of the sensor of a pulse-oximeter. 
```

## Diode exercises

````` {exercise} Single diode in signal path
```{figure} images/images_5/in_book/sim-circuit4.svg
:name: exercise5_diode_signal
:width: 500px
The source generates a 1 Vp 1 kHz sine wave. 
```

```` {dropdown} 🖊️ Exercise: Single diode in signal path

Derive the $U_{out}$, for the above circuit, with 1 Vp 1 kHz sine as $U_{in}$.

```{admonition} Tips for the derivation
:class: tip dropdown
At which $U_{in}$ is the diode conducting?  
What is the voltage drop over the diode when it is conducting?
```

```{admonition} ✅ Answer
:class: dropdown, seealso

The diode only conducts when $U_{in}$ < -0.7 V. 

It then follows the sine with a voltage drop of 0.7 V. The value of $U_{out}$ therefore varies between 0 and -0.3 V. 

```
````
````` 

`````` {exercise} Single diode as load
```{figure} images/images_5/in_book/sim-circuit3.svg
:name: exercise5_diode_load
:width: 500px
diode as load
```
````` {dropdown} 🖊️ Exercise:  Single diode as load

Now the voltage source, resistor and diode are still in series, but $U_{out}$ is measured over the diode. 

Derive how the output signal $U_{out}$ will look like

```{admonition} Tips for the derivation
:class: tip dropdown
At which $U_{in}$ is the diode conducting?  
What is the voltage drop over the diode when it is conducting?
```

```{admonition} ✅ Start of solution
:class: dropdown, seealso

When the diode is conducting, $U_{out}$ will be equal to the voltage drop over the diode: 0.7 V.   
The diode is conducting for $U_{in}$ >0.7V.  
When the diode is not conducting, the circuit acts as a voltage with a resistor: $U_{out}$ is then equal to $U_{in}$. 
```
`````
``````

`````` {exercise} multi diode circuit
```{figure} images/images_5/in_book/sim-circuit2.svg
:name: exercise5_multi_diode_circuit
:width: 500px
A circuit with multiple diodes
```
````` {dropdown} 🖊️ Exercise: multi diode circuit


For the following circuit with multiple diodes, with forward voltage of 0.7V the following settings are given:
- $U_D$= 0.7 V
- R1= 1 k $\Omega$
- Freq=1kHz

Derive what will be:
- $I_{R1,max}$ when $U_S$ generates a 8 $V_{pp}$ sine wave.

```{admonition} Tip for $I_{R1,max}$ 
:class: tip dropdown

What is the peak voltage generated?  
Will the current through the resistor be higher when one or when two diodes are conducting?
```

```{admonition} ✅ numeric value $I_{R1,max}$ 
:class: dropdown, seealso

-3.3 mA
```

Derive what will be:
- the sketch of $U_{out}$ under the above conditions.

```{admonition} Tip for $U_{out}$ 
:class: tip dropdown

What is the min and max  $U_{out}$ ?
```

```{admonition} ✅ Description diagram
:class: dropdown, seealso

 $U_{out}$ follows  $U_{in}$ between -0.7 V and +1.4 V. Outside this region the  $U_{out}$ is clipped. 
```
```{admonition} Tip for frequency spectrum for 1 $V_{pp}$ or 10 $V_{pp}$
:class: tip dropdown

Think about whether clipping occurs for 1 $V_{pp}$?
```

Derive what will be:

- the sketch of the frequency spectrum of $U_{out}$ when the source creates a sine-wave of 1 $V_{pp}$
- the sketch of the frequency spectrum of $U_{out}$ when the source creates a sine-wave of 10 $V_{pp}$

````{admonition} ✅ frequency spectrum 
:class: dropdown, seealso

There will be no clipping for 1 $V_{pp}$, so the frequency spectrum has a single peak. 

For 10 $V_{pp}$, clipping will occur, and the output signal will start resembling a block wave. Then you will find higher odd harmonics in the frequency spectrum (with decrasing amplitude). Since the duty cycle is not 50% also even harmonics are present. So you'll see peaks at 1 kHz, 2 kHz, 3 kHz, etc. 
````
`````
``````

`````` {exercise} Zener circuit
```{figure} images/images_5/in_book/zener_diode_circuit.svg
:name: exercise5_zener_diode_circuit
:width: 500px
Zener diode circuit
```
````` {dropdown} 🖊️ Exercise: Zener circuit

For the following circuit with a Zener diode, with break-down voltage of -5.0V, and forward voltage of 0.6V, sketch the transfer function $\frac{U_{out}}{U_{in}}$. 

```{admonition} Tip to analyse a circuit with the Zener diode
:class: tip dropdown
How will the circuit behave without Zener?  
When will the Zener be not conducting?
```

```{admonition} Tip for circuit analysis with conducting Zener diode
:class: tip dropdown
When the Zener is conducting: how much voltage will be over the Zener, how much voltage will be over the second resistor?
```

```{admonition} ✅ Start of solution
:class: dropdown, seealso

When the zener diode is not conducting, $U_o$ = 0.5 $U_i$  

When $U_i$ <0 then $U_{ZD}$ = -0.6V   
When $U_i$ >0 then $U_{ZD}$ = +5V   
This means that the zener diode does not conduct between a $U_i$ of -0.6 V to +5.0 V
```

```{admonition} ✅ Description diagram
:class: dropdown, seealso

Between $U_i$ of -0.6 V to +5.0 V, $U_o$ = 0.5 $U_i$  
Outside this region, the zener diode has a fixed voltage drop, and all other voltage will be over the output resistor.  
Therefore, for $U_{diode}$ > 5.0V, then $U_o$=$U_i$-5.0V  
Therefore, for $U_{diode}$ <-0.6V, then $U_o$=$U_i$+0.6V  
```

````{admonition} ✅ Drawing of diagram
:class: dropdown, seealso

```{figure} images/images_5/in_book/zener_circuit_solution.jpg
:name: zener_circuit_solution
Clipper circuit with two voltage sources, one AC, one DC.
```
````
`````
``````

`````` {exercise} Advanced clipper
```{figure} images/images_5/in_book/sim-circuit5_clipper_advanced.svg
:name: exercise5_clipper_advanced
:width: 500px

```
````` {dropdown} 🖊️ Exercise: Clipper with two voltage sources

In the above circuit we have to sources, one 5V DC source, and $U_{in}$ of 8Vp, 1kHz.  
Derive the time-dependent signal of $U_{out}$.



```{admonition} Tip where to start
:class: tip dropdown
Like with all diode circuits: first derive when the diode is conducting or not. 
And then derive what will happen to $U_{out}$ for the conductive and non-conductive part of the sine period. 
```

```{admonition} ✅ Start of solution
:class: dropdown, seealso

If the diode does not conduct, $U_{out}$ is half of the 5V DC signal, so 2.5 V. 
```

```{admonition} ✅ When is the diode conducting
:class: dropdown, seealso

The diode conducts when the diode and anode have a 0.7 V difference. 

Therefore the diode conducts, for $U_{in}$ > 2.5V +0.7 V.  
In that case, $U_{out}$ follows $U_{in}$ with 0.7 V difference. 
```
`````
``````

````` {exercise} Half-wave rectifier 1
```{figure} images/images_5/in_book/half-wave-rectifier_plus_cap2.svg
:name: exercise5_rectifier_plus_capacitor
:width: 500px

The AC source supplies 15 $V_{rms}$  
The voltage over the diode, $V_d$  is 0.7 V  
The load resistance R is 100 $\Omega$

```
```` {dropdown} 🖊️ Exercise: Half-wave rectifier 1

For the above rectifier, derive how $U_{out}$ will look like (a voltage versus time graph)

```{admonition} Tip for diode circuits
:class: tip dropdown

When does the diode conduct?   
What happens to $U_{out}$ when the diode is conducting, and when it is not conducting?
```

```{admonition} Tip for diode circuits + capacitor
:class: tip dropdown

First derive the behavior for the circuit without capacitor.  
When taking the capacitor into account, check how the RC time relates to the period of the sine. 
```


```{admonition} ✅ Description signal
:class: dropdown, seealso

The diode conducts when $U_{in}$ <-0.7V.  
only then $U_{out}$ follows $U_{in}$ but with a 0.7 V drop over the diode. 

```
````
````` 

````` {exercise} Half-wave rectifier 2
```{figure} images/images_5/in_book/half-wave-rectifier_plus_cap.svg
:name: exercise5_rectifier_plus_capacitance
:width: 500px

The AC source supplies 15 $V_{rms}$, 50 Hz

The voltage over the diode, $V_d$  is 0.7 V
The load resistance R is 100 $\Omega$

```
```` {dropdown} 🖊️ Exercise: Half-wave rectifier 2

For the above rectifier with a requirement of <5% ripple, what would be the required minimal value for the capacitance? 

```{admonition} Tip for deriving peak value $U_{out}$
:class: tip dropdown

First step is to calculate the values in $V_{peak}$ from the $V_{rms}$.  
Second step is to calculate the voltage over the resistor and capacitor.
```

```{admonition} Tip for derivation of the capacitor value
:class: tip dropdown

You might want to use the formula $Q= C dU = I dt$. Which values do you already know, which ones to still derive?
```

```{admonition} ✅ Numeric answer Capacitor value
:class: dropdown, seealso

C= 4 mF

```
````
````` 

````` {exercise} Full-wave rectifier
```{figure} images/images_5/in_book/Full-Wave-Rectifier-Showing-Current-Flow.svg
---
name: fig:full_wave_rectifier
width: 800px
align: center
---
Full-wave rectifier, $U_{out}$ is measured over the load resistor. 
```

```` {dropdown} 🖊️ Exercise: Full-wave rectifier

For the above rectifier $U_{in}$ is 3Vp, 1kHz and the load resistance is 1 k$\Omega$.  
a) What is the frequency of $U_{out}$ (over the load resistor)?  


```{admonition} Tip for frequency of $U_{out}$?
:class: tip dropdown

Draw the input signal, and then draw the output signal.  Do they have the same frequency?
```

```{admonition} ✅ Frequency answer 
:class: dropdown, seealso

f=2 kHz

```
b) What are the minimum and maximum values of $U_{out}$?

```{admonition} Tip for derivation $U_{out}$ values
:class: tip dropdown

When will $U_{out}$ follow $U_{in}$?  
Will $U_{out}$ be equal to $U_{in}$?  
```

```{admonition} ✅ Numeric answer $U_{out}$ value
:class: dropdown, seealso

$U_{out}$ will vary between 0V and +1.6 V (=3-2*0.7V)

```
````
````` 

````` {exercise} Two diode circuits
```{figure} images/images_5/in_book/examQ_two_diode_circuits.svg
---
name: fig:two_diode_circuits
width: 800px
align: center
---
Two diode circuits 
```

```` {dropdown} 🖊️ Exercise: Two diode circuits

The above circuit consists of two voltage sources, a resistor and a diode.  
Two possible configurations are given below. The diode may be assumed to be ideal.  
Given the following specifications for the other components:  
R1: 2.0 kΩ  
U1: DC +3.0V  
U2: Pulse source, 50% duty cycle, $U_{high}$ = +8.0V, $U_{low}$ = -8.0V  
A) Make a sketch of the output-voltage ($U_{out}$) of both circuits.  
 

```{admonition} Tip for the output voltage
:class: tip dropdown

Deduct when $U_{out}$ follows U1 and when does it follow U2.  
When does the diode conduct or block?
```

```{admonition} ✅ answer A
:class: dropdown, seealso

Uout (Circuit A) follows U2 if U2>U1, otherwise it follows U1.  
So $U_{out}$ for circuit A varies between +3 and +8V.  
If the diode would have been non ideal, the output voltage would be maximally 7.3 V. 

Uout(circuit B) follow U2 if U2<U1.  So the minimum is -8 V, and the maximum $U_{out}$ is +3V. 

```
B) Calculate the maximum current through the diode for each circuit 

```{admonition} Tip for maximum current
:class: tip dropdown

For the max current through the diode, the diode must conduct or block?  
Would it help to know the maximum voltage over the resistor (and why)?
```

```{admonition} ✅ Answer B (max current)
:class: dropdown, seealso
Circuit A: $I_{max} = | \frac{u_{max}}{R_1} | $ = |-5V/2kΩ| = 2.5mA 
Circuit B: $I_{max}= | \frac{u_{max}}{R_1} |$ = 11V / 2kΩ = 5.5mA   


```
````
````` 

`````` {exercise} Circuit with two sources and one diode 
```{figure} images/images_5/in_book/examQ_one_diode_two_sources.svg
---
name: fig:examQ_one_diode_two_sources
width: 400px
align: center
---
Circuit with one diode, two sources and two resistors
```

````` {dropdown} 🖊️ Exercise: Circuit with one diode, two sources and two resistors

Given the following circuit:
- R1 = 1kΩ
- R2 = 1kΩ
- U1 = +5V (DC)
- U2 = Pulse-source
    - Period time = 10ms
    - For 5ms U2 = 2V
    - For 5ms U2 = 10V

A) You may assume the diode is ideal. 
- Make a sketch of the voltage Ua over time.
- Explain the way this circuit works.



```{admonition} Tip for the ideal case
:class: tip dropdown
When does the diode conduct?  
And what determines the output voltage if the diode does not conduct?

```

```{admonition} ✅ answer A
:class: dropdown, seealso

When the pulse of U2 is low, the output voltage is determined by the 5V source and the resistive divider. Both resistors are equal, so the 5V is divided by two, hence 2.5 V.  
When the pulse source is high, the diode starts to conduct. Now the 10 V source determines the output voltage. 

```

B) What will happen when the diode is not ideal?

```{admonition} Tip for non ideal diode
:class: tip dropdown

When will there be a voltage drop over the diode?
```



```{admonition} ✅ Answer B 
:class: dropdown, seealso

A non-ideal diode will have a forward voltage loss of 0.7 V. The maximum
voltage at Ua will now be 9.3 V

```
`````

resistor R2 is replaced by a capacitor. See the circuit below.

```{figure} images/images_5/in_book/examQ_one_diode_two_sources+cap.svg
---
name: fig:examQ_one_diode_two_sources+cap
width: 400px
align: center
---
Circuit with one diode, two sources and a resistor and capacitor
```

````` {dropdown} 🖊️ Exercise: Circuit with one diode, two sources and resistor+capacitor

In the previous circuit R2 is replaced by C1:
- R1 = 1kΩ
- C1 = 10 $\mu$F
- U1 = +5V (DC)
- U2 = Pulse-source
    - Period time = 10ms
    - For 5ms U2 = 2V
    - For 5ms U2 = 10V

C) Make a sketch of the output voltage Ua’ over time. Explain what is happening.  




```{admonition} Tip for the output voltage
:class: tip dropdown
On which parts of the signal from the previous exercise will the capacitor have an effect?  


```

````{admonition} ✅ answer C
:class: dropdown, seealso

Now there is a voltage divider. When the pulse source would not be there, the capacitor would be charged from 0 V to 5V through R1.  
With the pulse source present, the capacitor will be quickly charged till 10V.  
When the pulse source switches to its lower output, the capacitor wil discharge through R1 to 5V. 

```{figure} images/images_5/in_book/examQ_one_diode_two_sources+cap_answer.svg
---
name: fig:examQ_one_diode_two_sources+cap_answer
width: 400px
align: center
---
The output voltage of the circuit with one diode, two sources and a resistor and capacitor
```
````

D) What will happen when the value of the capacitor is changed (increased and/or
decreased), explain your answer.

```{admonition} Tip on effect bigger or smaller capacitance
:class: tip dropdown

Check the RC time and the period of the signal. 
```

```{admonition} ✅ Answer D (varying capacitor))
:class: dropdown, seealso

The RC time of C1 and R1 is 10 ms. The period time is also 10 ms (5ms high, 5 ms low).  
The capacitor will lose $e^{-0.5}$, a small amount of its charge in the 5 ms when $U_{pulse}$ is low. 

```
`````
`````` 

`````` {exercise} Clipper against negative voltages
```{figure} images/images_5/in_book/two_clippers.svg
---
name: fig:Clipper_against_negative_voltages
width: 800px
align: center
---
Clipper against negative voltages
```

````` {dropdown} 🖊️ Exercise: Clipper against negative voltages
Uin is the voltage coming from a reaction chamber, and Uout goes to a computer interface, which needs to be protected against negative voltages. In order to protect the computer interface a clipper is placed between Uin and the input of the computer interface.  
Furthermore, the output should be limited as well (too high voltage will damage the input of the interface!). 

Two configurations (A and B, above figure) were designed.

a) In order to test the clippers, Uin is set to a triangle-wave of 100 Hz, with a 30 Vpp amplitude (symmetrical around 0 V).  
The forward voltage drop over the diodes is 0.6V.  
Ulimit = 10V.  
Make a precise sketch of the output voltage of each circuit when the triangle-wave is applied. 

```{admonition} Tip for where to start
:class: tip dropdown
When does the diode(s) conduct or block?
```

```{admonition} ✅ answer for Uout for circuit A
:class: dropdown, seealso

Uout will always be 0.6V lower than the input signal. Uout is clipped at Ulimit+0.6 V, and 0V.  
The 0 V occurs when both diodes are not conducting (through the 10 M $\Omega$ to ground)
.
```
```{admonition} ✅ answer for Uout for circuit B
:class: dropdown, seealso

Unlike circuit A there is no diode in the signal line, so Uout = Uin untill it clips at Ulimit+0.6V. 
The minimal value for Uout is -0.7V, then the bottom diode is starts conducting. 

```
````{admonition} ✅ graphical answer for Uout for circuits A & B
:class: dropdown, seealso
```{figure} images/images_5/in_book/two_clippers_answer.svg
---
name: fig:two_clippers_answer
width: 800px
align: center
---
Clipper against negative voltages: output voltages
```
````


b) Calculate the value of R1a and R1b, when the maximum current (for the 30Vpp triangle-wave) at Uin is 1mA

```{admonition} Tip for maximum current
:class: tip dropdown

The maximum current occurs for the maximum voltage drop over the resistor. What is the max voltage drop over the resistor for both circuits?
```

```{admonition} ✅ Answer for the max current circuit A
:class: dropdown, seealso

For circuit A this occurs at the positive peak. During the negative peak the diode blocks, so no current goes through the resistor.  
The current through the 10 M$\Omega$ can be neglected (this is about 1uA, the most).  
The voltage drop over the resistor will be: Uin – (Ulimit + 2 * Ud) = 15 -11,2 = 3.8V
R1a = U / I = 3,8 / 1mA = 3.8 k$\Omega$ 

```

```{admonition} ✅ Answer for the max current circuit B
:class: dropdown, seealso

For circuit B this occurs during the negative peak. The input is -15V, the lower diode will
conduct and has a voltage drop of 0.6V. Voltage drop over R = 15 – 0.6 = 14.4V, so R1b = 14.4 k$\Omega$ 


```
`````
`````` 

`````` {exercise} Complexer diode circuit
```{figure} images/images_5/in_book/examQ_diode_3R.svg
---
name: fig:examQ_diode_3R
width: 350px
align: center
---
Circuit with two sources, 3 resistors and two diodes. 
R1 = 50 Ω, R2 = 150 Ω, R3 = 50 Ω
```

````` {dropdown} 🖊️ Exercise: Complexer diode circuit
Have a look at the above diagram. This diagram belongs to a complex wave generator.  
- U1: Triangle wave, period time = 1s, amplitude = 20Vpp, symmetrical around zero
- U2: Square wave, period time = 1s, amplitude = 20Vpp, duty cycle 50%, symmetrical around zero  
Both waveforms start at t=0s with a positive period.

a.) Sketch the output voltage, you may assume the diodes are ideal.


```{admonition} Tip for working with diodes in a circuit
:class: tip dropdown
When does the diode(s) conduct or block?
```

```{admonition} ✅ answer for Uout 
:class: dropdown, seealso

When diode D1 conducts, the voltage U1 is split between R1 and R3.   
When diode D2 conducts, the voltage U2 is split between R2 and R3. 
```

````{admonition} ✅ graphical answer for Uout 
:class: dropdown, seealso
```{figure} images/images_5/in_book/examQ_diode_3R_answerA.svg
---
name: fig:examQ_diode_3R_answerA
width: 500px
align: center
---
Uout follows partially the triangular wave, partially the square wave.
```
````

b.) What will happen when we take the forward voltage drop of the diode (0.7V) into account?  
Draw Uout as accurate as possible, combined with U1 and U2 (draw U1 and U2 as dotted lines) in one
figure.

```{admonition} ✅ answer for Uout for non ideal diodes
:class: dropdown, seealso

The voltage drop of 0.7V is effectively split between two resistors.  
Therefore the max (triangular part of the) voltage out will be + 4.65 V.
Since the resistors R2 and R3 are not equal, the minimum (squared wave part of the) voltage becomes -2.15 V. 
```

````{admonition} ✅ graphical answer for Uout with non ideal diodes
:class: dropdown, seealso
```{figure} images/images_5/in_book/examQ_diode_3R_answerB.svg
---
name: fig:examQ_diode_3R_answerB
width: 500px
align: center
---
Uout follows partially the triangular wave, partially the square wave. But the voltage drop over the diode gets divided by the two resistors. 
```
````

`````
`````` 


`````` {exercise} Complexer diode circuit 2
```{figure} images/images_5/in_book/diode_circuit2.svg
---
name: fig:diode_circuit2
width: 500px
align: center
---
Complexer circuit with two sources, two diodes, and a resistor  
The diodes maybe assumed to be ideal. R1 = 1 kOhm.  
U1 = 10 sin (2*pi*250*t) and U1 = -U2
```

````` {dropdown} 🖊️ Exercise: Complexer diode circuit 2
A circuit with two diodes and two sources is made, see the circuit above.



a.) Draw Uo, you may assume the diodes are ideal.


```{admonition} Tip for working with diodes in a circuit
:class: tip dropdown
When does the diode(s) conduct or block?
```

```{admonition} ✅ answer for Uout 
:class: dropdown, seealso
Uo will be a rectified (absolute value) sinewave. Going from 0....10Vpeak, remember diodes are ideal, so no voltage loss.
```

b.) What is the frequency of Uo?
```{admonition} Tip for working with diodes in a circuit
:class: tip dropdown
Look at the signal, when does it repeat itself?
```
```{admonition} ✅ answer for frequency
:class: dropdown, seealso
U1 and U2 are in counterphase. The frequency of U1 is 250Hz. While U2 is in counterphase, the
frequency of the output signal will be double the frequency, thus 500Hz
```
c.) What is the RMS output voltage?
```{admonition} Tip for rms voltage
:class: tip dropdown
it involves a bit of scaling. 
```
```{admonition} ✅ answer for frequency
:class: dropdown, seealso
The output voltage will be the absolute value of the sinewave. Thus Urms = Upk / SQRT(2) = 7.1V
```

A zener diode is used to stabilise a voltage. Given the circuit below.

```{figure} images/images_5/in_book/diode_circuit2zener.svg
---
name: fig:diode_circuit2zener
width: 500px
align: center
---
Zener diode stabilizing circuit.  
U1 = 20V, R1 = 20 Ohm, R2 = 48 Ohm, D1 = 12V zener

```

d.) What is the power dissipation in the zener?
```{admonition} Tip for rms voltage
:class: tip dropdown
How do power, current and voltage relate? 
```
```{admonition} ✅ answer for frequency
:class: dropdown, seealso
P = U x I → I(R2) = U/R = 12 / 48 = 0.25 A  
I(R1) = (U1 – Uzd)/R1 = (20 -12)/20 = 8 / 20 = 0.4A  
Izd = I(R1) – I(R2) = 0.4 – 0.25 = 0.15A → Pzd = U * I = 12 * 0.15 = 1.8W
```
`````` 