<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Zurich Instruments Blogs</title>
	<atom:link href="http://www.zhinst.com/blogs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zhinst.com/blogs</link>
	<description></description>
	<lastBuildDate>Tue, 17 Apr 2012 06:30:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Connecting the Nanosurf Manual Controller to a Zurich Instruments HF2LI or HF2PLL</title>
		<link>http://www.zhinst.com/blogs/andreas/connecting-nanosurf-manual-controller-to-zurich-instruments-hf2li-pll/</link>
		<comments>http://www.zhinst.com/blogs/andreas/connecting-nanosurf-manual-controller-to-zurich-instruments-hf2li-pll/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 07:39:15 +0000</pubDate>
		<dc:creator>andreas</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[AFM]]></category>
		<category><![CDATA[EasyPLL]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[HF2PLL]]></category>
		<category><![CDATA[Manual Controller]]></category>
		<category><![CDATA[NC-AFM]]></category>
		<category><![CDATA[PLL]]></category>

		<guid isPermaLink="false">http://6.6</guid>
		<description><![CDATA[In March 2011, Nanosurf and Zurich Instruments announced a cooperation to establish the HF2PLL as official upgrade path for Nanosurf&#8217;s EasyPLL. This post shows how to connect Nanosurf&#8217;s Manual Controller to the Zurich Instruments HF2PLL. The Manual Controller combined with [...]]]></description>
			<content:encoded><![CDATA[<p>In March 2011, Nanosurf and Zurich Instruments announced a cooperation to establish the HF2PLL as official upgrade path for Nanosurf&#8217;s EasyPLL. This post shows how to connect Nanosurf&#8217;s Manual Controller to the Zurich Instruments HF2PLL.</p>
<p>The Manual Controller combined with the HF2LI allows for adding offset voltages to the dF signal (frequency deviation) of the Phase Locked Loop. In this way, it allows for manually setting the frequency setpoint using the fine feeling of your fingertips. It can also be used to control other parameters of an AFM setup.</p>
<p>The list of controllable parameters includes:</p>
<ul>
<li>Frequency deviation (dF)</li>
<li>Drive amplitude</li>
<li>Frequency</li>
<li>Arbitrary voltage on any Aux Output</li>
</ul>
<p>&nbsp;</p>
<table>
<tbody>
<tr>
<td><a href="http://www.zhinst.com/blogs/andreas/files/2012/03/manualcontroller.jpg"><img class="alignleft size-full wp-image-79" src="http://www.zhinst.com/blogs/andreas/files/2012/03/manualcontroller.jpg" alt="" width="200" height="170" /></a></td>
</tr>
<tr>
<td><em>Nanosurf Manual Controller box.</em></td>
</tr>
</tbody>
</table>
<h2>Requirements</h2>
<ul>
<li>Zurich Instruments <a href="http://www.zhinst.com/products/hf2pll">HF2PLL</a></li>
<li>Zurich Instruments <a href="http://www.zhinst.com/products/hf2li/hf2li-pid">HF2LI-PID Option</a></li>
<li>Nanosurf Manual Controller</li>
</ul>
<h2>Setup Overview</h2>
<p>The AFM system which was set up by the Molecular Self-Assembly Research Group of Professor Kühnle, University of Mainz, allows for manually controlling the frequency setpoint of the phase locked-loop in order to optimize the image quality of an NC-AFM scan.<br />
To connect the Manual Controller to the Zurich Instruments lock-in amplifier, an adapter to the Lemo connector has to be built according to the information you find in &#8220;Building Instruction&#8221; below.</p>
<table>
<tbody>
<tr>
<td><a href="http://www.zhinst.com/blogs/andreas/files/2012/04/afm_setup_2.png"><img class="alignleft size-full wp-image-85" src="http://www.zhinst.com/blogs/andreas/files/2012/04/afm_setup_2.png" alt="" width="600" /></a></td>
</tr>
<tr>
<td><em>Block diagram of the AFM system incorporating an HF2LI lock-in amplifier from Zurich Instruments and a Manual Controller box from Nanosurf.</em></td>
</tr>
</tbody>
</table>
<h2>Building Instructions</h2>
<p>The ZCtrl port of the HF2LI has to provide the power supply (±12V) for the Manual Controller. Furthermore, the Aux Input of the HF2LI has to read the returned analog offset voltage from the Manual Controller. Therefore, a Y-cable is needed that connects the Lemo connector of the Manual Controller to the ZCtrl and the Aux Input of the HF2LI. Here you find the necessary technical information for the connectors.</p>
<h3>Parts List</h3>
<ul>
<li>Lemo Connector PCA.0S.304.CLLC37 <a href="http://intra.lemo.ch/catalog/ROW/UK_English/unipole_multipole.pdf">Datasheet</a></li>
<li>BNC Connector (half BNC cable)</li>
<li>RJ45 connector with cable (sacrifice a network cable). Be referred to our user manual for a pin description of the ZCtrl connector.</li>
<li>Short piece of four-core cable</li>
</ul>
<h3>Electric Connectivity</h3>
<table>
<tbody>
<tr>
<td><strong>BNC</strong></td>
<td><strong>RJ45</strong></td>
<td><strong>Lemo</strong></td>
</tr>
<tr>
<td>Core: Offset+<br />
Shield: Offset- (GND)</td>
<td>Pin 1: +12V<br />
Pin 4: -12V</td>
<td>Pin 1: +12V<br />
Pin 2: Offset+<br />
Pin 3: Offset- (can be grounded)<br />
Pin 4: -12V</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table>
<tbody>
<tr>
<td><a href="http://www.zhinst.com/blogs/andreas/files/2012/03/DSC_0067_small.jpg"><img class="alignnone size-medium wp-image-25" src="http://www.zhinst.com/blogs/andreas/files/2012/03/DSC_0067_small-300x199.jpg" alt="Adapter cable" width="300" height="199" /></a></td>
</tr>
<tr>
<td><em>Adapter cable</em></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><img src="http://www.zhinst.com/blogs/andreas/files/2012/03/DSC_0075_crop.jpg" alt="Lemo connector" height="100px" /></td>
<td><img src="http://www.zhinst.com/blogs/andreas/files/2012/03/DSC_0078_crop.jpg" alt="Lemo connector disassembled" height="100px" /></td>
</tr>
<tr>
<td><em>Lemo connector</em></td>
<td><em>Lemo connector disassembled</em></td>
</tr>
</tbody>
</table>
<h2>HF2LI Configuration</h2>
<p>One of the four PID controllers of the HF2LI is used as a generic interconnectivity module providing only proportional gain. The output is written to the Aux Output offset (and thus added to the dF value, which is output at the same Aux Output). The PID is configured as follows:</p>
<table>
<tbody>
<tr>
<td>
<ul>
<li>Input = Aux Input</li>
<li>Setpoint = 0</li>
<li>P = gain</li>
<li>I = 0</li>
<li>D = 0</li>
<li>Output = Aux Output (Offset)</li>
<li>Center = 0</li>
<li>Range = maximum output range</li>
</ul>
</td>
<td><a href="http://www.zhinst.com/blogs/andreas/files/2012/03/pid_single.png"><img class="alignleft size-full wp-image-80" src="http://www.zhinst.com/blogs/andreas/files/2012/03/pid_single.png" alt="" width="242" height="204" /></a></td>
</tr>
</tbody>
</table>
<p>The HF2LI configuration file can be downloaded there:<br />
<a title="hf2conf_pll_AmpPID_OffsetBox.zip" href="http://http://people.zhinst.com/%7Eandreass/downloads/hf2conf_pll_AmpPID_OffsetBox.zip">hf2conf_pll_AmpPID_OffsetBox.zip</a></p>
<p>By default the Aux Input performs an averaging of 256 samples in a moving average manner. This is a sensible setting for this purpose as it has to reduce noise while still providing sufficient bandwidth.</p>
<h2>Connectivity to Scan Controller</h2>
<p>The voltage encoding of the dF &#8211; dFOffset fed into the scan controller as the feedback signal is set under &#8220;Aux outputs&#8221;. Depending on the scan controllers&#8217; feedback, the sign of the encoding has to be chosen accordingly.</p>
<h2>Application Example</h2>
<p>These images, which were recorded in non-contact mode using an HF2LI, were kindly provided by Philipp Rahe from the Molecular Self-Assembly Research Group Kühnle, University of Mainz, Germany.</p>
<table>
<tbody>
<tr>
<td><a href="http://www.zhinst.com/blogs/andreas/files/2012/03/z.png"><img class="alignnone size-medium wp-image-26" src="http://www.zhinst.com/blogs/andreas/files/2012/03/z-300x281.png" alt="" width="300" height="281" /></a></td>
<td></td>
<td><a href="http://www.zhinst.com/blogs/andreas/files/2012/03/z_atomar.png"><img class="alignnone size-medium wp-image-27" src="http://www.zhinst.com/blogs/andreas/files/2012/03/z_atomar-300x281.png" alt="" width="300" height="281" /></a></td>
</tr>
</tbody>
</table>
<p>P. Rahe, J. Schütte, A. Kühnle<br />
NC-AFM contrast formation on the calcite (10-14) surface<br />
J. Phys.: Condens. Matter 24 (2012) 084006</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/andreas/connecting-nanosurf-manual-controller-to-zurich-instruments-hf2li-pll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resolution, Scanning Speed and Demodulation Bandwidth</title>
		<link>http://www.zhinst.com/blogs/andrin/2011/12/06/scanning-speed-and-demodulation-bandwidth/</link>
		<comments>http://www.zhinst.com/blogs/andrin/2011/12/06/scanning-speed-and-demodulation-bandwidth/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 08:40:37 +0000</pubDate>
		<dc:creator>Andrin</dc:creator>
				<category><![CDATA[Theory]]></category>
		<category><![CDATA[AFM/SPM]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[Optics]]></category>

		<guid isPermaLink="false">http://5.380</guid>
		<description><![CDATA[This post is about the interplay between resolution, scanning speed and demodulation bandwidth. I demonstrate how the scanning process can be described in spatial, time and frequency domain, and show that this is a valuable toolbox to analyze your measurement setup as a whole.]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>In this post, I will demonstrate you the interplay between resolution, scanning speed and demodulation bandwidth. In case you ever used a scanning probe microscope (SPM) or a laser scanning microscope, you know that the image you acquired at the end of the day is your sample convoluted by the response of your scanning system. In standard AFM imaging, this is the shape of your scanning tip, in laser scanning microscopy, this is the shape of your focus, also known as the point spread function. However, during the actual scanning process, you are dealing with a continuous time measurement signal and need to ensure sensitive signal detection. I will therefore describe the scanning process in the time and frequency domain. With help of some calculations, I will show you how filters acting on the scanning signal influence the imaging resolution and how you can use these results in practice.</p>
<p><strong>Scanning: Filtering in time-domain</strong></p>
<p>In the spatial domain, the resolution along one line can often be described by a Gaussian function</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_7062'></span></div>
<p>with the relation</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_2792'></span></div>
<p>to the full width half maximum (FWHM), which approximates the smallest resolvable feature. In the scanning process, R(x) moves across the sample X(x) at a constant velocity vs. Consequently, a continuous-time measurement signal y(t) is generated. The scan controller samples this signal at distinct points, which correspond to equidistant points in the spatial domain: image pixels. For now, I want to focus on the properties of the continuous-time measurement signal y(t). With the substitution (x = vs t) into R(x), it is straightforward to see that R(t) is again a Gaussian with</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_1025'></span></div>
<p>In analogy to spatial filtering of the sample by R(x), R(t) is the impulse response of a Gaussian filter, which filters X(x = vs t). Assuming that the sample contains more features than those resolvable by R(x), the bandwidth of the measurement signal y(t) is limited by the Gaussian filter R(t). To calculate this bandwidth, I use the unitary Fourier transform for the frequency domain equivalent R(ω), similar as in (<a title="FourierTransformGaussian" href="http://mathworld.wolfram.com/FourierTransformGaussian.html" target="_blank">1</a>)</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_6878'></span></div>
<p>which has the 3dB frequency</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_5146'></span></div>
<p>In consistence with basic intuition, the bandwidth is proportional to the scanning speed and inversely proportional to the smallest resolvable feature. I plotted R(x), R(t) and R(ω) in the Figure below (from left to right). The abscissa for R(x) and R(t) is in units of the corresponding FWHM, whereas for R(ω), units of the 3dB frequency are chosen.</p>
<div style="margin-bottom: 10px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/10/fromxtof.png"><img class="aligncenter size-full wp-image-381" src="http://www.zhinst.com/blogs/andrin/files/2011/10/fromxtof.png" alt="" width="545" height="151" /></a>Note that I start in spatial domain, then transform to time substituting (x = vs t) and finally apply the Fourier transform. For completeness, keep in mind that imaging resolution and contrast can also be described by the modulation transfer function, which is the spatial Fourier transform of R(x). In case you are used to think in terms of modulation transfer functions, you can simply transform the frequency domain to the reciprocal space by substituting (ω = vs k), where k is 2π/x: It is therefore only a rescaling of the frequency axis.</div>
<p><strong>Role of the Lock-in Amplifier</strong></p>
<p>In many applications, R(ω) is modulated by a carrier ωc, whose frequency is well above the bandwidth of R(ω). In AFM/SPM, ωc is the probe oscillation in spatial domain; in laser scanning microscopy, ωc is the modulation frequency of the laser-beam in time domain. Accordingly, the measurement signal needs to be demodulated at ωc and filtered prior to pixel mapping by the scan controller. To keep things simple and general, I skip application details on AFM, where the demodulated signal is part of a feedback loop. A schematic on this is given in the figure below. On the left hand side, the moving tip/focus with modulation at ωc is depicted. This analog signal is demodulated by the HF2LI and routed to the scan controller by the auxiliary analog outputs. Because the HF2LI is a digital lock-in, an analog to digital (A/D) conversion on the input and a digital to analog (D/A) conversion on the auxiliary output is performed. This internal sampling is at a much higher rate than the pixel sampling in the scan controller. To avoid resolution degradation due to demodulation, the demodulation filter should thus leave R(ω) as it is. On the contrary, an efficient rejection of out of band noise requires a demodulation filter bandwidth as narrow as possible. To handle this tradeoff, I will show you some simulations for different filter settings and scanning speeds.</p>
<div style="margin-bottom: 10px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/10/scan_scheme.png"><img class="aligncenter size-full wp-image-389" src="http://www.zhinst.com/blogs/andrin/files/2011/10/scan_scheme.png" alt="" width="550" height="160" /></a></div>
<p><strong>Fast Scanning</strong></p>
<p>If you want to scan as fast as possible, the maximum demodulation bandwidth limits the scan speed. In practice, such situations arise in laser scanning microscopy at fast frame rates. The question I highlight is therefore: What is the fastest possible scan speed with the HF2LI?</p>
<p>First of all, the maximum demodulation bandwidth needs to be known. For the demodulator, the maximum bandwidth is 200 kHz for a first order filter with a time constant of 780 ns. I will refer to this demodulation filter as D. In addition, there is a second order 200 kHz analog filter on the auxiliary output. For this filter, I use A as reference.  These two filters together (D·A) have a bandwidth of 147 kHz. To find out how these filters affect the spatial resolution, I filter R(ω) with D and A and examine the resulting signal (R·D·A) in the spatial domain. By sweeping the scanning speed, I then get the effective FWHM, which I term as the effective resolution, in dependence of the scanning speed. The procedure is depicted in the figure below. In case you want the plots with a better resolution, just get the svg .</p>
<p>On the left hand side, the frequency domain signals and filters are illustrated. The D·A filter with 147 kHz bandwidth is depicted in magenta by the dashed line. The scanning signal R(ω) in red has here a bandwidth of 156 kHz and is therefore slightly above the demodulation bandwidth. The resulting R·D·A is shown in blue.</p>
<p>In the middle, you see R(x) and R·D·A(x). For R(x), I used a FWHM of 0.5 μm, which is a typical value for laser scanning setups. Because there is no analytical solution for a filtered Gaussian function, I needed to calculate R·D·A(x) with help of the inverse Fourier transform. Since the filters narrow the signal in frequency, the spatial equivalent is broader and results in a higher FWHM. For the illustrated curves, the effective FWHM is 1.43 times the physical FWHM of R(x). I did not include contrast degradation and phase shift due to the low pass filter. In the subsequent section on slow scanning, I include the delay due to the filter in my calculations.</p>
<p>On the right hand side, I plotted the effective resolution against the scanning speed in units of the physical FWHM. The abscissa is swept from 0 to 5E5. The maximum value on the abscissa therefore corresponds to R(ω) with a bandwidth of 156 kHz, which is shown on the illustrations on the left and in the middle. At the fastest speed, where the demodulation bandwidth is equal to the bandwidth of R(ω), the spatial resolution can be degraded by 30% (1 &#8211; 1/1.43).</p>
<p><a href="http://www.zhinst.com/blogs/andrin/files/2011/10/fastspeed.png"><img class="aligncenter size-full wp-image-471" src="http://www.zhinst.com/blogs/andrin/files/2011/10/fastspeed.png" alt="" width="550" height="175" /></a></p>
<div style="margin-bottom: 10px">To have an idea how the results for fast scanning are related in practice, I give a numerical example:</div>
<div style="margin-bottom: 10px">Suppose I do not want to increase my FWHM by more than 5%. With a physical FWHM of 0.5 μm, I therefore end up with an effective FWHM of 0.525 μm. From the plot on the right hand side of the figure above, I get a scanning speed vs of 82.9 mm/s. With this scanning speed, I can now calculate how many frames per second are possible for some predefined frame sizes. Without loss of generality, I use a pixel spacing of 0.25 μm, which is half the FWHM. The resulting frame rates are shown in the table below. I also show the results for an FWHM increase of 10% , 20%, 30% and 40% for even faster frame rates. These rates are also valid for other FWHM values, as long as you sample the FWHM with two pixels. I did not include any delays for beam repositioning within frames, which corresponds to scanning the sample up-down and down-up. For the 5%, 10% and 20% rates, the values are also found in the application note on nonlinear optical microscopy at high speed (not yet published). The highest scanning speed with an FWHM increase of 40% corresponds to equal bandwidths for R(ω) and the 147 kHz demodulation filter.</div>
<div style="margin-bottom: 5px">
<table align="center">
<tbody>
<tr>
<td style="text-align: center" width="100px">Frame Pixels</td>
<td style="text-align: center" width="100px">5% Rate</td>
<td style="text-align: center" width="100px">10% Rate</td>
<td style="text-align: center" width="100px">20% Rate</td>
<td style="text-align: center" width="100px">30% Rate</td>
<td style="text-align: center" width="100px">40% Rate</td>
</tr>
<tr>
<td style="text-align: center">512 x 512</td>
<td style="text-align: center">1.2 fps</td>
<td style="text-align: center">1.7 fps</td>
<td style="text-align: center">2.3 fps</td>
<td style="text-align: center">2.9 fps</td>
<td style="text-align: center">3.5 fps</td>
</tr>
<tr>
<td style="text-align: center">256 x 256</td>
<td style="text-align: center">4.9 fps</td>
<td style="text-align: center">6.7 fps</td>
<td style="text-align: center">9.4 fps</td>
<td style="text-align: center">11.7 fps</td>
<td style="text-align: center">13.8 fps</td>
</tr>
<tr>
<td style="text-align: center">175 x 175</td>
<td style="text-align: center">10 fps</td>
<td style="text-align: center">14 fps</td>
<td style="text-align: center">20 fps</td>
<td style="text-align: center">25 fps</td>
<td style="text-align: center">29.6 fps</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Slow Scanning</strong></p>
<p>At slower scan speeds, you have a lot of choices for the demodulation filter. You can choose between different filter orders as well as between different 3dB cutoff frequencies. To show you the related effects, I again made some simulations. Here, I used 1st, 2nd and 4th order filters &#8211; D1, D2 and D4 respectively &#8211; at different filter bandwidths. I expressed the filter bandwidth in units of the 3dB frequency of R(ω). The analog filter A on the auxiliary output is not considered, because it has a much higher bandwidth. Results are shown in the figure below. In case you want the plots with a better resolution, just get the svg .</p>
<p>On the left hand side, the frequency domain signals and filters are illustrated. The demodulation filters D1, D2 and D4 all have their bandwidth equal to the bandwidth of R(ω). Due to the filter steepness, higher order filters attenuate the signal stronger above their 3dB frequency compared t0 lower order filters, which can be readily seen in the figure below. Below their 3dB frequency, lower order filters attenuate the signal stronger compared to higher order filters, which is difficult to see in the illustrated figure.</p>
<p>In the middle, the curves are shown in the spatial domain. The demodulation filter bandwidth is also in this case identical to the bandwidth of R(ω). In the slow scanning case discussed here, I accounted for the phase shift of the demodulation filter. The phase shift in the frequency domain corresponds to a time delay of the filtered measurement signal. By mapping this delay to the spatial domain, the filtered curves are shifted in space. Accordingly, the spatial shift is the distance that the tip/focus travels until the demodulated signal is at the auxiliary output of the lock-in amplifier. The numerical values for the shift are 0.33, 0.52 and 0.79 times the FWHM for a 1st, 2nd and 4th order filter, respectively. In a regular imaging process, this shift/delay can be corrected by the pixel sampling in the scan controller. The situation is different in feedback systems, where an instantaneous feedback signal is essential for stability. In AFM systems, the conditions are even stricter, because you usually want the feedback system to react before crashing your tip against some sharp feature.</p>
<p>On the right hand side, the spatial shift and the effective resolution, both in units of the FWHM, are plotted against the demodulation filter bandwidth in units of the 3dB frequency of R(ω). On this figure, you see that the higher the demodulation filter bandwidth, the lower the spatial shift and effective FWHM, as less high frequency components in R(ω) are attenuated/delayed by the demodulation filter. When looking at these results, keep in mind that a higher demodulation filter bandwidth also degrades the SNR. If you increase the bandwidth by a factor of 4, the noise power doubles. In addition to that, a higher order filters suppress out of band noise better due to their higher steepness.</p>
<p>If the filters and R(ω) have equal 3dB frequencies, you can actually make some approximations to calculate the effective FWHM yourself. You get an analytical solution, if the demodulation filter would also be a Gaussian function. On the left hand side of the figure below, you see that a Gaussian decays much faster than a low pass filter. Approximating the demodulation filter as Gaussian therefore yields an upper limit to the spatial FWHM for the filter orders studied here. The analytical bound is easy to calculate, since the multiplication of two Gaussians with equal bandwidth results in a Gaussian with a √2 times lower bandwidth. The effective spatial FWHM is therefore higher by a factor of √2 ~ 1.414. The numerical values found here are all smaller: 1.24, 1.29 and 1.33 for the 1st, 2nd and 4th order filter, respectively.</p>
<p>For the spatial phase shift, you can also easily calculate an analytical upper bound. Consider a first order filter with its bandwidth equal to the bandwidth of R(ω). At the signals 3dB frequency, the filter introduces a phase shift of 45°, which corresponds to a time delay of one eighth of the 3dB frequency&#8217;s oscillation period. Transforming this delay back to the spatial domain results in a shift of 1/8·FWHM/0.312 ~ 0.4. The numerically calculated value for the first order filter is 0.33.</p>
<p><a href="http://www.zhinst.com/blogs/andrin/files/2011/10/slowspeed.png"><img class="aligncenter size-full wp-image-440" src="http://www.zhinst.com/blogs/andrin/files/2011/10/slowspeed.png" alt="" width="550" height="175" /></a><strong>Usage in Practice</strong></p>
<p>In practice, you might not know how your R(x) looks like. In this case, the ziControl software of the HF2LI has a very useful tool: ZoomFFT. This tool shows you the frequency spectrum of the demodulated signal. By scanning your sample and observing ZoomFFT with peak hold averaging and demodulation filter compensation, you can at first determine the 3dB bandwidth of R(ω) and find out at which level your noise floor is. If you are scanning a sample with a multitude of sharp features, you can even determine R(ω) with help of ZoomFFT and then calculate R(x) from this, because the scanning speed is a known quantity. This is a different approach than the widely used resolution determination at one single step.</p>
<p>With the bandwidth of R(ω) at hand, it is up to you to choose a demodulation filter. In case of very weak signals, you need to make a tradeoff in imaging resolution and SNR.</p>
<p>In special cases where you are not capable of spatial oversampling, the demodulation filter can also be used for higher aliasing suppression in the resulting image. The transformation of a low pass filter to an image filter is very easy, because the frequency domain is transformed into the reciprocal domain by substituting (ω = vs k).<br />
<strong></strong></p>
<p><strong>References</strong></p>
<div>
<ol>
<li><a href="http://mathworld.wolfram.com/about/author.html">Weisstein, Eric W.</a> &#8220;Fourier Transform&#8211;Gaussian.&#8221; From <a href="http://mathworld.wolfram.com/"><em>MathWorld</em></a>&#8211;A Wolfram Web Resource. <a href="http://mathworld.wolfram.com/FourierTransformGaussian.html">http://mathworld.wolfram.com/FourierTransformGaussian.html</a></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/andrin/2011/12/06/scanning-speed-and-demodulation-bandwidth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Plotting of HF2 Lock-in Data with Python</title>
		<link>http://www.zhinst.com/blogs/schwizer/2011/11/dynamic-plotting-of-hf2-lock-in-oscilloscope-data-with-python/</link>
		<comments>http://www.zhinst.com/blogs/schwizer/2011/11/dynamic-plotting-of-hf2-lock-in-oscilloscope-data-with-python/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 17:06:11 +0000</pubDate>
		<dc:creator>Lara Juricic</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ZI Interfaces]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[oscilloscope]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://2.1173</guid>
		<description><![CDATA[The Matplotlib is a library for creating 2D plots of arrays in Python. The purpose of this blog entry is to depict a general approach to enable continuous updating of figure data during the Python script execution. The figure update functionality is useful for plotting measurement data that is recorded with the Zurich Instruments HF2LI Lock-in amplifier.]]></description>
			<content:encoded><![CDATA[<p>The Matplotlib is a library for creating 2D plots of arrays in Python. Matplotlib.pyplot and Matplotlib.pylab have a collection of commands that make Matplotlib work like Matlab. The designers of the Matplotlib library made two assumptions concerning plotting with Python. First, when plots are created by scripting, there is no need to update the figure every time a single property is changed, only once after all the properties are changed. Thus, Matplotlib defers plotting until the end of the Python script because drawing can be an expensive operation. Second, when working in the Python shell, it is desirable to update the figure with each command. The purpose of this blog entry is to depict a general approach to enable continuous updating of figure data during the Python script execution.</p>
<p>The installation of the Zurich Instruments Python interface is discussed in <a href="http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/">Controlling the HF2LI Lock-in with Python</a>.</p>
<h3>Simple Plotting Example with Python</h3>
<p>Find below a simple plot example that uses the Matplotlib.pyplot module:</p>
<p><code><span class="command">import</span> matplotlib.pyplot <span class="command">as</span> plt<br />
<span class="command">from</span> numpy <span class="command">import</span> *<br />
</code><br />
<code>a=arange(0,10,0.1)<br />
plt.figure()<br />
plt.plot(a,sin(2*pi*a/10))<br />
</code><br />
<code>plt.figure()<br />
plt.plot(a,cos(2*pi*a/10))<br />
plt.show()<br />
</code><code><span class="command">print</span> <span class="string">'Done!'</span><br />
</code></p>
<p>The <code>show()</code> command tells the Matplotlib to render all figure windows and start the GUI mainloop. As the mainloop is blocking, this command should be called only once at the end of the script. The figure will contain the final result of all preceding plot commands. Script commands following <code>show()</code> will be blocked until all figures are closed by the user.<br />
One solution to plot continuous oscilloscope data using the <code>show()</code> command is the creation of a new figure for each oscilloscope shot.<br />
However, it is more convenient to update the same figure for each oscilloscope shot as it is for example done for the oscilloscope tab within ziControl (Zurich Instruments graphics user interface). Therefore, continuous updating of the figure with each pyplot command has to be enabled. Command <code>draw()</code> is suitable to force re-plotting. In that case, the program execution after plotting will also be possible, even without closing the figure.</p>
<h3>Python Settings for Dynamic Plotting</h3>
<p>There are interactive Python distributions such as iPython that are automatically working in the mode where every pyplot command triggers a figure update. The subsequently presented approach is not limited to a specific distribution and explains a general method to enable the interactive mode.<br />
Matplotlib uses matplotlibrc configuration file to customize all kinds of properties such as default figure size, line width, colors and style, grid properties, text font. To find out the location of matplotlibrc file that is currently loaded use the command <code>matplotlib.matplolib_frame()</code>. To support updating the figure on every pyplot command the backend should be set to TkAgg and the interactive flag should be set to <code>True</code> in the matplotlibrc file. If matplotlib is installed again, the settings will be overwritten.<br />
Alternatively, the settings can also be applied in the python script directly. Before importing pyplot, backend should be set with command <code>matplotlib.use('TkAgg')</code>. After importing pyplot, interactive mode should be turned on with the command <code>matplolib.pyplot.ion()</code>.</p>
<h3>Dynamic Plotting of HF2 Lock-in Oscilloscope Data</h3>
<p>The Python script presented in this section will plot the sum of two sine waves with frequency difference of 1 Hz. The result is a signal with beating amplitude. Before running the script <code>scope_example.py</code>, Signal Output 2 Out should be connected to Signal Output 1 Add and Signal Output 1 Out should be connected to Signal Input 1 +In. The HF2-LI Lock-in should be connected to the computer with a USB 2.0 cable. The ziServer should be running on the computer where the instrument is connected to.<br />
There are several ways how to run <code>scope_example.py</code> script because the code in the script is structured so that can be used as a standalone program and as a module. As a standalone program, the script can be run from the command prompt with <code>python -i scope_example.py</code>. This is possible if you are located in folder that contains file <code>scope_example.py</code> and the environment variable <code>path</code> contains path to the executable Python file in C:Python26.<br />
For the users who are using IDLE (Python GUI), it&#8217;s recommended to open file <code>scope_example.py</code> with the right click on file and selecting &#8216;Edit with IDLE&#8217;. In this case the IDLE shell will write a message <code>==== No Subprocess ====</code>. To run the script, press F5 or select Run module from the Run menu. It&#8217;s important to run Python shell with no sub-processes because otherwise the script execution will crash if you for example only try to move the figure window.<br />
The <code>scope_example.py</code> script can be imported in a Python shell as a module with <code>import scope_example</code>. It contains class called <code>Oscilloscope</code>. Class instantiation automatically invokes the <code>__init__()</code> method to obtain initialized instance of the class. Arguments that must be supplied at class instantiation are the reference to the server, the device name string and the input channel number of which data should be analyzed. The class defines methods <code>set_parameters</code> and <code>update</code>. Method <code>set_parameters</code> sets the oscilloscope parameters (see ZI oscilloscope tab in the ziControl) source channel, sampling rate, configuring the trigger, and time between to oscilloscope shots. The method <code>update</code> creates an oscilloscope window and plots new oscilloscope data after each call.</p>
<p>Download the file .</p>
<pre><code><span class="command">import</span> time, math, random
<span class="command">import</span> zhinst.ziPython, zhinst.utils
<span class="command">import</span> matplotlib
matplotlib.use(<span class="string">'TkAgg'</span>)
<span class="command">import</span> matplotlib.pyplot <span class="command">as</span> plt
<span class="command">from</span> numpy <span class="command">import</span> *
plt.ion()
</code>
<code><span class="command">class </span><span class="function">Oscilloscope</span>(object):
   <span class="command">def</span> <span class="function">__init__</span>(self,device,daq,channel):
       self.device=device
       self.daq=daq
       self.channel=channel
       self.updated=0
</code>       
<code>   <span class="command">def</span> <span class="function">set_parameters</span>(self, bwlimit=0,trigedge=1,triglevel=0,
                      trigholdoff=0.01,trigchannel=-2,t=1):
       settings = [
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/channel'</span>], self.channel-1],
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/bwlimit'</span>], bwlimit],
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/trigedge'</span>], trigedge],
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/triglevel'</span>], triglevel],
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/trigholdoff'</span>], trigholdoff],
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/trigchannel'</span>], trigchannel],
           [[<span class="string">'/'</span>, self.device, <span class="string">'/scopes/0/time'</span>], t]
       ]
       self.daq.set(settings)
       <span class="comment"># Wait 1s</span>
       time.sleep(1)
       <span class="comment"># Clean queue</span>
       self.daq.flush()
</code> 
<code>   <span class="command">def</span> <span class="function">update</span>(self):
           rng=self.daq.getDouble(<span class="string">'/'</span> + self.device + <span class="string">'/sigins/'</span>
                                  + str(self.channel-1) + <span class="string">'/range'</span>)
           <span class="comment"># Poll data 0.05s with a timeout of 500ms</span>
           dataDict = self.daq.poll(0.05,500)
           <span class="comment"># For first oscilloscope shot use plot function and after is</span>
           <span class="comment"># used draw function to update figure with new oscilloscope data</span>
           <span class="command">if</span> self.device <span class="command">in</span> dataDict:
               data=dataDict[self.device][<span class="string">'scopes'</span>][<span class="string">'0'</span>][<span class="string">'wave'</span>][0][<span class="string">'wave'</span>]
               datay=data*rng/float(2**15)
               <span class="command">if</span> plt.get_fignums() and self.updated==1:
                   self.line.set_ydata(datay)
                   plt.draw()
               else:
                   <span class="comment"># Create oscilloscope window</span>
                   plt.figure()
                   plt.grid(True)
                   plt.title(<span class="string">'Osciloscope data'</span>)
                   plt.xlabel(<span class="string">'Time(us)'</span>)
                   plt.ylabel(<span class="string">'Amplitude(V)'</span>)
</code>                   
<code>		   <span class="comment"># Plot first oscilloscope shot</span>
                   dt=dataDict[self.device][<span class="string">'scopes'</span>][<span class="string">'0'</span>][<span class="string">'wave'</span>][0][<span class="string">'dt'</span>]
                   datax=[x*1e6 <span class="command">for</span> x <span class="command">in</span> arange(0,dt*2048,dt)]
                   plt.axis([0,datax[-1],-2*rng,2*rng])
                   self.line, = plt.plot(datax,datay)
                   self.updated=1
</code>

<code><span class="command">if</span> __name__ == <span class="string">'__main__'</span>:
</code>
<code>   <span class="comment"># Open connection to ziServer</span>
   daq = zhinst.ziPython.ziDAQServer(<span class="string">'localhost'</span>, 8005)
</code>
<code>   <span class="comment"># Detect device</span>
   device = zhinst.utils.autoDetect()
</code>
<code>   <span class="comment"># Set channels parameters</span>
   channel_settings = [
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/0/diff'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/0/imp50'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/0/ac'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/0/range'</span>], 1],
</code>
<code>       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/1/diff'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/1/imp50'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/1/ac'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/1/range'</span>], 1],
</code>
<code>       [[<span class="string">'/'</span>, device, <span class="string">'/oscs/0/freq'</span>], 100e3],
       [[<span class="string">'/'</span>, device, <span class="string">'/oscs/1/freq'</span>], 100e3+1],
</code>
<code>       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/0/add'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/0/on'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/0/range'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/0/amplitudes/6'</span>],0.5],
</code>
<code>       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/1/add'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/1/on'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/1/range'</span>],1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/1/amplitudes/7'</span>],0.5],
       ]
   daq.set(channel_settings)
   time.sleep(1)
