CHM 598 - Starting from Raw FID data and Ending Up with a Processed NMR Spectrum

Prof. Yarger - Methods in Magnetic Resonance

Hands-On part to Lecture #15

(The examples are done on a Intel Mac, Os X system. Red is my input. Blue is the computers responce. Black is a comment)


First, logon one of the iMac computers (as Chemistry 598)

(username and password)

When you are on a Varian spectrometer and using vnmr, you can save the FID in ascii format using the command 'writefid' and you can save the spectrum in ascii format using a Varian macro called either 'writexy' or 'writespec'. Also, remember that you can save your FID in Varian binary format using the command 'svf'

So, lets put Ethanol in CDCl3 and throw this in the 200 MHz NMR. We will lock, shim and run a 1D (bloch decay) 1H NMR experiment. The VNMR experimental parameters can be shown by typing dg:

The FID can be shown by typing df:

We can set the line broadening to 1 Hz (lb=1) and do a weighted FT (wft):

Now, we can save the data in either ascii or binary-varian format.

svf('etoh_fid') - saves the FID in binary Varian format..... specifically, creating a directory named etoh_fid.fid with 4 files (fid, log, procpar and text).

writefid('etoh_fid') - writes the FID in ascii format. The format is real - imaginary intensities (no time axis)

writexy - creates two files, trace.1 and xytrace.1 - The files are typically written in ~/vnmrsys/exp#/

So, move the xytrace.1 and trace.1 files to your home directory and name it etoh_trace and etoh_xytrace. (example, mv xytrace.1 ~/CHM598/etoh_trace)

Now, we have a full set of ascii spectra, FID and original FID data!!!

(If you are familiar with getting ascii data in and out of matlab and just want to have the matlab file to play around with.... Click here: etoh_processing.mat)

Get them onto the computer you are using.... The data is currently on in the Gemini account on the 200 MHz NMR Sun computer (192.168.1.2).

Use the VPN to connect to the internal 192.168. internet addresses. Then download the data (etoh_fid.fid, etoh_fid, etoh_trace, etoh_xytrace).

All this data is archived in zip format here. Or each data file: etoh_fid, etoh_trace and etoh_xytrace. Also, the original varian data: etoh_fid.fid

We now have ALL FIDs and SPECTRA in ASCII Format and can import this data into any common scientific software for further analysis, plotting and presentation.


As an example, lets load this data in Matlab. Because we are using intel Mac's and we don't have the latest intel Mac Java patch, we are going to do this in no jvm mode.

So, start up and xterm: Applications > Utilities > X11 > xterm

It also helps to customize the xterm so you can cut and paste into the xterm. I recommend the following .Xdefaults file. (.Xdefaults). Specifically, you need to add some Meta key functions to make the xterm behave more like the standard Terminal window (Xdefault ascii text file):

Store all data in a directory named NMR (/Users/chm598/Desktop/NMR)

Now, lets start Matlab (and if you are using my .Xdefaults it will look like):

chm598$ cd /Applications/MATLAB73/bin

chm598$ ./matlab -nojvm

Now this xterm window should be a Matlab workspace:

>> cd /Users/chm598/Desktop/NMR

>> ls

etoh.zip etoh_fid etoh_fid.fid etoh_trace etoh_xytrace

>> load etoh_fid;

>> whos

Name Size Bytes Class

ans 1x26 52 char array
etoh_fid 8192x2 131072 double array

Grand total is 16410 elements using 131124 bytes

>> x=[1:1:8192]';

