WFDB, WFDB_tools and ecgpuwave for Windows 7 64 bit

The WFDB Software Package is a comprehensive software package developed at Physionet to permit an effective use of PhysioBank data.

The WFDB Software Package is made of several components: the WFDB library plus several application for signal processing and WAVE, a GUI for working with waveform data. The software (except WAVE) is supported natively (once built with MinGW using the windows API) on Windows 32 bit platforms, but, unfortunately, most modern Windows machines now run a 64 version of Windows 7.

Many users (like me and my students) over the years used the WFDB library plus the WFDB_tools to read and write data in the PhysioBank format from Matlab. The WFDB_tools are now obsolete and a different approach is reccomended for the same goal, the WFDB Toolbox for Matlab.

Unfortunately, while I reccomend the WFDB Toolbox for Matlab for new projects, we have accumulated a bunch of Matlab codes which use the WFDB_tools, so it would be a pain to rewrite all of them. I therefor decided to build an (unsupported) version of the WFDB library and tools (no WAVE GUI) which run natively under Windows 7 64 bit. I pubblish here this (unsupported) notes for the needs of my students and who might have the same necessity.

If you are in a hurry of getting you software at work, here are the links to the binaries produced with the process described below. As stated in the relevant section, when compiling ecgupwave you now need to use gfortran (g77 is not supported in gcc 4.x). This leads to slighly different results and further testing is needed. So use ecgupwave bearing this in mind.

