# Thilina's Blog

## Symbolic Integration and Differentiation using MATLAB

While messing with MATLAB during free time I have found the method (thanks to MATLAB documentation) of performing symbolic integration and differentiation using MATLAB. And also the proper way to display a function in MATLAB command line. In this small article I am going to share my experience on symbolic integration and differentiation using MATLAB.

### Representing a function as reader friendly format

Take an example function f(x) as, We can input our function to MATLAB as follows. You can clearly see that ‘x’ is a symbolic object and f(x) is a symbolic function. Say If you need to evaluate f(x) at x = 10; that is f(10) then it’s simply; However this equation and answer representation is bit annoying. Therefore by using the command ‘pretty’ we can display this in more readable format in MATLAB command line. Now let’s have a look how the symbolic differentiation is performed.

2013 December 15

## Process spatial operations without ‘for’ loops in MATLAB

While working on some image enhancement applications which the intensity of a given pixel is also a function of its location (spatial coordinates), I used to use ‘for’ loops to iterate each pixel at once and calculate its intensity based on (x,y) value obtained from those two ‘for’ loops. This is very annoying since it takes quite some time to process two ‘for’ loops as well as it is a belief that the MATLAB ‘for’ loops are used to slow. In this article I share my experience how I avoided the requirement of two ‘for’ loops by using the properties of complex numbers for a photo effect which I described in a previous article of mine.

Normally in an image there is an mxnx3 matrix which represents red, green and blue intensities respectively. In my case I append another 4th matrix of coordinates which makes the image matrix as mxnx4. (Even-though there is a memory drawback in this design, it is very easy to handle rather than two nested ‘for’ loops).

This 4th matrix contains complex numbers which their real value is equal to row index and its imaginary value is equal to its column index. And now we do have another advantage. Using the properties of complex numbers we can easily calculate the distance and angle between two pixels in interest which is very useful in image effects such as ‘focal BW’.

2013 October 18

## Serial PORT MATLAB – Getting Started

Serial port is a physical communication interface which transfer one bit at a time in contrast to parallel port. In the recent past, before USB serial port communication is the most famous communication medium for many computer peripherals such as mouse, keyboard, Etc. Still in many embedded development environments use serial port communication as data transmission interface.

When it comes to my field of interest, where developing embedded systems, mostly signal processing applications, I wanted to visualize and to do some tweaks to processed data to verify whether my application works properly or not. In this case normal serial port desktop applications does not allowed me to visualize what I needed except the application ‘Serial Chart’. Therefore as usual I ended up with a MATLAB solution that is serial port communication with MATLAB. In this article I will share my experience in sending data and receiving data with interrupts in serial port with MATLAB.

2013 August 25

## Photo Effects using MATLAB 3.0 – Image warping using MATLAB – Fisheye Similar Effect

The term fisheye was coined in 1906 by American physicist and inventor Robert W. Wood based on how a fish would see an ultra-wide hemispherical view from beneath the water (a phenomenon known as Snell’s window) (Wikipedia). I tried several domain transformation functions to create the fisheye effect and ultimately I ended up with warping an image into a circle which gives somewhat similar result to the fisheye effect. In this article I am going to share my experience on warping an image in to a circle (fisheye effect, my version).

Here is an example of correct fisheye effect. 2013 April 22

## MATLAB plotting tools 1.0 – ‘plot’ command

Data visualization is a main requirement in Image and Audio signal processing, since it can be used to identify special features, intermediate results, process states as well as the correctness of the final results. Data plotting is one way of data visualization which used in very common by all MATLAB users. However the selection and handling of plot for the requirement is a critical factor since the whole representation of the data is depends on the tool we choose to visualize it. In this article (or maybe a set of articles) I am going to share my experience and suggestions on using MATLAB plotting tools.

### plot Command

The command ‘plot’ is the most widely used data visualization tool which will create a 2D line plot on a MATLAB figure. Say you are having a data set called ‘y’ based on values ‘x’, you can simply visualize them using the plot command as follows.

