top of page

Last edited: 17-02-2025

ELECTRO-MAGNET DESIGN TOOL

A useful MATLAB script for designing electromagnets

Whilst most of the projects on my page are centered around analog and discrete circuit design, building a physical simulation-tool might not be achievable for many in a short timeframe. The MATLAB script listed on this page started out as a rough draft for designing coreless deflection coils for CRTs, later adapted and improved during my bachelor studies to be used for my final paper about the design of coil matrices for low-field portable MRI machines, and will later be optimized for any arbitrary coil structure, from  modeling complicated deflection coils to dynamic magnetic field stabilization and beyond. The code was optimized such that accurate models of real coils can be generated and can be run on versatile software (MATLAB), without using expansion packs to keep cost low, which can be ran on older laptops with outdated software without issues. This was done through approximating coils by linesegments, careful optimization of the mathematics, and the use of a generational algorithm to calculate the needed driving currents with hard boundaries to approach a desired magnetic field to be generated with the coils. 

 

As for now, this page will remain a draft with all the code and its backlog kept open to the public. This was used in an academic setting, and whilst I wholeheartedly like to believe only good contributions will be made by future researchers continuing in the line of work, I also want to protect my work from either being claimed as intellectual property by future students contiuing the line of research, for my paper to dissapear into a forest of irrelevant research aimed mostly towards filling wallets with tax money, or for the knowledge to end up behind a paywall of an online library.

​

Because like c'mon, I had to pay tuition to be allowed to do research for half a year. My results were submitted as an abstract to the ISMRM conference of 2025 for me to be old other people have to present my work since I didn't have a high enough title to allocate money to send me over there. What a waste of time in the end. My code is useful to me for my radar display project, but I hope it can be used by others to help with their fun endeavours. 

What does the code exactly do?

You give a set of arrays (in the form of a matrix) with coordinates which represent the wire, as linesegments, of a set of existing coils. The code will calculate the magetic field contribution of every coil in a field of coordinates (also an array with x, y, and z cartesian coordinates) for a normalized current (1 A). When giving a constant present measured magnetic field (in x, y, and z directions) plus the desired field (also in any direction), it will unleash a generational algorithm to effectively calculate what currents you have to put into your coil system to generate that desired field. 

​

So, when designing, say, the yoke for a CRT, it won't optimize the coil geometry for you to get your desired magnetic field. Say, just for horizontal deflection, where a traditional yoke would use a symmetric set of coils on either side of the neck, you must build two or more sets with slightly different geometries, the software will tell you in what ratio these coils can be combined to approximate the appropriate geometry for your deflection coil. It will utilize a ratio of currents between the coils to elecrically model the desired geometry. Electrically it is more complicated and a bit less efficient, making a horrible system for mass production, this way of modeling has great benefits being highly versatile in one-off production, prototyping and other research purposes. 

Papers (documentation purposes, you can skip this)

Everything above sounds super abstract. I'm stuck here in quite an academic teaching style, but worry not. All the way down the page, I'll eventually show you an implementation of the usecase of the software. I'll firstly happily present you with the material I wrote during my research. My final paper was heavily constrained with a page-limit, I rather would've gone into useful detail, but to get a high grade I had to cut most of the interesting stuff out in order to appear to the rubrics. Sadly, I can't find the files anymore with proper elaboration, I hope everything will be clear, these will be rewritten. The abstract listed here was the first draft, since in the final submission, extra critical information was added by a colleague which I don't want to take claim of. Interestingly enough, this should've been already published I think, despite I was first author, it was submitted to the conference with me being a co-author so I do not have access to the final version. I wasn't sent the final version before submission and some random name appeared of someone else. A cheap way improving your h-index I suppose, good example why we learn nowadays this metric is completely useless to prove credibility of an author.

​​​​​​

Abstract

Final paper​​

Code backlog (documentation purposes, you can skip this)

Before the final version written, to drive home the origins of the code, here's a set of files of early drafts. Probably useless to many, but I want to keep it around for documentation purposes mostly. I was conservative sharing this code. The data generated for the "constant field disturbance" is the work of my colleauge. Here's the full picture:

 

These redirect you off the site to my Google drive btw!

Demo code

Legacy code

​​​

Code download link 

The final version of the code can be found clicking on the following link:

​

This one as well!

Code V1.0

​

bottom of page