Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Ionization Chamber

An ionization chamber is a device used to measure radioactivity levels. When air atoms are hit by radioactive particles, an ion pair is produced. Ions have an electric charge, and if they are in an electric field created by positive and negative electrodes, negative ions will move toward the positive electrode, and positive ions will move toward the negative electrode. They will attempt to "meet each other," thereby creating a current. This current can be measured and is proportional to the number of ion pairs. The number of ion pairs is proportional to the radioactivity level.

The architecture of the device is presented below. It consists of an analog part and an STM8 microcontroller, which collects and sends measurements via UART. These measurements are collected on the Raspberry Pi side and processed using Python and R scripts. The results are stored as .csv files (raw data) or .png files (diagrams). While it would be possible to simplify this setup and eliminate the Raspberry Pi, I wanted to enable data collection and flashing of the microcontroller remotely, without needing to be physically near the device.

The outer electrode of the ionization chamber was made from PCB scraps and a copper plate, while the inner electrode was constructed using a few centimeters of non-enameled wire. To avoid electromagnetic interference, the amplifier was placed inside a metal chassis.

High voltage is required to create a sufficient electric field in the chamber. Initially, I was unsure of the exact voltage needed, so I added a simple DC/DC converter to the PCB to generate 400V DC. However, tests showed that 4x12V from batteries is sufficient. As a result, while the DC/DC converter is soldered onto the board (visible on the bottom left side of the picture), it is not in use.

The software was written in C and compiled using SDCC. A strange limitation of SDCC is that even if functions are unused, they are still compiled and included in the final binary. Since I am using StdPeriph as a HAL, there were many unused functions that occupied space. To work around this, I added #ifdef 0 ... #endif around each unused function, then attempted to compile and uncommented the functions that were actually needed.

The diagram below shows the results obtained from the device. As can be seen, the device is quite sensitive, capturing even small variations in the measurements.

For more details on the project, feel free to check out the full source code and documentation on GitHub. You can also follow the project's development and updates on Hackaday.

Camera nuclear-radiation sensor: part I

In previous posts I've described a radioactivity detector based on a photodiodes. Image sensors in cameras use photoelements too, so I think that they could be also used to detect radioactivity. At this moment i didn't success in this , nevertheless I will describe here my attempts.

I'm using RaspbberyPI, to get data from the sensor, camera is some low-budget/quality clone designed for RaspberryPI. I have removed optics, and covered whole camera in black tape to block any light coming to the sensor. It's visible on the picture below.

To handle the camera on the software side, I'm using Python script (with PiCamera library). In infinitive loop it takes a photo and calculate sum of pixels value and then sums values of each RGB channel. This value with timestamp is put to CSV file that is later parsed to diagrams using R script.

Without any sample, internal noise of the sensor (and maybe background radiation) should give after some time (e.g. after a couple of hours) a Gaussian curve on the histogram. After putting measured sample to the sensor and waiting similar period, a new Gaussian curve would appear, so that the histogram would have to visible peaks. That was my assumption, hit would prove that the sensor works, however as visible below it doesn't - there is only one peek.

I will try to better isolate the sensor also from electromagnetic noise or maybe buy a new camera (less noisy). Other than that I don't have ideas to make it works.

Semiconductor nuclear-radiation sensor: part III

In this post I will present a new hardware version of my sensor, older versions are described in part I and part II. In comparison to the previous one, sensitivity is roughly x10 more sensitive.

In previous version, tin foil window for photodiodes was very close to the BNC sockets and because enclosure was small, it was hard to place a sample close enough. Not it's better, however, if I would choosing again, I would use metal enclosure similar to those used in PC oscilloscopes and put BNCs on front panel, power socket on rear panel and tin foil window on top. This would allow me to easier access for debugging- now I have to desolder sockets to get to photodiodes or to bottom side of PCB (fortunately this side is empty).

Bellow you can see the diagram (click on it to enlarge), what has changed in comparison to previous version:

  • One additional photodiode (previous version has only two of them) to increase sensitivity, also the window in enclosure is much bigger
  • x10 bigger resistance of the feedback loop resistor in first stage amplifier, I tried bigger, but then osculations started
  • Bias for photodiodes using 12V batteries, I could increase it, but didn't have enough space in this enclosure
  • Buffer op-amp at the analog output
  • Digital output.

Additional changes not shown on diagram:

  • U1 is OPA657U
  • U2 is OPA656U
  • R4 is 1G
  • As close as possible to input power socket are placed in paraller 1n/16V and 100n/16V, without them the device started to oscillate randomly.
  • A Schottky diode is connected in series after mentioned above extra capacitors to reduce risk of damaging the device when power supply is connected incorrectly. I don't know if it will help enough but I have already broke one PCB of this device this way, so now it's there.

Digital output is 12V in high state, 0V in low state, this is not very useful for 3V3 logic microcontroller that I'm using for data acquisition, so I made a simple converter using additional PCB.