```x = 0:0.001:100; % x is the array of 0 to 100 with 0.001 intervals
y = sin(0.05*pi*x); % y is the sine value array of x
plot(y);
```

After this command plot will be drawn in a MATLAB figure as follows; 2013 February 1 Posted by | MATLAB | , , , | 4 Comments

## Setting up MATLAB with Atlys Spartan 6 FPGA for Hardware Co-simulation

In my previous articles I discussed how to perform a hardware co-simulation using MATLAB, by using Digilent Atlys Spartan 6 FPGA development kit. But many of my colleagues had the problem of setting up MATLAB for Hardware co-simulation. With a help of a friend of mine, we managed to configure MATLAB for hardware co-simulation. In this short article I am going to share my experience on setting up MATLAB for hardware co-simulation with Atlys Spartan 6 Development Kit.

2012 September 26

## MATLAB GUI programming (code level) 2.0 – Undocumented MATLAB – JAVA codes in MATLAB M-files

This is something I found really interesting in MATLAB. We can write m-scripts with JAVA codes, this is very useful when designing UI components for MATLAB applications. In this article I will share my experience on creating GUI in MATLAB using JAVA and also an implementation of video cropping software (backend part will be discussed on my next article).

When using JAVA codes in *.m files we do not use “new” keywords to initiate any objects.  I am not sure the usage of import keyword in MATLAB/JAVA. Therefore JFrame must be used as  java.swing.JFrame. It is quite different from JAVA.

`JFrame frame = new JFrame; // Java Syntax`
`frame = javax.swing.JFrame; % matlab syntax`

2012 May 30

## Photo Effects using MATLAB 2.0 – Optical Illusion using MATLAB – Shake your head and see the image

This is something I found really interesting while wandering in facebook. Most of facebook fan pages shares a set of images which has black and white columns saying “shake your head and see the image”, which will results in seeing a hidden image in black and white column grid. Later when I search google, also found a number of images which similar to the images shared around facebook. In this article I share my attempts and experience on how I create my own optical illusion (shake your head and see image) using MATLAB.

When we look at the image closely we can notice the hidden image with very low intensity, which is not noticeable when we look at it from a average distance of our eye to monitor. This is what I have done and it gives much better results when we use gray scale images than colour images. Fist I made a frame which has black and white columns (binary image) in same size of my source image. Then I performed element-wise multiplication with source image and created brightness shifted and normalized image as follows. Then again it was multiplied element-wise with the negation of frame.

2012 April 12 Posted by | Image Processing, MATLAB | 1 Comment

## Translation Invariant Image Registration using Phase Correlation – Panorama Imaging on MATLAB

Panorama Imaging is one of most specialized techniques in photography. The ratio of this photo is 2:1 or larger in size. Nowadays even modern mobile phones also have the feature of capturing panorama images, specially accelerometer based techniques have made it easier to capture wonderful pieces of images in panoramic way. Unfortunately in my mobile phone camera, even though it has panoramic imaging, it does not have such flexible feature on creating panorama images, therefore what I do is take two pictures and stitch them using MATLAB.

2012 March 24 Posted by | Image Processing, MATLAB, Technology | 9 Comments

## Hardware co-simulations for image processing applications using MATLAB Simulink Xilinx Block-set

When working with image processing applications on hardware level, during the simulations I personally felt, very hard to work with bit/byte data, without seeing the resulting image/video data. For this kind of application we need to stream in and stream out data bits/bytes to and for the hardware module we implemented. MATLAB Simulink with combination of Xilinx Block-set gives great help in dealing this issue. By using MATLAB we can reshape images in to data stream as well as reshape data streams back in to images in MATLAB environment as I discussed in my previous article.

But the problem rises with the complexity of the system in interest. According to the performance of your computer the simulation time can be varying, sometimes it may be able to take hours. Hardware Co simulations on MATLAB come as the solution for the pc performance limitation issue. In this article I am going to share my experiences on performing a hardware co-simulation on MATLAB with the FPGA development kit Atlys Spartan 6 with xls45-3 FPGA.

2011 December 6