(Here an older 32 bit version of the same library, in case you need it for a comparison:

Building the WFDB library and applications

A nice guide for building a native 32 bit version of the WFDB suite is provided by Physionet here. The procedure to build a native 64 bit version is similar.

The steps are:

  1. Download and install Cygwin. Just download the base set (plus X if you like, but it will not be necessary here). Do not install GCC or any development toolchain other than x86_64-w64-mingw32 and make. Cygwin is a 32 bit environment. From within it, we would use a cross-compiler (MinGW64) to obtain native 64 bit executables. Than type from a Cygwin shell:
      ln -s /bin/x86_64-w64-mingw32-gcc.exe /bin/gcc.exe
      ln -s /bin/x86_64-w64-mingw32-strip.exe /bin/strip.exe
      ln -s /bin/x86_64-w64-mingw32-ranlib.exe /bin/runlib.exe
      ln -s /bin/x86_64-w64-mingw32-ar.exe /bin/ar.exe
      ln -s /bin/x86_64-w64-mingw32-as.exe /bin/as.exe
      ln -s /bin/x86_64-w64-mingw32-gfortran.exe /bin/gfortran.exe

    This will create symbolic links to the MinGW64 cross-compiler. Old 32 bit versions of the codes might be on the Cygwin path, so, to be to double sure that this is not the case, from the Cygwin prompt we set:

      export PATH
  2. The WFDB libray uses libcurl to access data on the web. We need to build a 64 bit version of the library (the one provided by Cygwin is a 32 bit version!). This is quite straightforward. Just download the source and unpack it where you prefer. Then enter the folder and from the Cygwin prompt type

      ./configure --prefix=/opt/libcurl --without-ssl --host=x86_64-w64-mingw32
      make install

    The configure script can take a long time. Just be patient. The library will be built and installed under /opt/libcurl.

  3. Similarly, we need to build a 64 bit version of expat. That is nearly as easy. First (as suggested here) edit the file /usr/x86_64-w64-mingw32/sys-root/mingw/include/process.h, replacing line 165
      int __cdecl execv(const char *_Filename,char *const _ArgList[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
      int __cdecl execv(const char *_Filename,const char * _ArgList[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;

    This MUST be reversed (the old line must be plugged back) once expat is built. Then download the source from the website of the project and unpack in your favorite folder. Finally, from this folder, at the Cygwin command prompt type:
      ./configure --prefix=/opt/libexpat --host=x86_64-w64-mingw32
      make install

    The library will be installed in /opt/libexpat.

  4. Let's build the WFDB suite. First, download the source code from Physionet and unpack it where you prefer. Then we need to prepare the directory where the library will be installed. We are going to build a native 64 bit versione and we do not want it in system foders. So accepting the suggestion of the WFDB quick start for MS-Windows the library will be installed in /opt/wfdb (once built you can move it out of the cygwin folder as it will not rely on it). To do so, at the Cygwin prompt:

      mkdir -p /opt/wfdb/bin
      export PATH="/opt/wfdb/bin:$PATH"
      cd /opt/libcurl
      cp -p bin/curl-config bin/libcurl-4.dll lib/* /opt/wfdb/bin
      cp -pr include /opt/wfdb
      cd /opt/libexpat
      cp -p lib/* /opt/wfdb/bin
      mkdir /opt/wfdb/include/expat
      cp -pr include/* /opt/wfdb/include/expat
  5. We need to adapt the source to the x86_64-w64-mingw32 toolchain:

  6. We are now ready to configure the package with:
      ./configure --without-cygwin --with-libcurl --prefix=/opt/wfdb
    make install

    During the check of the library, you might get WFDB error. These are due to the different path separator in Cygwin ("/") and Win64 ("\"). To check that the library was built properly, open a Windows prompt, move to the checkpkg folder and type.

    lcheck -v >lcheck.W64.log

    The lcheck.W64.log should then contained only tests with an OK on their side.

The library is now built as well as the WFDB tools. You should move it where you prefer and add the bin folder to the system path. You should check that the dll only links to 64 bit modules. To do so, download the 64 bit version of the and run it on the wfdb-10.5.dll file. You should get no errors related to 32 bit modules loaded (a situation like the one in this picture is fine).

Building ecgpuwave

ecgpuwave is a nice QRS detector that works on PhysioBank data. A bit of changes to the original code are necessary to make it compatible with the new GFortran.

  1. First download the source code from Physionet and unpack it where you prefer.
  2. Download these modified files and replace the corresponding source files.
  3. Then, from the source folder, at the Cygwin prompt type:
      make install
      cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgfortran-3.dll /opt/wfdb/bin/.

    The last line is necessary to copy the dll which is needed.

  4. Finally test it with:
      ./ecgpuwave -r 100s -a test
    The first test should fail and you should have the following output on the console:
    QRS  en  el ECG:  75
    QRS en la conv.:  74
    QRS conformados:  74
    ..           72  beats
    Test 1 Failed
    bxb -r 100s -a test exp -O -f 0 -w s1 >bxb.out 2>&1
    Test 2 passed

    The failure is likely due to a different size of the double precision variables, with gfortran 64 bit. The second passed test says that the difference found in the reference points is minimal, but more checks should be performed. So use ecgpuwave with this in mind.

Building the WFDB_tools

The WFDB_tools are wrappers which permit to exploit the WFDB library from within the Matlab prompt. As written above, this is an obsolete way of doing, but still useful for old codes.

To build the WFDB tools:

  1. One needs to first set up the proper toolchain. To do so install GnuMEX. The sources can be downloaded from the SourceForge page. GnuMEX needs to be tuned to work with a 64 bit version of Matlab. Gregory Lee posted clear instructions in the user forum (WFDB_tools do not need the OpenMP support though).
    As an addedum, also:
    • Rename the files shortpath.mexw64 to shortpath74.mexw64 and uigetpath.mexw64 to uigetpath74.mexw64;
    • You do not need to modify the file if you give write permission to everyone to the file %MATLAB%\R2010b\bin\
    • Modify the line:
      if mlv_ge('7.1'), oext = 'mexw32'; else oext = 'dll'; end
      in the file gnumex.m so that reads:
      if mlv_ge('7.1'), oext = 'mexw64'; else oext = 'dll'; end
  2. Modify the file mexopts.bat in your %appdata%\MathWorks\MATLAB\[version] folder. Add the WFDB dll (with the complete path) to the line that begins with set GM_ADD_LIBS=... and the include path to the wfdb/include folder at the end of the line that begins with set COMPFLAGS=... (that is -I [yourPath]\wfdb\include).
  3. Finally, download the source from Physionet and unpack it in your favorite place. Then, at the Matlab prompt, navigate to the WFDB_Tools\src folder and launch make_WFDB_dlls.m. The script will build all the wrappers which then need to be copied to the main folder (which in turn must be added to the Matlab PATH). It is likely that you need to modify the Matlab script removing each occurence of the string -f mexopts.bat if you get an error saying "Error: Could not find specified options file 'mexopts.bat'".
Then you are all set.

©2012 Roberto Sassi