</code>
<code>   <span class="comment"># Select lock-in channel</span>
   channel=1
</code>
<code>   <span class="comment"># Create object Oscilloscope</span>
   a=Oscilloscope(device,daq,channel)
</code>
<code>   <span class="comment"># Set parameters for the scope</span>
   a.set_parameters(bwlimit=0,trigedge=1,triglevel=0,
                    trigholdoff=0.01,trigchannel=0,t=1)
</code>
<code>   <span class="comment"># Subscribe to scope data</span>
   path0 = <span class="string">'/'</span> + device + <span class="string">'/scopes/0/wave'</span>
   daq.subscribe(path0)
</code>
<code>   <span class="comment"># N is number of oscilloscope shots</span>
   N=random.randint(50,100)
</code>
<code>   <span class="command">for</span> i in range(0, N):
       a.update()
</code>   
<code>   <span class="comment"># Unsubscribe     </span>
   daq.unsubscribe(path0)
   <span class="command">print</span> <span class="string">'Done!'</span>
</code></pre>
<p>Here is a figure with only 8 oscilloscope shots plotted in the same figure. The darker the color the later the oscilloscope data was recorded.</p>
<p><a rel="attachment wp-att-1301" href="http://www.zhinst.com/blogs/schwizer/2011/11/dynamic-plotting-of-hf2-lock-in-oscilloscope-data-with-python/blue_oscilloscope_data_2t_lw4/"><img class="alignnone size-full wp-image-1301" src="http://www.zhinst.com/blogs/schwizer/files/2011/05/blue_oscilloscope_data_2T_lw4.png" alt="" width="652" height="492" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/schwizer/2011/11/dynamic-plotting-of-hf2-lock-in-oscilloscope-data-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exploring the HF2LI-MOD: Measuring Bessel Functions</title>
		<link>http://www.zhinst.com/blogs/andrin/2011/10/20/exploring-the-hf2li-mod-measuring-bessel-functions/</link>
		<comments>http://www.zhinst.com/blogs/andrin/2011/10/20/exploring-the-hf2li-mod-measuring-bessel-functions/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 11:40:35 +0000</pubDate>
		<dc:creator>Andrin</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[AM/FM]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[MOD]]></category>

		<guid isPermaLink="false">http://5.112</guid>
		<description><![CDATA[In this post, I demonstrate the capabilities of the HF2LI-MOD upgrade by demodulating 4 FM sidebands simultaneously. With the help of a basic sweep routine programmed in LabVIEW, I measure 5 Bessel functions by direct sideband demodulation of an FM signal. This post might give you an inspiration on how to improve your measurement sensitivity by introducing an advanced demodulation scheme of multiple sidebands.]]></description>
			<content:encoded><![CDATA[<p>Today, I will explore the MOD option, which allows direct sideband demodulation with the HF2LI. First of all, I will explain the difference between direct sideband demodulation and tandem demodulation. Then, I will show you loopback examples, where I generate a frequency modulation (FM) signal on the output channel and feed this signal back to the input for direct sideband demodulation. These loopback measurements demonstrate the unique capabilities of the HF2LI-MOD. Advanced application examples are mentioned at the end of this post.</p>
<p>The MOD option is not included in the basic HF2LI and additionally requires the multifrequency option MF. If you already have a HF2LI and are interested in the MOD option, the upgrade is possible on the field without shipping the HF2LI back to ZI.</p>
<p><strong>Tandem Sideband Demodulation with the HF2LI<br />
</strong></p>
<p>Suppose I want to demodulate an input signal consisting of a carrier at a frequency ωc and two sidebands at frequencies +-ωm from the carrier. Tandem demodulation is the standard approach that requires two lock-in amplifiers in a tandem configuration: firstly, the input signal is demodulated to baseband at the carrier frequency with a bandwidth larger ωm; then the demodulated signal (either R or Theta according to whether the signal is an amplitude of frequency modulated signal) is fed to the second lock-in, where it is demodulated at the modulation frequency ωm. Additional instrumentation or measurement effort is paid, because the demodulation oscillator in the first demodulation step needs to be in phase with the carrier at ωc of the incoming signal.</p>
<p>As one single HF2LI contains two lock-in amplifiers, tandem demodulation is feasible. The first channel demodulates the incoming signal at the carrier frequency. From the three available demodulators of channel 1, I would use one demodulator with a narrow bandwidth to analyze the carrier frequency and another demodulator with sufficient bandwidth for the baseband signal. For further demodulation with the modulation frequency, the baseband signal is fed to the input of the second lock-in channel via the analog auxiliary output. In doing so, up to three sidebands can be analyzed in the second channel. The core limitation of this technique is set by the highest possible 200 kHz demodulation bandwidth and another 200 kHz filter on the auxiliary output channel.</p>
<p><strong>Direct Sideband Demodulation with the HF2LI-MOD</strong></p>
<p>Instead of tandem demodulation, the sidebands can also be analyzed directly by demodulating at frequencies (ωc &#8211; ωm) and (ωc + ωm). The HF2LI-MOD implements this scheme by using local oscillators at the corresponding sum and difference frequency of ωc and ωm. The assignment of the 6 internal demodulators to these local oscillators is shown in the figure below: Demodulators (1,2,3) and (4,5,6) are grouped into two MOD channels, MOD1 and MOD2, respectively. The 2 carrier frequencies can be equal, harmonics of each other (e.g. ωc1 = n * ωc2) or set arbitrarily. The same holds for the 4 different sideband spacings ωm1, .., ωm4. In the example of the figure below, each of these frequencies is set arbitrarily.  In total, you can therefore detect 4 sidebands (one upper and one lower sideband for each MOD channel). With such many degrees of freedom, you have plenty of possibilities for direct sideband demodulation with a frequency range up to 50 MHz in just one single box. This direct scheme has several advantages: it reduces lab complexity (only one lock-in used) and minimizes the SNR, because only one analog to digital conversion is required, which is not the case for tandem demodulation schemes.</p>
<div style="margin-bottom: 15px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/10/modcap1.png"><img class="aligncenter size-full wp-image-366" src="http://www.zhinst.com/blogs/andrin/files/2011/10/modcap1.png" alt="" width="534" height="212" /></a></div>
<p><strong>HF2LI-MOD Output Signals<br />
</strong></p>
<p><strong></strong>As stimuli for your measurements, you can choose between sinusoidal excitation, amplitude modulated (AM) excitation or frequency modulated (FM) excitation for either the MOD1 or MOD2 channel. Note that the FM generation requires two oscillators and one demodulator, thus leaving the other MOD available for demodulating 1 carrier and 2 sidebands. For sinusoidal excitation and AM excitation, you have all the 6 demodulators available to measure 4 independent sidebands.</p>
<p><strong>The FM Spectrum</strong></p>
<p>Only few people are excited about the mathematical description of an FM signal s(t), because</p>
<div style="margin-bottom: 10px"><span id='tex_6260'></span></div>
<p>with the modulation index</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_5394'></span></div>
<div style="margin-bottom: 10px;margin-top: 10px">containing the peak frequency derivation Δω. s(t) therefore describes a signal, whose instantaneous frequency sinusoidally changes between (ωc &#8211; Δω) and (ωc + Δω) at a rate given by the modulation frequency ωm. φc and φm account for the constant phase shift of the corresponding oscillator. The spectrum of s(t) is an infinite number of sidebands around ωc. Each of sideband pair is weighted with the associated Bessel function Jn (of the first kind) evaluated at the modulation index. Due to this weighting, you observe only a few low order harmonics in practice, whereas high order harmonics vanish. For odd negative n, the sign of the Bessel function is inverted, because</div>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_6189'></span></div>
<div style="margin-bottom: 10px;margin-top: 10px">The Bessel functions of the first kind are depicted below for n = 0,1,2. For a more intuitive approach on the Bessel functions, I recommend you <a href="http://www.zhinst.com/blogs/michele/2011/10/20/amfm/" target="_blank">Michele&#8217;s post on amplitude and frequency/phase modulation</a>.</div>
<div style="margin-bottom: 10px;margin-top: 10px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/09/Bessel_Functions_1st_Kind_n012.png"><img class="aligncenter size-full wp-image-157" src="http://www.zhinst.com/blogs/andrin/files/2011/09/Bessel_Functions_1st_Kind_n012.png" alt="" width="525" height="394" /></a></div>
<p><strong>Measuring the Bessel Functions </strong></p>
<p>To demonstrate direct sideband demodulation with the HF2LI-MOD, I will sweep the modulation index h and directly measure the Bessel functions shown above with the demodulated sidebands. In a first step, I will generate an FM signal and demodulate 2 sidebands by using one HF2LI-MOD. In a second step, I use two HF2LI-MOD, one to generate the FM signal and another one to demodulate 4 sidebands.</p>
<p><em>Single Instrument FM Loop-back</em></p>
<p>To generate the FM signal, I use MOD1. I set the carrier frequency ωc to 1 MHz, the modulation frequency ωm to 1 kHz and the output amplitude to 1 V. The frequency deviation Δω is the sweep parameter. This FM signal is fed back to the input and routed to MOD2, where all sidebands are demodulated with a bandwidth of 6.8 Hz. I set demodulator 4 to the carrier frequency ωc, demodulator 5 to  ωc + ωm and demodulator 6 to ωc &#8211; 2ωm, which is done in the MF panel by selecting the harmonic 2 in demodulator 6.<a href="http://www.zhinst.com/blogs/andrin/files/2011/09/1dev_meas.png"><br />
</a>I implemented the modulation index sweep in a LabVIEW routine, where I step the frequency derivation Δω in 100 steps from 0 to 10 kHz and record a single measurement value per demodulator for each step. The modulation index is thus swept from 0 to 10 with a step size of 0.1. Before the measurement, my routine provides an auto-zero function to eliminate the phase shifts φc and φm. I therefore directly obtain the Bessel functions on the (in-phase) X channels of each demodulator. One detail is a factor of √2 due to the RMS reading of X, which I accord for before plotting the Bessel functions. The resulting demodulator signals plotted against the modulation index h are shown in the figure below. The carrier corresponds to J0, the first sideband to J1 and the second sideband to J2. While the second sideband actually is a lower sideband (n=-2), I directly get J2 due to the even n.</p>
<div style="margin-bottom: 10px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/09/1dev_cossin_blog.png"><img class="aligncenter size-full wp-image-350" src="http://www.zhinst.com/blogs/andrin/files/2011/09/1dev_cossin_blog.png" alt="" width="550" height="502" /></a></div>
<p>In a next step, I then set φm to -90 degrees, which leads to a phase shift of -90 degrees between each created sideband. The first sideband is therefore shifted by -90 degrees and needs to be detected on the (quadrature) Y channel. The demodulated signal will correspond to -J1. The second sideband is shifted by 180 degrees and is measured on X. In this case, also the second sideband will have a different sign and therefore correspond to -J2. The figure shown below exactly reproduces the expectations.</p>
<div style="margin-bottom: 10px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/09/1dev_coscos_blog.png"><img class="aligncenter size-full wp-image-351" src="http://www.zhinst.com/blogs/andrin/files/2011/09/1dev_coscos_blog.png" alt="" width="550" height="501" /></a></div>
<p>In case you are interested in the LabVIEW implementation, you can download the vi . Provided you have a HF2LI-MOD, you simply need to connect output 1 to input 1 and run the vi with the same settings as shown in the former figure. If you also want to reproduce the latter figure, you need to shift the phase of oscillator 2 by -90 degrees.</p>
<p><em>Two Instrument FM Loop-back</em></p>
<p><em></em>To measure 4 sidebands at a time, I use a second HF2LI device with the MOD extension to generate an FM signal. Think of the FM signal generated by the second lock-in I use as the measurement signal resulting from an experiment. Consider for instance a laser, intensity modulated at 1 MHz and phase modulated at 1 kHz. You could use such a setup to measure the phase modulation sidebands at higher frequencies, where the laser noise is lower than at kHz frequencies. Hereto, you need a 1 MHz and a 1 kHz sinusoidal carrier to excite the modulation and then have exactly the same situation as I create here with a second lock-in amplifier as FM generator.</p>
<p>I use exactly the same settings for the generated FM signal as in the example with one device. On the HF2LI used for sideband demodulation, I use the second demodulator for J1, the third for J2, the fifth for J3 and the sixth for J4. The third and sixth demodulator both measure a lower sideband, but are here equal to the upper due to the properties of the Bessel functions Jn for even n. The resulting plots are shown in the figure below. On the left hand side, I have set the phases φc and φm to zero and thus get all the signals on the X channels. On the right hand side, I used a phase shift of -90 degrees for φm. I therefore detect the odd sidebands on the Y channels and the even sidebands on the X channels. According to the expectations, J1 and J2 are negative, whereas J3 and J4 are again positive.</p>
<div style="margin-bottom: 10px"><a href="http://www.zhinst.com/blogs/andrin/files/2011/09/2dev_vi_blog.png"><img class="aligncenter size-full wp-image-353" src="http://www.zhinst.com/blogs/andrin/files/2011/09/2dev_vi_blog.png" alt="" width="550" height="394" /></a></div>
<p><strong>Application Examples</strong><br />
You are welcome to browse the <a title="publications" href="http://www.zhinst.com/publications" target="_blank">publications</a> section of the Zurich Instruments website for the HF2LI-MOD. You find there examples on frequency modulation Kelvin probe force microscopy (FM-KPFM) and on advanced gyroscopes for inertial navigation. These examples combine the MOD option with the PLL option to measure sidebands of mechanical resonances, which is a very powerful tool for AFM and MEMS applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/andrin/2011/10/20/exploring-the-hf2li-mod-measuring-bessel-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On Amplitude and Frequency/Phase Modulation</title>
		<link>http://www.zhinst.com/blogs/michele/2011/10/20/amfm/</link>
		<comments>http://www.zhinst.com/blogs/michele/2011/10/20/amfm/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 07:22:11 +0000</pubDate>
		<dc:creator>Michele Zaffalon</dc:creator>
				<category><![CDATA[Theory]]></category>
		<category><![CDATA[AM/FM]]></category>
		<category><![CDATA[demodulation]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[phasors]]></category>
		<category><![CDATA[rotating frame]]></category>

		<guid isPermaLink="false">http://4.10</guid>
		<description><![CDATA[I always had difficulties in understanding frequency modulation (FM) and its frequency spectrum. Even for the pure tone modulation, the FM spectrum consists of an infinite number of sidebands whose signs change from one sideband to the next one and whose amplitudes are given by the horrible Bessel functions. I have a pictorial representation of AM/FM that helped me understand the sidebands.]]></description>
			<content:encoded><![CDATA[<p>I always had difficulties in understanding frequency modulation (FM) and its frequency spectrum&#8230; 
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/michele/2011/10/20/amfm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Application: Pseudoheterodyne Detection in Optics</title>
		<link>http://www.zhinst.com/blogs/andrin/2011/09/15/new-application-pseudoheterodyne-detection-in-optics/</link>
		<comments>http://www.zhinst.com/blogs/andrin/2011/09/15/new-application-pseudoheterodyne-detection-in-optics/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 15:56:42 +0000</pubDate>
		<dc:creator>Andrin</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[Optics]]></category>

		<guid isPermaLink="false">http://5.272</guid>
		<description><![CDATA[There is a new application note about <a title="pseudoheterodyne detection in nearfield optics" href="http://www.zhinst.com/docs/appnotes/zi_appnote_pseudohet_snom.pdf" target="_blank">pseudoheterodyne detection in nearfield optics</a>. The application has also relevance for laser spectroscopy. Hereafter are a few personal comments about phase sensitive detection in optics, as I participated in the described experiments.]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>There is a new application note about <a title="pseudoheterodyne detection in nearfield optics" href="http://www.zhinst.com/docs/appnotes/zi_appnote_pseudohet_snom.pdf" target="_blank">pseudoheterodyne detection in nearfield optics</a>, which is based on measurements I did together with Rolf Brönnimann at the EMPA Dübendorf, Switzerland, on a scanning nearfield optical microscope (SNOM). The detection scheme allows for visualization of optical intensity and phase down to intensities in the lower femtowatt range. First of all, this is two orders of magnitude better than what is possible with an avalanche photodiode module (APD), and furthermore gives you optical phase information. You can achieve higher detection sensitivity by using time-triggered single photon detectors (PMTs or APDs in Geiger mode). These however require a pulsed laser setup.</p>
<p>Please note that the optical phase needs to be preserved with interferometric techniques, because any nowadays available optical detector solely measures the optical intensity. Besides the discussed pseudoheterodyne detection scheme, heterodyne detection and phase shifting interferometry are popular approaches to measure the optical phase.</p>
<p><strong>Difference between Heterodyne and Pseudoheterodyne Detection<br />
</strong></p>
<p>Sometimes I get confused reactions on the term &#8220;pseudoheterodyne detection&#8221;, because &#8220;pseudo&#8221; sounds like nothing real is going on. To avoid confusions, I&#8217;d like to shortly point out how I see the difference between heterodyne and pseudoheterodyne detection in optics.</p>
<p>For both detection techniques, the measurement setup results in interference between the measurement signal and the modulated reference signal. The measurement signal (sig) and the modulated reference signal (ref) are both from the same laser source, as shown in the figure below.</p>
<p><a href="http://www.zhinst.com/blogs/andrin/files/2011/09/interf_mod.png"><img class="aligncenter size-full wp-image-304" src="http://www.zhinst.com/blogs/andrin/files/2011/09/interf_mod.png" alt="" width="541" height="219" /></a></p>
<p>By neglecting losses in the optical setup, the intensity of the interference signal to be detected reads</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_9444'></span></div>
<p>which corresponds to the square sum of the corresponding field amplitudes plus the interference term. φ is the optical phase difference between the measurement signal and the reference signal. By keeping the optical phase of the reference signal constant, φ is the optical phase of the sample and therefore the quantity of interest for phase-sensitive measurements. The main idea behind modulation of the reference signal is a spectral separation of the interference term. I therefore introduced an additional modulation ϕ, which accounts for the modulation technique. In total, there are two modulation techniques manipulating exclusively the optical phase of the reference signal:</p>
<div style="margin-bottom: 10px">
<ol>
<li>Frequency-shifting</li>
<li>Phase-modulation</li>
</ol>
</div>
<p><em>Frequency-shifting</em></p>
<p>Frequency-shifting can be realized by acousto-optic modulators (AOM). The shift-frequency Δω is in the order of several MHz and a combination of two AOM is often applied for a kHz shift-frequency (<a title="Nesci et al: Quantitative amplitude and phase measurement by use of a heterodyne scanning near-field optical microscope" href="http://dx.doi.org/10.1364/OL.26.000208" target="_blank">1</a>, <a title="Sandtke et al: Novel instrument for surface plasmon polariton tracking in space and time" href="http://dx.doi.org/10.1063/1.2825463" target="_blank">2</a>). The interference term for a frequency-shifted reference signal is</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_6570'></span></div>
<p>The detection of φ and the amplitude of the measurement signal is straightforward with a lock-in amplifier that demodulates Δω. Frequency-shifting therefore creates one single interference beat oscillating at Δω. Phase-sensitive detection by frequency-shifting is known as a heterodyne detection technique.</p>
<p><em>Phase-modulation</em></p>
<p>Phase-modulation can be realized by electro-optic modulators (EOM) or piezo-electric phase modulators. Depending on the modulation device, the modulation frequency ω has a value from lower kHz up to MHz. The interference term for a phase-modulated reference signal is</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_7656'></span></div>
<p>where I introduced the angular phase modulation amplitude am, which is also known as the modulation depth or the modulation index. If I want to extract the optical amplitude and phase of the signal, I need to expand the interference signal as a Fourier series. To do so, I first use the cos(a+b) identity to separate the φ terms and then use the expansions for cos(cos) and sin(cos), which introduce lengthy Fourier series. The result is</p>
<div style="margin-bottom: 10px;margin-top: 10px"><span id='tex_8084'></span></div>
<p>The formula above should give you the following two important messages: Firstly, each sideband is a harmonic of the modulation frequency and weighted by the corresponding Bessel function evaluated at the modulation amplitude. Due to this weighting, you observe only a few low order harmonics in practice, whereas high order harmonics vanish. Secondly, the optical in-phase component &#8211; the term proportional to cos(φ) on the first line &#8211; is on even harmonics, whereas the optical quadrature component &#8211; the term proportional to sin(φ) on the second line &#8211; is on odd harmonics. As both the optical in-phase and quadrature component are needed for phase-resolved measurements, an even and an odd harmonic of the modulation frequency need to be demodulated by the lock-in amplifier. The most convenient way is to set the modulation amplitude am to 2.63 rad (e.g. 150.7°), where J1(am) = J2(am) = 0.4624, as mentioned in the application note. The first and second harmonic then have the same Bessel coefficient and are demodulated with the lock-in amplifier, which is straightforward with the HF2LI.<br />
Phase-modulation therefore creates multiple interference beats oscillating at several harmonics of the modulation frequency. Phase-sensitive detection by phase-modulation is known as pseudoheterodyne detection. The main difference to phase-sensitive heterodyne detection is that more than one beat frequency needs to be demodulated in order to extract the optical phase information.</p>
<p><strong>Does Phase-Modulation imply Pseudoheterodyne Detection?</strong></p>
<p>Based on this description, one might thinks that optical heterodyne detection is linked to frequency-shifting and pseudoheterodyne detection is linked to phase-modulation. However, this is only true with respect to interferometric phase-sensitive detection. While frequency-shifting creates only a single beat frequency, pseudoheterodyne applications for frequency-shifting do not exist. For phase-modulation on the other hand, there are numerous applications where only the first sideband is demodulated. Accordingly, these techniques are termed heterodyne detection. The outcome of these measurements is not the same as for the pseudoheterodyne detection technique described above. I give a few examples in the following, where I differentiate between interferometric techniques and non-interferometric techniques. For interferometric techniques, the formulas above are also applicable. These techniques measure the first harmonic exclusively, which corresponds to the optical quadrature component discussed above. For non-interferometric techniques, different formalisms are needed to describe oscillating components in the measured intensity.</p>
<p>An example for interferometric heterodyne detection with phase-modulation is interferometric CARS, where optical quadrature component yields the background-free vibrational absorption spectrum (<a title="Potma et al: Heterodyne coherent anti-Stokes Raman scattering (CARS) imaging" href="http://dx.doi.org/10.1364/OL.31.000241" target="_blank">3</a>). Another example for interferomtric heterodyne detection with phase modulation is the optical interferometer incorporated into AFMs to measure the cantilever oscillation (<a title="Rugar et al: Force microscope using a fiber‐optic displacement sensor " href="http://dx.doi.org/10.1063/1.1139958" target="_blank">4</a>). The cantilever movement modulates the optical phase with a very small modulation amplitude. For both examples, the phase of the reference signal needs to be adjusted for maximum sensitivity, which is when the two interfering signals are in quadrature. A third example is Pound-Drever-Hall laser stabilization (<a title="Drewer et al: Laser phase and frequency stabilization using an optical resonator " href="http://dx.doi.org/10.1007/BF00702605" target="_blank">5</a>), which creates a feedback signal based on the first phase-modulation sideband.</p>
<p>Another set of examples for heterodyne detection with phase-modulation is found in non-interferometric detection schemes. One example is FM spectroscopy, where the first sideband gives information about absorption and dispersion (<a title="Bjorklund et al: Frequency modulation (FM) spectroscopy" href="http://dx.doi.org/10.1007/BF00688820" target="_blank">6</a>).</p>
<p>While optical heterodyne detection has a counterpart in communication technology (heterodyne receiver with local oscillator), I never heard anyone from the communication community speaking about a pseudoheterodyne receiver. The term pseudoheterodyne detection is so far only used in the context of phase-resolved measurements in optics (<a title="Vaez‐Iravani et al: Phase contrast and amplitude pseudoheterodyne interference near field scanning optical microscopy" href="http://dx.doi.org/10.1063/1.108789" target="_blank">7</a>,<a title="Ocelic et al: Pseudoheterodyne detection for background-free near-field spectroscopy" href="http://dx.doi.org/10.1063/1.2348781" target="_blank">8</a>).</p>
<p><strong>References</strong></p>
<ol>
<li>A. Nesci, R. Dändliker, H. Herzig, Quantitative amplitude and phase measurement by use of a heterodyne scanning near-field optical microscope, Opt. Lett. <strong>26</strong>, 208-210 (2001)</li>
<li>M. Sandtke, R. J. P. Engelen, H. Schoenmaker, I. Attema, H. Dekker, I. Cerjak, J. P. Korterik, F. B. Segerink, L. Kuipers, Novel instrument for surface plasmon polariton tracking in space and time, Rev. Sci. Instrum. 79, 013704 (2008)</li>
<li>E. Potma, C. Evans, X. Xie, Heterodyne coherent anti-Stokes Raman scattering (CARS) imaging, Opt. Lett. 31<strong></strong>, 241-243 (2006)</li>
<li>D. Rugar, H. J. Mamin, R. Erlandsson, J. E. Stern, B. D. Terris, Force microscope using a fiber-optic displacement sensor, Rev. Sci. Instrum. 59, 2337 (1988)</li>
<li>C.G. Bjorklund, M. D. Levenson, W. Lenth, C. Ortiz, Frequency modulation (FM) spectroscopy, Applied Physics B: Lasers and Optics, Vol. 32, Nr. 3, 145 &#8211; 152 (1983)</li>
<li>R. W. P. Drever, J. L. Hall, F. V. Kowalski, J. Hough, G. M. Ford, A. J. Munley, H. Ward, Laser phase and frequency stabilization using an optical resonator, Applied Physics B: Lasers and Optics, Vol. 32, Nr. 3, 97 &#8211; 105 (1983)</li>
<li>M. Vaez-Iravani, R. Toledo-Crow, Phase contrast and amplitude pseudoheterodyne interference near field scanning optical microscopy, Appl. Phys. Lett. 62, 1044 (1993)</li>
<li>Nenad Ocelic, Andreas Huber, Rainer Hillenbrand, Pseudoheterodyne detection for background-free near-field spectroscopy, Appl. Phys. Lett. 89, 101124 (2006)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/andrin/2011/09/15/new-application-pseudoheterodyne-detection-in-optics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling Zurich Instruments Devices with LabVIEW</title>
		<link>http://www.zhinst.com/blogs/andrin/2011/09/06/controlling-zurich-instruments-devices-with-labview/</link>
		<comments>http://www.zhinst.com/blogs/andrin/2011/09/06/controlling-zurich-instruments-devices-with-labview/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 14:56:03 +0000</pubDate>
		<dc:creator>Andrin</dc:creator>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>

		<guid isPermaLink="false">http://5.5</guid>
		<description><![CDATA[With Zurich Instruments LabVIEW driver, you can integrate your device into complex laboratory setups and create your own graphical interface for simplified experiment control.The driver provides access to all adjustable parameters and measurement readings of your Instrument.<br/>
In this post, I explain on the VIs included in our LabVIEW driver and on a simple example on parameter setup and data streaming. LabVIEW beginners find a link to our Getting Started for guaranteed programming success in LabVIEW.]]></description>
			<content:encoded><![CDATA[<p>All Zurich Instruments (ZI) devices can be controlled with LabVIEW using the ziAPI driver provided in the ziBase installation. For proper executability, LabVIEW 8.2 or newer is needed. This blog entry explains the installation and wage of the LabVIEW driver.</p>
<p>The LabVIEW example described in this blog can be downloaded . Our getting started for inexperienced LabVIEW users is found . Note that both these files require a proper installation of our LabVIEW driver, as explained below.</p>
<p>Other communication interfaces are explained in <a href="http://www.zhinst.com/blogs/schwizer/2011/01/controlling-the-hf2li-lock-in-with-matlab/">Controlling the HF2LI Lock in with Matlab</a>  and in <a href="http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/">Controlling the HF2LI Lock in with Python</a>. LabVIEW has a different concept than these two languages due to its graphical programming interface, but the underlying communication scheme is similar. Since the ziControl user interface itself is based on LabVIEW, many useful functional building blocks and sophisticated examples are included in the LabVIEW driver.</p>
<p><strong>Installation</strong></p>
<p>The LabVIEW API is included in the ziBase installation, which can be downloaded from our website. To inte­grate the driver within LabVIEW, you need to extract driver.zip from API/LabVIEW in your Zurich Instru­ments program folder to the instr.lib folder in the LabVIEW program folder. After restarting Lab­VIEW, the added functions are found in LabVIEWs func­tion palette, as illustrated below.</p>
<div style="margin-bottom: 10px;">
<p style="text-align: center;"><img class="aligncenter" src="http://www.zhinst.com/blogs/andrin/files/2011/08/functions.png" alt="Function Palette" width="330" height="285" /></p>
</div>
<p><strong>The Instrument Driver Functionality</strong></p>
<p><strong></strong>The VI tree shown below depicts the drivers capabilities.</p>
<div style="margin-bottom: 10px;"><img class="alignleft size-full wp-image-15" src="http://www.zhinst.com/blogs/andrin/files/2011/08/labviewtree.png" alt="" width="893" height="393" /></div>
<p>As can be seen in the tree, ziOpen and ziClose are mandatory functions to initialize and close the connection to the Instrument. Then, there are three subgroups, whose elements are freely arrangeable to fulfill your desired measurement task.</p>
<p><em>Configuration</em></p>
<p>The configuration functions give reading and writing access to the parameters of the ZI device. This capability to define the critical parameters and settings for specific measurements directly within LabVIEW guarantees reproducible measurement conditions.</p>
<p>Besides parameter access, the configuration subgroup also provides functions to read a single instantaneous measurement value. One can choose between all possible readings of the Instrument, which are 6 demodulators, 2 analog auxiliary inputs and 1 digital input with up to 32 bits for the HF2LI. It is furthermore possible to set the values for the auxiliary outputs. For experiments requiring only a few measurement readings, these simple functions are sufficient.<strong></strong> <strong></strong></p>
<p><em>Data</em></p>
<p>The data functions stream sequential data and are essential if every measurement sample needs to be processed. To choose the input to be streamed, subscribe and unsubscribe functions are provided. Once there is a subscription, the buffered data stream is read out with ziPollData.vi. The data rate is specified by the user and high data rates up to 230kS/sec are possible. Later in this blog, there is a loop-back example which demonstrates the proper use of the subscribe and poll functions.<strong></strong></p>
<p><em>Utility</em></p>
<p>The utility functions provide a set of functions to use setting files to save/load the instrument configuration, work with multiple ZI devices, use frequency sweeping functions to measure transfer functions and perform unit conversions.</p>
<p><strong>LabVIEW Examples</strong></p>
<p>LabVIEW examples give a guideline on how the functions can be used. Upon proper installation of the driver, the examples can be found by searching for HF2 within LabVIEWs example finder. Inexperienced LabVIEW users furthermore find a getting started  for download, which uses easy to understand examples to guarantee programming success.</p>
<p><em>Loop-back Example</em></p>
<p>For demonstration purposes, I provide an example performing basic parameter setup and measurement data streaming with the HF2LI. The block diagram is shown in the figure below. If you want to explore this VI yourself, you can download it . In the following, I explain the program flow according to the text labels shown in the bottom of the block diagram.</p>
<div style="margin-bottom: 10px;">
<p style="text-align: center;"><img class="aligncenter" src="http://www.zhinst.com/blogs/andrin/files/2011/08/webexample.png" alt="Web Example" width="1216" height="283" /></p>
</div>
<p><em>Label 1 / 2: Initialize a connection / Initialize settings</em></p>
<p>The program flow starts with ziOpen, which initializes the connection to the Instrument. Thereafter, I initialize three parameters within a for loop. Within each loop iteration, one of the three node/value pairs from the array is unbundled and routed to ziSetValueDouble. This function writes the value to the parameter addressed by its node definition. Here I use the following node definitions</p>
<div style="margin-bottom: 5px;">
<table>
<tbody>
<tr>
<td width="30px"> 1.</td>
<td width="150px">oscs/0/freq</td>
<td>to set the frequency of the first oscillator to 13.5 kHz</td>
</tr>
<tr>
<td> 2.</td>
<td>sigouts/0/amplitudes/6</td>
<td>to set the output voltage of the first signal output to 1 V</td>
</tr>
<tr>
<td> 3.</td>
<td>sigouts/0/on</td>
<td>to activate the first output</td>
</tr>
</tbody>
</table>
</div>
<p>The quickest way to find out a parameters node definition is within the ziControl application. Every time you change a parameter in ziControl, you see the parameters node definition with the new value in the history bar in the bottom of the ziControl window.<strong></strong> <strong></strong></p>
<p><em>Label 3 / 4: Subscribe data node / Flush data buffer</em></p>
<p>To setup data streaming, we use ziSubscribe to get a subscription to the first demodulator channel, which is addressed by demods/0/sample. Before reading data, ziFlush is used to remove any old data from the buffer.<strong></strong></p>
<p><em>Label  5: Poll and plot data</em></p>
<p><strong></strong>In the subsequent poll loop, data is continuously read  from the ziServer buffer and plotted in the graph. If the buffer has no new data upon request, ziPollData waits for new data until the specified timeout expires, which is here set to 100 ms. Such cases only occur with slow sample rates and it is recommended to always guarantee functionality of your program by adding a case structure that treats a possible timeout event. In the current example, this case structure is labeled with Timeout? and assures that no data is plotted in case of a timeout. As can be seen inside the case structure, each measurement sample read by ziPollData contains the following records:</p>
<div style="margin-bottom: 5px;">
<table>
<tbody>
<tr>
<td width="30px"> 1.</td>
<td width="150px">Timestamp (ticks)</td>
<td>Sample timestamp in ticks. ziTicks2S converts ticks into seconds</td>
</tr>
<tr>
<td> 2.</td>
<td>X (Vrms)</td>
<td>Demodulator RMS reading of the in-phase signal (X)</td>
</tr>
<tr>
<td> 3.</td>
<td>Y (Vrms)</td>
<td>Demodulator RMS reading of the quadrature signal (Y)</td>
</tr>
<tr>
<td> 4.</td>
<td>Osc. Phase (deg)</td>
<td>Actual phase of the demodulation oscillator</td>
</tr>
<tr>
<td> 5.</td>
<td>Freq (Hz)</td>
<td>Frequency of the demodulation oscillator</td>
</tr>
<tr>
<td> 6.</td>
<td>DIO</td>
<td>Digital input reading</td>
</tr>
<tr>
<td> 7.</td>
<td>Aux In 0 (V)</td>
<td>Auxiliary input 0 reading</td>
</tr>
<tr>
<td> 8.</td>
<td>Aux In 1 (V)</td>
<td>Auxiliary input 1 reading</td>
</tr>
</tbody>
</table>
</div>
<p>In this basic example, I only use the demodulators X and Y reading to calculate and plot the corresponding absolute value.<strong></strong> <strong></strong></p>
<p><em>Label 6: Close the connection</em></p>
<p>At the end of the program, ziClose closes the connection to the device.</p>
<p><em>Loop-back Measurement</em></p>
<p>If I physically feed the output signal back to the input, I perform a simple loop-back experiment. If I then run the example program, the front panel appears as shown below. The data graph correctly shows a straight line corresponding to the RMS value of 1/√2. To avoid remaining open connections to the Instrument, program execution must be aborted with the STOP button instead of LabVIEWs own abort button. Otherwise, too many unclosed connections left in the memory could hamper your computing performance and a LabVIEW restart is needed to release the occupied memory.</p>
<div style="margin-bottom: 10px;"><img src="http://www.zhinst.com/blogs/andrin/files/2011/08/loopback_frontpanel.png" alt="Loopback Measurement" /></div>
<p><strong>LabVIEW Driver Summary</strong></p>
<p>Altogether the LabVIEW driver offers you far reaching possibilities towards measurement automation and measurement reproducibility due to the following features<strong></strong></p>
<ol style="margin-bottom: 10px;">
<li>Full control over instrument parameters</li>
<li>Fast measurement data streaming</li>
<li>Flexible interface to control complex measurements</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/andrin/2011/09/06/controlling-zurich-instruments-devices-with-labview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling the HF2LI Lock-in with Python</title>
		<link>http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/</link>
		<comments>http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/#comments</comments>
		<pubDate>Wed, 04 May 2011 14:45:20 +0000</pubDate>
		<dc:creator>Lara Juricic</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ZI Interfaces]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://2.568</guid>
		<description><![CDATA[This blog entry contains a basic example how to communicate with HF2LI Lock-in using the Python programming language. This is achieved with an interface library of Zurich Instruments that transforms the ziAPI into a native Python interface.]]></description>
			<content:encoded><![CDATA[<p>The Zurich Instruments device can be controlled with any programming language that can interface to a dynamically loaded (on Windows) or shared (on Linux) library. This blog entry contains a basic example how to communicate with HF2LI Lock-in using the Python programming language. This is achieved with an interface library of Zurich Instruments that transforms the ziAPI into a native Python interface, subsequently named ziPython.</p>
<p>Communication with HF2LI Lock-in using Matlab is explained in <a href="http://www.zhinst.com/blogs/schwizer/2011/01/controlling-the-hf2li-lock-in-with-matlab/">Controlling the HF2LI Lock in with Matlab.</a>. These two libraries share most of the code and are thus very similar in usage. </p>
<h3>Zurich Instruments Python Interface Installation</h3>
<p>Currently, Python 2.6x is supported. It&#8217;s recommend to install this Python version from <a href="http://www.python.org">Python programming language official website</a>. The ziPython package containing the interface to control the HF2LI Lock-in from Python can be downloaded from <a href="http://www.zhinst.com/downloads">the Zurich Instruments download page</a>. Please use your Zurich Instruments login to get access to the download area.</p>
<p>To install the package on Windows execute the installer. It will guide you through the installation process as displayed in the following screen shots.</p>
<p><a rel="attachment wp-att-865" href="http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/f/"><img class="alignnone size-full wp-image-865" src="http://www.zhinst.com/blogs/schwizer/files/2011/04/f.png" alt="" width="546" height="358" /></a></p>
<p>After clicking on the Next button, the existing Python installation can be selected. The package will be installed in the folder &#8230;Python26Libsite-packageszhinst.</p>
<p><a rel="attachment wp-att-597" href="http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/second/"><img class="alignnone size-full wp-image-597" src="http://www.zhinst.com/blogs/schwizer/files/2011/04/second.png" alt="" width="546" height="358" /></a></p>
<p>The interface will use numpy for fast data transfer. Therefore, the package <a href="http://numpy.scipy.org/">NumPy</a> is required. To run the example code the <a href="http://matplotlib.sourceforge.net/">matplotlib</a> library needs to be installed as well. Unofficial 64bit precompiled packages of both modules can be found on the page of <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">Christoph Gohlke</a>.</p>
<p>After installation, we are ready to run the first Python script controlling the HF2 Lock-in amplifier.</p>
<h3>Simple Loop-back Measurement with the HF2LI Lock-in</h3>
<p>During a loop-back measurement we generate a signal and measure the signal with the HF2LI Lock-in. Thus, connect the Signal Output 1 Out to Signal Input 1 +In with a BNC cable. The HF2LI Lock-in is connected to the computer with a USB 2.0 cable. The ziServer should be running on the computer where the instrument is connected to. It is automatically started if the Zurich Instruments driver ziBase was installed beforehand. To check whether a server is running, check in the Windows Task Manager for the processes ziSrv01.exe and ziStrt01.exe. On Linux the process name is ziServer64 or ziServer32 for 64bit or 32bit systems, respectively.</p>
<p>The package ziPython contains two modules <code>zhinst.ziPython</code> and <code>zhinst.utils</code>. The module <code>zhinst.ziPython</code> provides all classes for interfacing to the ziServer which is communicating with the HF2LI Lock-in. The class <code>ziDAQServer</code> provides methods that access the device with synchronous calls. This methods block during execution.<br />
The module <code>zhinst.utils</code> contains helper functions to provide code for often performed tasks. In the example below we use the method <code>autoDetect</code> to read the name of the HF2LI Lock-in device currently connected to the ziServer.<br />
Download the file  .</p>
<p><code><span class="command">import</span> zhinst.ziPython, zhinst.utils<br />
<span class="command">from</span> numpy <span class="command">import</span> *<br />
<span class="command">import</span> time<br />
<span class="comment"># Open connection to ziServer</span><br />
daq = zhinst.ziPython.ziDAQServer(<span class="string">'localhost'</span>, 8005)<br />
<span class="comment"># Detect device</span><br />
device = zhinst.utils.autoDetect()<br />
<span class="comment">#Record one demodulator sample from the specified node</span><br />
sample = daq.getSample(<span class="string">'/'</span>+device+<span class="string">'/demods/0/sample'</span>)<br />
r = sqrt(sample[<span class="string">'x'</span>]**2+sample[<span class="string">'y'</span>]**2)<br />
<span class="command">print</span> <span class="string">'Measured rms amplitude is %fV.'</span> % r</code></p>
<p>After running this script, measured rms amplitude is zero because the output channel is not enabled.</p>
<h3>Changing Device Settings </h3>
<p>Switching the output channel on and setting the amplitude of the output signal to 100 mV using the ziControl interface, the measured rms amplitude after running the same example will be around 70.7 mV. Because the ziServer manages all communication between the HF2LI amplifier and all programs (clients) that access the HF2LI, it&#8217;s possible to control HF2LI device with user programs and ziControl simultaneously. The ziServer keeps track of all the setting changes and sends update changes to the other applications.</p>
<p>There are two methods for changing device settings with Python. The first approach is using <code>setInt(...), setDouble(...), setByte(...)</code> methods. This methods receive as argument a path string of the node and the node value. In a multi-threaded environment the Python interpreter uses a global lock, called Global Interpreter Lock (GIL), that synchronizes the code execution of the different Python threads. Only one thread that has acquired the GIL may operate on Python objects. This serialization process may slow down program execution in the multi-thread environment if many set commands are executed in sequence. For performance reasons it is thus an advantage to collect all settings in a list and the set all at once. During that set command execution the GIL is released by ziPython. This allows the Python interpreter to execute code from other threads simultaneously.<br />
The following   gives an example of single <code>setInt(...), setDouble(...), and setByte(...)</code> commands. The ziPython interface performs an implicit conversion between double and integer if needed. Thus, for most settings the precision is accurate enough to use either of them.</p>
<pre><code><span class="command">import</span> zhinst.ziPython, zhinst.utils
<span class="command">from</span> numpy <span class="command">import</span> *
<span class="command">import</span> time
<span class="comment"># Open connection to ziServer</span>
daq = zhinst.ziPython.ziDAQServer(<span class="string">'localhost'</span>, 8005)
<span class="comment"># Detect device</span>
device = zhinst.utils.autoDetect()
<span class="comment">#set the amplitude of output channel 1 to 100mV</span>
daq.setDouble(<span class="string">'/'</span> + device + <span class="string">'/sigouts/0/amplitudes/0'</span>, 0.1);
<span class="comment">#set the enable output channel</span>
daq.setDouble(<span class="string">'/'</span> + device + <span class="string">'/sigouts/0/enables/0'</span>, 1);
<span class="comment">#turn on output channel</span>
daq.setInt(<span class="string">'/'</span> + device + <span class="string">'/sigouts/0/on'</span>, 1);
<span class="comment"># wait 1s</span>
time.sleep(1)
<span class="comment">#Record one demodulator sample from the specified node</span>
sample = daq.getSample(<span class="string">'/'</span>+device+<span class="string">'/demods/0/sample'</span>)
r = sqrt(sample[<span class="string">'x'</span>]**2+sample[<span class="string">'y'</span>]**2)
<span class="command">print</span> <span class="string">'Measured rms amplitude is %fV.'</span> % r</code></pre>
<p>From the point of view of program execution time if it&#8217;s needed to change more settings, it&#8217;s better to use <code>set</code> command. That method receives as argument a list with elements <code>[[node_path], set_value]</code>. The next example uses the <code>set</code> command to change settings of the HF2LI Lock-in amplifier.</p>
<p>It&#8217;s convenient to use the ziControl to find out path strings of the nodes. If you change a setting using the ziControl, the command line display (located at the bottom of the ziControl interface) will show the command that was sent to the instrument in a format <code>node_path : set_value</code>.</p>
<h3>Polling Demodulator Data</h3>
<p>If continuous data recording is performed polling functions are best suited. To select the nodes from which data should be polled, the subscribe / unsubscribe commands are used. The following example demonstrates the synchronous poll usage. Thus, the poll command will block during the specified recording time. Due to the blocking behavior, too long recording times should be avoided as the interface is not responsive within that time.</p>
<p>For recoding times longer than 10s it is recommended to used the poll command inside a loop. With this method continuous data can be recorded over a longer time frame. Internal data buffering on the ziServer ensures that no data is lost between the poll commands. As these buffers are limited in size, the time between poll commands must not be too large for high sampling rates. If extensive calculations should be performed during the poll commands, the asynchronous poll interface might be better suited.<br />
Download the file .</p>
<pre><code><span class="command">import</span> time, math
<span class="command">import</span> zhinst.ziPython, zhinst.utils
<span class="command">import</span> matplotlib
<span class="command">import</span> matplotlib.pyplot <span class="command">as</span> plt
<span class="command">from</span> numpy <span class="command">import</span> *
<span class="command">def</span> <span class="function">measureSynchronousFeedback</span>(daq, device, channel, frequency):
   c=str(channel-1)
   amplitude=1
   rate=200
   tc=0.01
   <span class="comment"># Disable all outputs and all demods</span>
   general_setting = [
        [[<span class="string">'/'</span>, device, <span class="string">'/demods/0/trigger'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/demods/1/trigger'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/demods/2/trigger'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/demods/3/trigger'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/demods/4/trigger'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/demods/5/trigger'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/0/enables/*'</span>], 0],
        [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/1/enables/*'</span>], 0]
   ]
   daq.set(general_setting)
   <span class="comment"># Set test settings</span>
   t1_sigOutIn_setting = [
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/'</span>,c,<span class="string">'/diff'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/'</span>,c,<span class="string">'/imp50'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/'</span>,c,<span class="string">'/ac'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigins/'</span>,c,<span class="string">'/range'</span>], 2],
       [[<span class="string">'/'</span>, device, <span class="string">'/demods/'</span>,c,<span class="string">'/order'</span>], 8],
       [[<span class="string">'/'</span>, device, <span class="string">'/demods/'</span>,c,<span class="string">'/timeconstant'</span>], tc],
       [[<span class="string">'/'</span>, device, <span class="string">'/demods/'</span>,c,<span class="string">'/rate'</span>], rate],
       [[<span class="string">'/'</span>, device, <span class="string">'/demods/'</span>,c,<span class="string">'/adcselect'</span>], channel-1],
       [[<span class="string">'/'</span>, device, <span class="string">'/demods/'</span>,c,<span class="string">'/oscselect'</span>], channel-1],
       [[<span class="string">'/'</span>, device, <span class="string">'/demods/'</span>,c,<span class="string">'/harmonic'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/oscs/'</span>,c,<span class="string">'/freq'</span>], frequency],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/'</span>,c,<span class="string">'/add'</span>], 0],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/'</span>,c,<span class="string">'/on'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/'</span>,c,<span class="string">'/enables/'</span>,c], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/'</span>,c,<span class="string">'/range'</span>], 1],
       [[<span class="string">'/'</span>, device, <span class="string">'/sigouts/'</span>,c,<span class="string">'/amplitudes/'</span>,c], amplitude],
   ]
   daq.set(t1_sigOutIn_setting);
   <span class="comment"># wait 1s to get a settled lowpass filter</span>
   time.sleep(1)
   <span class="comment">#clean queue</span>
   daq.flush()
   <span class="comment"># Subscribe to scope</span>
   path0 = <span class="string">'/'</span> + device + <span class="string">'/demods/'</span>,c,<span class="string">'/sample'</span>
   daq.subscribe(path0)
   <span class="comment"># Poll data 1s, second parameter is poll timeout in [ms]  </span>
   <span class="comment"># (recomended value is 500ms) </span>
   dataDict = daq.poll(1,500);
   <span class="comment"># Unsubscribe to scope</span>
   daq.unsubscribe(path0)
   <span class="comment"># Recreate data</span>
   if device in dataDict:
       if dataDict[device][<span class="string">'demods'</span>][c][<span class="string">'sample'</span>][0][<span class="string">'time'</span>][<span class="string">'dataloss'</span>]:
           <span class="command">print</span> <span class="string">'Sample loss detected.'</span>
       else:
           e=0.5*amplitude/sqrt(2)
           data = dataDict[device][<span class="string">'demods'</span>][c][<span class="string">'sample'</span>][0]
           rdata = sqrt(data[<span class="string">'x'</span>]**2+data[<span class="string">'y'</span>]**2)
           <span class="command">print</span> <span class="string">'Measured rms amplitude is %.5fV (expected: %.5fV).'</span> %(mean(rdata),e)
           tdata= (data[<span class="string">'timestamp'</span>]-data[<span class="string">'timestamp'</span>][0])/210e6
           <span class="comment"># Create plot </span>
           plt.figure(channel)
           plt.grid(True)
           plt.plot(tdata,rdata)
           plt.title(<span class="string">'Demodulator data'</span>)
           plt.xlabel(<span class="string">'Time (s)'</span>)
           plt.ylabel(<span class="string">' R component (V)'</span>)
           plt.axis([tdata[0],tdata[-1],0.97*e,1.03*e])
           plt.show()
<span class="comment"># Open connection to ziServer</span>
daq = zhinst.ziPython.ziDAQServer(<span class="string">'localhost'</span>, 8005)
<span class="comment"># Detect device</span>
device = zhinst.utils.autoDetect()
measureSynchronousFeedback(daq, device, 1, 1e5);
</code></pre>
<p>The method <code>ziDAQServer</code> creates an instance of the ziServer you are connecting to. The <code>poll</code> method of this object returns data of all subscribed nodes in the Python dict data type. In the previous example values of the following nodes have been received.</p>
<pre><code>data[<span class="string">'timestamp'</span>] <span class="comment"># Time stamp data [uint64]. Divide value by 210e6 to</span>
<span class="comment"># calculate the time stamp in seconds.</span>
data[<span class="string">'x'</span>] <span class="comment"># Demodulator x value in volt [double]</span>
data[<span class="string">'y'</span>] <span class="comment"># Demodulator y value in volt [double]</span>
data[<span class="string">'frequency'</span>] <span class="comment"># Current demodulator frequency in hertz [double].</span>
data[<span class="string">'phase'</span>] <span class="comment"># Phase value [double].</span>
data[<span class="string">'dio'</span>] <span class="comment"># Digital IO data [uint32].</span>
data[<span class="string">'auxin0'</span>] <span class="comment"># Auxiliary input value of channel 0 in volt [double].</span>
data[<span class="string">'auxin1'</span>] <span class="comment"># Auxiliary input value of channel 1 in volt [double].</span>
data[<span class="string">'time'</span>][<span class="string">'dataloss '</span>] <span class="comment"># Indication of sample loss (including block loss).</span>
data[<span class="string">'time'</span>][<span class="string">'blockloss '</span>] <span class="comment"># Indication of data block loss over the socket</span>
<span class="comment"># connection. This may be the result of a too long break between subsequent</span>
<span class="comment"># poll commands.</span>
data[<span class="string">'time'</span>][<span class="string">'invalidtimestamp '</span>] <span class="comment"># Indication of invalid time stamp data</span>
<span class="comment"># as a result of a sampling rate change during the measurement.</span>
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/schwizer/2011/05/controlling-the-hf2-li-lock-in-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling the HF2LI Lock-in with Matlab</title>
		<link>http://www.zhinst.com/blogs/schwizer/2011/01/controlling-the-hf2li-lock-in-with-matlab/</link>
		<comments>http://www.zhinst.com/blogs/schwizer/2011/01/controlling-the-hf2li-lock-in-with-matlab/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 10:33:25 +0000</pubDate>
		<dc:creator>Jürg Schwizer</dc:creator>
				<category><![CDATA[Matlab]]></category>
		<category><![CDATA[ZI Interfaces]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[ziDAQ]]></category>

		<guid isPermaLink="false">http://2.397</guid>
		<description><![CDATA[Controlling the Zurich Instruments device directly with Matlab is extremely powerful for repetitive measurements and scripting. This blog entry explains a method to communicate with the ziServer directly from Matlab. This interface is very fast and thus well suited to record large data sets at high-speed.]]></description>
			<content:encoded><![CDATA[<p>Controlling the Zurich Instruments device directly with Matlab is extremely powerful for repetitive measurements and scripting. This blog entry explains a method to communicate with the ziServer directly from Matlab. This interface is very fast and thus well suited to record large data sets at high-speed.<br />
Loading data from a binary file is explained in the blog entry <a href="http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/">http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/</a>.</p>
<h3>Simple Loop-back Measurement with the Instrument</h3>
<p>To perform the measurement connect the HF output of your instrument with the HF input with a short BNC cable. This routes the output signal back to the input of the instrument. Also connect your Zurich Instruments HF2LI device with a USB cable to a computer with the ziServer running. The ziServer is automatically started if the Zurich Instruments driver was installed beforehand.</p>
<p>Next you need to install the Matlab driver ziDAQ for the instrument. You can get the latest version by supplying following information in a support request:</p>
<ul>
<li>Matlab version e.g 7.6</li>
<li>Matlab processor architecture e.g. 64Bit (win64)</li>
<li>Operating system e.g. Windows 7</li>
</ul>
<p>The appropriate DLL driver (e.g. ziDAQ.mexw64) needs to be copied in the local directory you are working in. Or you also may add the driver directory to your Matlab path (type <code>help path</code> in Matlab).</p>
<p>Now you are ready to start the example in Matlab.</p>
<p>The interface to the Zurich Instruments lock-in amplifier is based on the function call <code>ziDAQ</code>. The first parameter is used to specify the interface functionality that should be executed. Use the command <code>help ziDAQ</code> to get a help text on all available commands.<br />
The simplest method of accessing demodulator data offers the function call <code>ziDAQ(<span class="string">'getSample'</span>,...)</code>. This function call returns a single sample from the specified demodulator path. Download the file .</p>
<p><code><span class="command">function</span> simple_example<br />
clear ziDAQ<br />
ziDAQ(<span class="string">'connect'</span>);<br />
device = autoDetect;<br />
<span class="comment">% Record one demodulator sample from the specified node.</span><br />
sample = ziDAQ(<span class="string">'getSample'</span>, [<span class="string">'/'</span> device <span class="string">'/demods/0/sample'</span>]);<br />
<span class="comment">% Calculate r from x and y.</span><br />
r = sqrt(sample.x.^2 + sample.y.^2);<br />
fprintf(<span class="string">'Measured rms amplitude %gVn'</span>, r);</code></p>
<p>In order to select the connected device automatically, the following helper function should be copied in the working directory. The function assumes, that only one device is connected to the computer. Download the file .</p>
<p><code><span class="command">function</span> device = autoDetect<br />
nodes = lower(ziDAQ(<span class="string">'listNodes'</span>, <span class="string">'/'</span>));<br />
dutIndex = strmatch(<span class="string">'dev'</span>, nodes);<br />
if length(dutIndex) &gt; 1<br />
error(<span class="string">'autoDetect does only support a single device configuration.'</span>);<br />
elseif isempty(dutIndex)<br />
error(<span class="string">'No DUT found. Make sure that the USB cable is connected to the host and the device is turned on.'</span>);<br />
end<br />
<span class="comment">% Found only one device -&gt; selection valid.</span><br />
device = lower(nodes{dutIndex});<br />
fprintf(<span class="string">'Will perform measurement for device %s ...n'</span>, device)</code></p>
<h3>Polling Demodulator Data</h3>
<p>If continuous data recording is required the polling functions are best suited. To select the nodes from which data should be polled, the subscribe / unsubscribe commands are used. The following example demonstrates the synchronous poll usage. Thus, the poll command will block during the specified recording time. Due to the blocking behavior, too long recording times should be avoided as the interface is not responsive during that time.<br />
For recoding times longer than 10s it is recommended to used the poll command inside a loop. With this method continuous data can be recorded over a longer time frame. Internal data buffering on the ziServer ensures that no data is lost between the poll commands. As these buffers are limited in size, the time between poll commands must not be too large for high sampling rates. If extensive calculations should be performed during the poll commands, the asynchronous poll interface may be better suited.<br />
Download the file .</p>
<p><code><span class="command">function</span> synchronous_example<br />
clear ziDAQ<br />
ziDAQ(<span class="string">'connect'</span>);<br />
device = autoDetect;<br />
measureSynchronousFeedback(device, 1, 1e5);</code></p>
<p><code><span class="command">function</span> measureSynchronousFeedback(device, channel, frequency)<br />
c = num2str(channel - 1, <span class="string">'%0d'</span>);<br />
<span class="comment">% Settings</span><br />
rate = 200;<br />
tc = 0.001;<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/sigins/'</span> c <span class="string">'/imp50'</span>], int64(1));<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/sigins/'</span> c <span class="string">'/ac'</span>], int64(0));<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/sigins/'</span> c <span class="string">'/diff'</span>], int64(0));<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/sigins/'</span> c <span class="string">'/range'</span>], 2);<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/sigouts/'</span> c <span class="string">'/on'</span>], int64(1));<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/sigouts/'</span> c <span class="string">'/enables/'</span> c], int64(1));<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/sigouts/'</span> c <span class="string">'/add'</span>], int64(0));<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/sigouts/'</span> c <span class="string">'/range'</span>], 1);<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/sigouts/'</span> c <span class="string">'/amplitudes/*'</span>], 0);<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/sigouts/'</span> c <span class="string">'/amplitudes/'</span> c], 1);<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/rate'</span>], rate);<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/phaseshift'</span>], 0);<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/order/'</span>], int64(8));<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/harmonic/'</span>], int64(1));<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/adcselect/'</span>], int64(channel - 1));<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/timeconstant'</span>], tc);<br />
ziDAQ('setInt',[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/oscselect'</span>], int64(channel - 1));<br />
ziDAQ('setDouble',[<span class="string">'/'</span> device <span class="string">'/oscs/'</span> c <span class="string">'/freq'</span>], frequency);<br />
<span class="comment">% Unsubscribe all streaming data</span><br />
ziDAQ(<span class="string">'unsubscribe'</span>, <span class="string">'*'</span>);<br />
<span class="comment">% Clean queue</span><br />
ziDAQ(<span class="string">'flush'</span>);<br />
<span class="comment">% Pause to get a settled lowpass filter</span><br />
pause(10*tc);<br />
ziDAQ(<span class="string">'subscribe'</span>,[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/sample'</span>]);<br />
d = ziDAQ(<span class="string">'poll'</span>, 1, int64(200));<br />
ziDAQ(<span class="string">'unsubscribe'</span>,[<span class="string">'/'</span> device <span class="string">'/demods/'</span> c <span class="string">'/sample'</span>]);<br />
if ~isempty(d)<br />
device = getfield(d, device);<br />
if device.demods(channel).sample.time.dataloss<br />
fprintf(<span class="string">'Sample loss detected.'</span>);<br />
end<br />
r = mean(sqrt(device.demods(channel).sample.x.^2 + device.demods(channel).sample.y.^2));<br />
end<br />
e = 0.5 / sqrt(2);<br />
fprintf(<span class="string">'Measured rms amplitude %gV (expected: %gV)n'</span>, r, e);</code></p>
<p>The function call <code>ziDAQ(<span class="string">'poll'</span>, ...)</code> returns the following data structure.</p>
<p><code>sample.timestamp <span class="comment">% Time stamp data [uint64]. Divide value by 210e6 to calculate the time stamp in seconds.</span><br />
sample.x <span class="comment">% Demodulator x value in volt [double]</span><br />
sample.y <span class="comment">% Demodulator y value in volt [double]</span><br />
sample.frequency <span class="comment">% Current demodulator frequency in hertz [double].</span><br />
sample.phase <span class="comment">% Phase value [double].</span><br />
sample.dio <span class="comment">% Digital IO data [uint32].</span><br />
sample.auxin0 <span class="comment">% Auxiliary input value of channel 0 in volt [double].</span><br />
sample.auxin1 <span class="comment">% Auxiliary input value of channel 1 in volt [double].</span><br />
sample.time.dataloss <span class="comment">% Indication of sample loss (including block loss).</span><br />
sample.time.blockloss <span class="comment">% Indication of data block loss over the socket connection. This may be the result of a too long break between subsequent poll commands.</span><br />
sample.time.invalidtimestamp <span class="comment">% Indication of invalid time stamp data as a result of a sampling rate change during the measurement.</span><br />
</code></p>
<p>Vectors that contain NaN&#8217;s indicate sample loss. In this case the <code>sample.time.dataloss</code> flag is set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/schwizer/2011/01/controlling-the-hf2li-lock-in-with-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading HF2LI Lock-in Measurements with Matlab</title>
		<link>http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/</link>
		<comments>http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 10:52:39 +0000</pubDate>
		<dc:creator>Jürg Schwizer</dc:creator>
				<category><![CDATA[Matlab]]></category>
		<category><![CDATA[ZI Interfaces]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[HF2LI]]></category>
		<category><![CDATA[lock-in]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[ziControl]]></category>

		<guid isPermaLink="false">http://2.340</guid>
		<description><![CDATA[The combination of Zurich Instruments devices and Matlab is a powerful tool set to get your application measured. In a first step I show a method to load the demodulator data of the Zurich Instruments HF2LI lock-in amplifier into the Matlab workspace. This approach uses the graphical user interface of the HF2LI to save the data in binary format. In a later blog entry a will show another method which allows for direct control of the HF2LI from Matlab. This enables scripting and recording of large measurement data sets.]]></description>
			<content:encoded><![CDATA[<p>The combination of Zurich Instruments devices and Matlab is a powerful tool set to get your application measured. In a first step I show a method to load the demodulator data of the Zurich Instruments HF2LI lock-in amplifier into the Matlab workspace. This approach uses the graphical user interface of the HF2LI to save the data in binary format. In a later blog entry a will show another method which allows for direct control of the HF2LI from Matlab. This enables scripting and recording of large measurement data sets.</p>
<h3>Using the HF2LI Graphical User Interface <a href="http://www.zhinst.com/products/hf2software/is">ziControl</a></h3>
<p>Loading the data from a file is a simple and fast approach. It is well suited if you would like to share the data between different applications.</p>
<p>It is best to save the data in binary format. Therefore, make sure that the check box <span class="guielement">Binary Save</span> is enabled. Then press the <span class="guielement">Save</span> button to start the measurement. This should save binary files with file extension *.ziBin into the specified directory.</p>
<div id="attachment_362" class="wp-caption alignnone" style="width: 470px"><a href="http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/save_binary_data_zicontrol/" rel="attachment wp-att-362"><img class="size-full wp-image-362" src="http://www.zhinst.com/blogs/schwizer/files/2010/12/save_binary_data_zicontrol.png" alt="Saving measurement data with the ziControl" width="460" height="247" /></a><p class="wp-caption-text">Saving measurement data with the ziControl</p></div>
<h3>Loading the Binary Data in Matlab</h3>
<p>To load the measurement files we use a helper function which loads the file content into a structure. Download the file .</p>
<p><code><span class="command">function</span> data = ziLoad(file)<br />
<span class="comment">% Loads the measurement data from a ziBin file<br />
% E.g data = ziLoad('Freq1.ziBin');</span><br />
fid = fopen(file, <span class="string">'r'</span>, <span class="string">'ieee-be'</span>);<br />
if fid == -1<br />
error([<span class="string">'File '</span> file <span class="string">' not found.'</span>]);<br />
end<br />
raw = fread(fid, inf, <span class="string">'*double'</span>);<br />
if mod(length(raw), 7) ~= 0<br />
error(<span class="string">'Illegal file size of ziBin file detected.'</span>);<br />
end<br />
data.timestamp = raw(1:7:end);<br />
data.x = raw(2:7:end);<br />
data.y = raw(3:7:end);<br />
data.frequency = raw(4:7:end);<br />
data.bits = uint32(raw(5:7:end));<br />
data.auxin0 = raw(6:7:end);<br />
data.auxin1 = raw(7:7:end);<br />
fclose(fid);</code></p>
<p>To load the data in Matlab you just call the function ziLoad in Matlab.</p>
<p><code><span class="comment">% Load the measurement data of demodulator 1 into a structure</span><br />
data = ziLoad(<span class="string">'mydata/Freq1.ziBin'</span>);</code></p>
<p>Now the data is found on the workspace. It is a structure array with following fields.</p>
<p><code>data =<br />
timestamp: [2855x1 double]<br />
x: [2855x1 double]<br />
y: [2855x1 double]<br />
frequency: [2855x1 double]<br />
bits: [2855x1 uint32]<br />
auxin0: [2855x1 double]<br />
auxin1: [2855x1 double]</code></p>
<p>Now we plot R over recording time. The plot2svg function can be downloaded <a href="http://www.zhinst.com/blogs/schwizer/2009/08/scalable-vector-graphics-svg-export-of-figures-from-matlab/">here</a>.</p>
<p><code>s = plot(data.timestamp - data.timestamp(1), ...<br />
sqrt(data.x.^2 + data.y.^2) * 1e9, <span class="string">'black'</span>);<br />
<span class="comment">% Format the plot</span><br />
set(s, <span class="string">'LineWidth'</span>, 2);<br />
xlabel(<span class="string">'Time [s]'</span>);<br />
ylabel(<span class="string">'Voltage R [nV]'</span>)<br />
box on<br />
grid on<br />
<span class="comment">% Save the plot as Scalable Vector Graphics (SVG)</span><br />
plot2svg(<span class="string">'my_first_lockin_measurement.svg'</span>)</code></p>
<div id="attachment_392" class="wp-caption alignnone" style="width: 501px"><a href="http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/my_first_lockin_measurement/" rel="attachment wp-att-392"><img class="size-full wp-image-392" src="http://www.zhinst.com/blogs/schwizer/files/2010/12/my_first_lockin_measurement.png" alt="R recorded with Zurich Instruments HF2LI" width="491" height="265" /></a><p class="wp-caption-text">R recorded with Zurich Instruments HF2LI</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.zhinst.com/blogs/schwizer/2010/12/loading-hf2-lock-in-measurements-with-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