I loaded the ascii FID data. I viewed the loaded data (whos) and I created an x-axis of points (x=[1:1:8192]')

>> plot(x,etoh_fid(:,1));

This should produce a figure that looks like:

The y-axis is the real part of the FID and the x-axis is 'points'. You should also plot the imaginary data.... Is it 90-degree phase shifted??

Before we can process the FID, we need to combine the data into a standard complex data set.

>> fid=etoh_fid(:,1)+i*etoh_fid(:,2);

>> whos

Name Size Bytes Class

ans 1x63 126 char array
etoh_fid 8192x2 131072 double array
fid 8192x1 131072 double array (complex)
x 8192x1 65536 double array

Grand total is 32831 elements using 327806 bytes

So, now we could generate the same plot as above by typing:

>> plot(x,real(fid));

Using the data from dg (above), we can generate the correct x-axis in time and frequency. Lets start with making a correct x-axis for the FID plot.

>> sfrq=199.976e6; at=2.73039; np=16384; sw=3000.3; dt=1/sw; np_real=np/2;

Spectrometer Frequency (sfrq), Acquisition Time (at), Number of Points (np), Spectral Width (sw), Dwell Time (dt).

So, we can create the correct time axis for the FID data. It is from 0 seconds to 2.73039 seconds (at) in increments of the dwell time (1/sw).

>> time=[0:dt:at]';

>> whos

Name Size Bytes Class

ans 1x63 126 char array
at 1x1 8 double array
dt 1x1 8 double array
etoh_fid 8192x2 131072 double array
fid 8192x1 131072 double array (complex)
np 1x1 8 double array
np_real 1x1 8 double array
sfrq 1x1 8 double array
sw 1x1 8 double array
time 8192x1 65536 double array
x 8192x1 65536 double array

Grand total is 41029 elements using 393390 bytes

>> plot(time,real(fid)); title('FID Plot'); xlabel('Time (sec)'); ylabel('Intensity');

So, lets make a plot of the real and imaginary parts of the FID to ensure they are phase shifted. I will also expand the x-axis to see the data better (blue is imaginary and black is real).

>> plot(time,real(fid),'k',time,imag(fid),'b'); title('FID Plot'); xlabel('Time (sec)'); ylabel('Intensity'); axis([0 .05 -19000 19000]);

It should look something like:

Okay, so the FID data looks good and we have generated the proper x-axis. Now, lets process the FID data.

Lets start with baseline correction and exponential multiplication of the FID data.

>> (sum(fid(1:8192)))/(length(fid(1:8192)))

ans =

-0.5454 - 2.3303i

So, basically the baseline is good.... (very close to zero).

Next, let make an exponential window function and multiple our fid by this function (with a line broadening of 1 hz).

>> lb=1; em=max(real(fid)).*exp(-lb*(0:np_real-1)*dt*pi)';

>> plot(time,real(fid),'k',time,imag(fid),'b',time,real(em),'r');

You can change lb to 5 hz and the EM window function (em) would look like:

>> lb=5; em=max(real(fid)).*exp(-lb*(0:np_real-1)*dt*pi)';
>> plot(time,real(fid),'k',time,imag(fid),'b',time,real(em),'r');

It is obvious that lb of 1 Hz is more appropriate.... Go back to lb=1

>> lb=1; em=max(real(fid)).*exp(-lb*(0:np_real-1)*dt*pi)';

>> plot(time,real(fid),'k',time,imag(fid),'b',time,real(em),'r');

Now multiple our fid with this window function:

>> lb=1; em=exp(-lb*(0:np_real-1)*dt*pi)';

>> wfid=em.*fid;

Now zero fill to 16k:

>> zero=[0:8192-1].*0; zero=zero';

>> zwfid=[wfid;zero];

>> timez=[0:dt:at*2]';

>> plot(timez,real(zwfid));

Now we can Fourier Transform:

>> spec=fftshift(fft(conj(zwfid)));

>> hz=[1500.15:-3000.3/16383:-1500.15]';

>> plot(hz,spec); points=[1:1:16384]';

So, we still need to get the axis in ppm and phase the spectrum. Set values of ph0 and ph1 and (ph0 around 190 and ph1 around 0)

>> ph0=#; ph1=#;

>> specphase=spec*exp(-i*ph0/180*pi)*exp(-i*pi/180*2*ph1); plot(hz,real(specphase));

Now make the x-axis ppm:

>> ppm=((hz-1014)/sfrq).*1000000;

>> plot(ppm,real(specphase))

Or you can put the x-axis in points:

>> points=[1:1:16384]';

>> whos

Name Size Bytes Class

ans 1x4 32 double array
at 1x1 8 double array
dt 1x1 8 double array
em 8192x1 65536 double array
etoh_fid 8192x2 131072 double array
fid 8192x1 131072 double array (complex)
hz 16384x1 131072 double array
lb 1x1 8 double array
np 1x1 8 double array
np_real 1x1 8 double array
ph0 1x1 8 double array
ph1 1x1 8 double array
points 16384x1 131072 double array
ppm 16384x1 131072 double array
sfrq 1x1 8 double array
spec 16384x1 262144 double array (complex)
specphase 16384x1 262144 double array (complex)
sw 1x1 8 double array
time 8192x1 65536 double array
timez 16384x1 131072 double array
wfid 8192x1 131072 double array (complex)
x 8192x1 65536 double array
zero 8192x1 65536 double array
zeroc 8192x1 65536 double array
zwfid 16384x1 262144 double array (complex)

Grand total is 188429 elements using 2031720 bytes

You will have to treat the negative as a positive sign on the ppm scale (it is easiest to way to do this.... keep in mind the tradition in NMR is to plot ppm from positive to negative, left to right.... which is opposite of convensional plotting).

>> plot(ppm,real(specphase))

Also, remember that there is imaginary data if you want to look at it too (it should be in dispersion mode):

>> plot(ppm,imag(specphase))

I encourage you to go throught each step and play around with the variables.

Lastly, it is very handy to get this data out of the Matlab software and into vector graphic manipulation packages (such as Illustrator and Corel Draw) or directly into presentation or word processing software (like MS-Word, Powerpoint, LaTeX, Pages, Keynote, PDF, etc). This can be done directly from the above plot by clicking Files > Save As, and then choosing a compatible format.

ai and eps are the most common vector graphic formats (for illustrator or corel draw) and jpg and tif are the most common bitmap graphic formats (for ms-word, powerpoint). I will save the file as an illustrator format (*.ai) and open it in adobe illustrator to conveniently label the plot, change the plot symbols or color, manipulate the fonts or axis, etc... For example, in less than a minute I read the above plot into Adobe Illustrator CS2 and made the spectrum look like:

While you can add text, graphics and general plot manipulation (ticks, axis labels, etc..) in matlab or any plotting package directly, it is typically much more convenient and powerful to use a vector graphics package like Adobe Illustrator to do this plot manipulation.... Now it is ready for presentation or publication.


Caffeine:

Here is the FID data for Caffeine in CDCl3. Go through this process with this data and see if you can reproduce the plots below:

The caffeine_fid is ascii fid data, caffeine_xytrace is ascii spectrum and the caffeine_fid.fid directory is the original Varian data. caffeine.zip

The Varian data looks like: