Multi-Language Programming Environment for C++ Implementation of SONAR Signal Processing by Linking with MATLAB External Interface and FFTW Ivan Aleksi 1 , Dieter Kraus 2 , Željko Hocenski 1 1 Faculty of Electrical Engineering, University of Josip Juraj Strossmayer in Osijek, Cara Hadrijana bb, HR-31000 Osijek, Croatia 2 Hochschule Bremen, University of Applied Sciences, Institute of Water-Acoustics, Sonar-Engineering and Signal-Theory, Neustadtswall 30, D-28199 Bremen, Germany Ivan.Aleksi@etfos.hr Abstract - In this paper we present our Visual Studio C++ (VSC) programming environment (PE) used for SONAR signal processing and acoustic imaging. Proposed PE is implemented in combination with fast C and flexible MATLAB programming tools. SONAR imaging techniques are executed in a fast manner, by implementing them in C. With MATLAB's External Interfaces we achieve the flexibility through access to a large set of MATLAB functions and the Filter Design Toolbox that creates the filtering coefficients. The Fastest Fourier Transform in the West (FFTW) library is used in the VSC for the Discrete Fourier Transform (DFT) and the fast convolu- tion technique. Efficient verification is done by comparing the MATLAB results with the implemented VSC results. The verifica- tion is done by storing the results from MATLAB to MAT-files, and calling the scripts for comparison. In research institutes with availa- ble MATLAB licenses (Universities) where one is developing a product, one can benefit from the presented programming environ- ment. In our case, we are simulating a SONAR system for surface reconstruction. The proposed PE significantly reduces the execution time of simulations and it reduces the implementation and verifica- tion time. Keywords Programming environment; Digital signal processing; MATLAB External Interface; C++ MEX file; Overlap add fast con- volution with FFTW I. INTRODUCTION It is a well known fact that the MATLAB executes faster when the code is utilized with less loops, and that the MEX- files are even faster since they are implemented in a lower programming language [1]. While having the goal to develop a standalone application that runs without MATLAB, it may be useful to firstly transfer smaller parts of the MATLAB code into a MEX-files, in order to achieve faster simulations during the MATLAB code development process. On the other side, if one is implementing a method in a standalone application with C code, it may be useful to link it with MATLAB in order to remain the code flexibility and the easiness of verification with the use of MATLAB's graphical capabilities [2]. By connecting MATLAB 7 and Microsoft Visual Studio 2010 C++ (VSC) programming tools, a fast and flexible programming environ- ment (PE) for implementations in C++ can be achieved. We briefly describe how to use MATLAB and C++ together, sepa- rate or simultaneously, in order to exploit MATLAB's flexibili- ty and fast execution times of C programs [3], as depicted in Fig. 1. MATLAB's flexibility comes from a large set of prede- fined functions applicable in many different computational areas [4]. MATLAB uses an interpreter that creates and ex- ecutes C code, each time with a wrapping function that is en- suring that the program will not crush and subsequently mak- ing a reduction in timing performance. Therefore, execution times are generally better in C. If one of those programming tools is used as a host, the other one can be used as a slave, and vice versa. If MATLAB is a host, then the MEX files can be implemented in C and called as MATLAB functions, cf. Fig 1a. In the case when C is used as a host and MATLAB as a slave, the so called MATLAB engine is used to execute the lines of MATLAB commands which are defined in C as a string, cf. Fig 1c. If both are used separately, MAT file format can be used as intermediate and simple data storage with data compression and with a capability of storing multidimensional variables by their names, [3], [5], cf. Fig 1b. In this work we used the Fastest Fourier Transform in the West (FFTW) library which contains implementations of Dis- crete Fourier Transform (DFT) functions in C++. The FFTW library is also used for MATLAB's DFT functions [6], [7]. We used the FFTW library in VSC for implementation of the fast convolution technique with overlap add algorithm [8]. This article is organized as follows. Section II describes a way to establish the proposed PE which has the benefits in flexibility as well as in the shorten of verification and execu- tion times. Experimental results are proposed in Section III. Finally, Section IV concludes this paper. Figure 1. Algorithm development environments by using: MATLAB as a host and C++ MEX functions (a); C++ as a host which executes MATLAB's functions and exchange data (b); MATLAB and C++ separately with storing intermediate results in MAT file for re-use or result comparison, cf. Ref. [3].