mirror of
https://github.com/nqrduck/nqr-blochsimulator.git
synced 2024-06-27 07:49:07 +00:00
Added unit conversion and q factors for calculations.
This commit is contained in:
parent
61b1072c61
commit
90c9ed444e
|
@ -23,6 +23,8 @@ class Simulation:
|
||||||
length_coil: float,
|
length_coil: float,
|
||||||
diameter_coil: float,
|
diameter_coil: float,
|
||||||
number_turns: float,
|
number_turns: float,
|
||||||
|
q_factor_transmitt:float,
|
||||||
|
q_factor_receive:float,
|
||||||
power_amplifier_power: float,
|
power_amplifier_power: float,
|
||||||
pulse: PulseArray,
|
pulse: PulseArray,
|
||||||
averages: int,
|
averages: int,
|
||||||
|
@ -30,6 +32,7 @@ class Simulation:
|
||||||
temperature: float,
|
temperature: float,
|
||||||
loss_TX: float = 0,
|
loss_TX: float = 0,
|
||||||
loss_RX: float = 0,
|
loss_RX: float = 0,
|
||||||
|
conversion_factor: float = 1,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Constructs all the necessary attributes for the simulation object.
|
Constructs all the necessary attributes for the simulation object.
|
||||||
|
@ -52,6 +55,10 @@ class Simulation:
|
||||||
The diameter of the coil in meters.
|
The diameter of the coil in meters.
|
||||||
number_turns : float
|
number_turns : float
|
||||||
The number of turns of the coil.
|
The number of turns of the coil.
|
||||||
|
q_factor_transmitt : float
|
||||||
|
The Q-factor of the transmitt path of the probe coil.
|
||||||
|
q_factor_receive : float
|
||||||
|
The Q-factor of the receive path of the probe coil.
|
||||||
power_amplifier_power : float
|
power_amplifier_power : float
|
||||||
The power of the power amplifier in Watts.
|
The power of the power amplifier in Watts.
|
||||||
pulse: PulseArray
|
pulse: PulseArray
|
||||||
|
@ -66,6 +73,8 @@ class Simulation:
|
||||||
The loss of the transmitter in dB.
|
The loss of the transmitter in dB.
|
||||||
loss_RX:
|
loss_RX:
|
||||||
The loss of the receiver in dB.
|
The loss of the receiver in dB.
|
||||||
|
conversion_factor:
|
||||||
|
The conversion factor of the receiver in spectromter units / Volt.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.sample = sample
|
self.sample = sample
|
||||||
|
@ -76,6 +85,8 @@ class Simulation:
|
||||||
self.length_coil = length_coil
|
self.length_coil = length_coil
|
||||||
self.diameter_coil = diameter_coil
|
self.diameter_coil = diameter_coil
|
||||||
self.number_turns = number_turns
|
self.number_turns = number_turns
|
||||||
|
self.q_factor_transmitt = q_factor_transmitt
|
||||||
|
self.q_factor_receive = q_factor_receive
|
||||||
self.power_amplifier_power = power_amplifier_power
|
self.power_amplifier_power = power_amplifier_power
|
||||||
self.pulse = pulse
|
self.pulse = pulse
|
||||||
self.averages = averages
|
self.averages = averages
|
||||||
|
@ -83,6 +94,7 @@ class Simulation:
|
||||||
self.temperature = temperature
|
self.temperature = temperature
|
||||||
self.loss_TX = loss_TX
|
self.loss_TX = loss_TX
|
||||||
self.loss_RX = loss_RX
|
self.loss_RX = loss_RX
|
||||||
|
self.conversion_factor = conversion_factor
|
||||||
|
|
||||||
def simulate(self):
|
def simulate(self):
|
||||||
reference_voltage = self.calculate_reference_voltage()
|
reference_voltage = self.calculate_reference_voltage()
|
||||||
|
@ -90,6 +102,7 @@ class Simulation:
|
||||||
B1 = (
|
B1 = (
|
||||||
self.calc_B1() * 1e3
|
self.calc_B1() * 1e3
|
||||||
) # I think this is multiplied by 1e3 because everything is in mT
|
) # I think this is multiplied by 1e3 because everything is in mT
|
||||||
|
print(B1)
|
||||||
# B1 = 17.3 # Something might be wrong with the calculation of the B1 field. This has to be checked.
|
# B1 = 17.3 # Something might be wrong with the calculation of the B1 field. This has to be checked.
|
||||||
self.sample.gamma = self.sample.gamma * 1e-6 # We need our gamma in MHz / T
|
self.sample.gamma = self.sample.gamma * 1e-6 # We need our gamma in MHz / T
|
||||||
self.sample.T1 = self.sample.T1 * 1e3 # We need our T1 in ms
|
self.sample.T1 = self.sample.T1 * 1e3 # We need our T1 in ms
|
||||||
|
@ -123,7 +136,7 @@ class Simulation:
|
||||||
Mtrans_avg = np.delete(Mtrans_avg, -1) # Remove the last element
|
Mtrans_avg = np.delete(Mtrans_avg, -1) # Remove the last element
|
||||||
|
|
||||||
# Scale the signal according to the reference voltage, averages and gain
|
# Scale the signal according to the reference voltage, averages and gain
|
||||||
timedomain_signal = Mtrans_avg * reference_voltage * 1e6
|
timedomain_signal = Mtrans_avg * reference_voltage * self.conversion_factor
|
||||||
|
|
||||||
# Add the losses of the receiver - this should probably be done before the scaling
|
# Add the losses of the receiver - this should probably be done before the scaling
|
||||||
timedomain_signal = timedomain_signal * (1 - 10 ** (-self.loss_RX / 20))
|
timedomain_signal = timedomain_signal * (1 - 10 ** (-self.loss_RX / 20))
|
||||||
|
@ -244,6 +257,7 @@ class Simulation:
|
||||||
B1 = (
|
B1 = (
|
||||||
np.sqrt(2 * self.power_amplifier_power / 50)
|
np.sqrt(2 * self.power_amplifier_power / 50)
|
||||||
* np.pi
|
* np.pi
|
||||||
|
* np.sqrt(self.q_factor_transmitt)
|
||||||
* 4e-7
|
* 4e-7
|
||||||
* self.number_turns
|
* self.number_turns
|
||||||
/ self.length_coil
|
/ self.length_coil
|
||||||
|
@ -313,6 +327,11 @@ class Simulation:
|
||||||
reference_voltage = (
|
reference_voltage = (
|
||||||
reference_voltage * self.sample.powder_factor * self.sample.filling_factor
|
reference_voltage * self.sample.powder_factor * self.sample.filling_factor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# This is assumes thatour noise is dominated by everything after the resonator - this is not true for low Q probe coils
|
||||||
|
reference_voltage = reference_voltage * np.sqrt(self.q_factor_receive)
|
||||||
|
|
||||||
return reference_voltage
|
return reference_voltage
|
||||||
|
|
||||||
def calculate_noise(self, timedomain_signal: np.array) -> np.array:
|
def calculate_noise(self, timedomain_signal: np.array) -> np.array:
|
||||||
|
@ -406,6 +425,24 @@ class Simulation:
|
||||||
def number_turns(self, number_turns):
|
def number_turns(self, number_turns):
|
||||||
self._number_turns = number_turns
|
self._number_turns = number_turns
|
||||||
|
|
||||||
|
@property
|
||||||
|
def q_factor_transmitt(self) -> float:
|
||||||
|
"""Q-factor of the transmitt path of the probe coil."""
|
||||||
|
return self._q_factor_transmitt
|
||||||
|
|
||||||
|
@q_factor_transmitt.setter
|
||||||
|
def q_factor_transmitt(self, q_factor_transmitt):
|
||||||
|
self._q_factor_transmitt = q_factor_transmitt
|
||||||
|
|
||||||
|
@property
|
||||||
|
def q_factor_receive(self) -> float:
|
||||||
|
"""Q-factor of the receive path of the probe coil."""
|
||||||
|
return self._q_factor_receive
|
||||||
|
|
||||||
|
@q_factor_receive.setter
|
||||||
|
def q_factor_receive(self, q_factor_receive):
|
||||||
|
self._q_factor_receive = q_factor_receive
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def power_amplifier_power(self) -> float:
|
def power_amplifier_power(self) -> float:
|
||||||
"""Power of the power amplifier in Watts."""
|
"""Power of the power amplifier in Watts."""
|
||||||
|
|
|
@ -44,10 +44,12 @@ class TestSimulation(unittest.TestCase):
|
||||||
number_isochromats=1000,
|
number_isochromats=1000,
|
||||||
initial_magnetization=1,
|
initial_magnetization=1,
|
||||||
gradient=1,
|
gradient=1,
|
||||||
noise=2456.3,
|
noise=2,
|
||||||
length_coil=6e-3,
|
length_coil=6e-3,
|
||||||
diameter_coil=3e-3,
|
diameter_coil=3e-3,
|
||||||
number_turns=9,
|
number_turns=9,
|
||||||
|
q_factor_transmitt=100,
|
||||||
|
q_factor_receive=100,
|
||||||
power_amplifier_power=500,
|
power_amplifier_power=500,
|
||||||
pulse=self.pulse,
|
pulse=self.pulse,
|
||||||
averages=1,
|
averages=1,
|
||||||
|
@ -55,6 +57,7 @@ class TestSimulation(unittest.TestCase):
|
||||||
temperature=77,
|
temperature=77,
|
||||||
loss_TX=12,
|
loss_TX=12,
|
||||||
loss_RX=12,
|
loss_RX=12,
|
||||||
|
conversion_factor=1622137.746 # This is for the LimeSDR based spectrometer
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_simulation(self):
|
def test_simulation(self):
|
||||||
|
|
Loading…
Reference in a new issue