Here it is visible soldered. I like in those SMA Female sockets that they can be soldered to the edge of the PCB (as visible below) and this is still quite mechanically stable, but doesn't require to drill holes as in regular mounting way.

All materials (including software part presented in previous post) for this hardware revision can be downloaded from project's repository.

Semiconductor nuclear-radiation sensor: part II

There are many ways to measure radioactivity level, semiconductor detectors sense interactions between ionizing radiation and p-n junction. Because in hobbyist area most popular are Geiger-Muller based detectors (in short: not a semiconductor but lamp based devices), I think it's a cool idea to take a look at this approach.

In this post I will present such home-made sensor and a set of software to parse collected results.

Picture below presents circuit of the sensor that I made, it consist of a photodiode that acts as a sensor, transimpedance amplifier and "regular" amplifier. I've selected op-amps that has little input noise.

Changes that I made during testing the device, that are not presented on the diagram:

  • D1 is BPW34
  • U1 is OPA657U
  • U2 is OPA656U
  • 2p capacitor is connected in parallel with R6
  • 820k resistor is connected between U2 out and BNC socket.

Below is visible sensor in enclosure and without it. Because the device is sensitive for background EMI and light noise, a metal housing is needed. To increase exposure of the sensor to the radiation, where it is, in the housing, a hole is made and just a tiny adhesive metal tape is covering it.

Collecting data from measurements devices using USBTMC, SCPI, Python and R

High end test gear allows two-way communication with PC to set measurement parameters and to send the measured data to PC for further analyze. On PC side there are applications for this (LabView, BenchVue), but they are expensive. One option is to make own program/script that will communicate with the device and parse/present measured data - this approach I will present it in this post. The tool I'm using it with is 34460A(digital multimeter).

Below is an example of the measurement graph made using this home-made software.

The module of communication with the device I made in Python, it stores data to .csv file, that is later parsed by a script in R and the output graph is stored as .png image. The R part could ass well do some numeric stuff and print it on STDOUT, but for me that was not the case.

Initially all was in Python, but I didn't like Python's graphs, they weren't visually nice.

Python part when started will save measurements to the .csv file constantly, at any time, user can run R script to create new graph.

Installation steps

Assuming device driver correctly enumerate in the Device Manager (if not one needs to install its drivers first).

  • Install Python and R, add them to Path (environment variable).
  • In R, install following packages: latticeExtra, gridExtra, grid.
  • In Python install following packages: usbtmc, pyusb.
  • On Windows, download libusb-win32 and follow README steps to bind it to the device. In addition it didn't work for me if I didn't run the tool as an Administrator. If everything went ok, device will be visible in Device Manager in branch named libusb-win32 devices.
  • Download Python/R scripts, they are available via my IonizationChamber repository.
  • In main.py, replace idDMM with id of the device.

For usbtmc, I got the same problem as described here, fortunately the fix presented in that thread fixed it, so please check it if you have some weird stacktrace errors in Python.

Usage

I made those scripts for my personal use, so they may be a bit awkward to work with, but once the setup is done, everything should work fine.

  • Set meassurement type and range on your device (this could be also done via python script)
  • Start python script
  • Run R script, it will create results.png file with graphs.

That's all.

German tank problem

Sometimes science is applied in really amazing ways, one of examples is German tank problem. During World War II, the Allies observed that the Nazis created a new model of tank. Total number of manufactured units was unknown, but the Allies, know serial numbers of some tanks. In this case, the first produced tank has serial number starts = 1, the second has serial number = 2, etc. How the Allies could estimate total amount of manufactured tanks?

Answer may be estimated by using simple equitation. Let's assume that N = estimated total amount of enemy tanks, k = amount of observed tanks, m = maximum observed serial number. Then:

N = m - 1 + m/k

Example

We observed enemy tanks with serial numbers: 20, 23, 45, 47, 48. In this case, m=48, k=4, answer can be computed on calculator or for example in R language (I really like to use it as a powerful "calculator"):

> 48 - 1 + 48/4
[1] 59

Other use cases

The same as used for German tank problem was used to estimate amount of sold Apple's products. The customers were asked to upload their serial numbers.

Zipf's law and natural languages

If we count the appearance of words in a sample of (most) human languages, it's visible that they have the Zipf's distribution. It can be used to distinguish human languages (and humans) from texts generated randomly (by spambots). This is presented on below histogram:

Zipf's law in natural languages

Below I will present tools that I made to verify this, first of them is a C++ program used to parse a text and generate a distribution of words that he encountered, second is a R script used to generate diagram from mentioned distribution.

How does recursive packing of a file changes its size?

How the size of a packed file will change if you will pack it again? How will it change if you do that again and again? Will it be the same, bigger of smaller? I checked this with popular kinds of files and below I will show the results. I used Bash script and R language to check this. Charts shows how the file size changes in each iteration, first bar is the size of original, unpacked file.