Saturday, April 28, 2007

Export figure to pdf in Matlab

In LaTex, if the figure is in pdf format, you can click pdfLaTex just once to generate the output. Otherwise, if the figure is in eps format, you have to click button three times to do the same thing by using the LaTex -> dvi2ps -> ps2pdf workflow.

The good thing is, Matlab can export figure to pdf format. Unfortunately, when saving a figure to a pdf file in Matlab, you'll find the figure doesn't fit the layout very well, i.e. there is a large margin from the figure to the page boundary. Those margins will be inserted into the LaTex output when you include these pdf figures.

A solution is:
1) After you plot the figure in Matlab, go to 'File->Export Setup', input the size of the output you want, e.g. Width: 6 inches, Height: 5 inches. Then click 'Apply to Figure' button.
2) Don't close the 'Export Setup' window. Go to 'File->Print Preview->Paper', input the same size in the Width and Height options.
3) Don't close the 'Print Preview' window. Go back to the 'Export Setup' window, and click 'Export', then select pdf format and save it.
4) Check the output pdf file, you'll see it is perfect.

Friday, April 27, 2007

Making Slides Using LaTex

Recently I'm preparing for my dissertation slides. I used to create transparencies with PowerPoint because of its simplicity, but it is really difficult to cope with mathmatical equations. You have to reserve space for equations in the text, and if you modify some equations later, you may have to readjust their reserved space one by one.

So I transfer to LaTex, although I need some time to learn it, it is powerful. It has rich overlay and dynamic effects. The layout, the colors and the fonts can easily be changed. The most important thing for me is that it can merge text and mathematical formulae smoothly and can reuse LaTex codes of my previous papers.

There are some well-known existing packages for slides making in LaTex, such as Beamer, Proper, Foiltex etc. I didn't spend too much time on investigating and comparing those packages pros and cons. I just select the Beamer.

After half day's learning, I can create slides with Beamer quickly. Beamer can handle graphics but with less flexibility, e.g. locating the position of figures freely is not that easy. Fortunately, I found another package called 'pstricks' which can do this kind of work easily. However, pstricks does not support PdfLaTex. The workflow of pstricks is LaTex->dvips->pspdf.

The following figure is a demo of the slides created by Beamer.

Wednesday, April 25, 2007

Error LNK2001: unresolved external symbol...

Recently, when I used the templates in C++, I got a link error: unresolved external symbol "public: __thiscall ...". My work has three files: fc.h, fc.cpp and main.cpp.







------------------------------------------------

// fc.h

template <class T>

class fc

{

    public:

       func();

};

// end of fc.h//

------------------------------------------------

// fc.cpp

template <class T>fc <class T>::func() { }

// end of fc.cpp//

------------------------------------------------

// main.cpp

#include "fc.h"

int main()

{

    fc A;

    A.func();

}

------------------------------------------------







However, when I removed the template declaration from the header file, or put all three files just in one body, the link runs smoothly. Finally, I found the reason and the solution of this kind of problem from the Internet [1].

At least three cases are related to this link error:
1. Forget to define a declared member function, especially the constructor.
2. Static member or class.
3. Using template with splitted declaration and definition.

For the first scenario, in general, people will not forget to define a member function after the declaration. So this kind of link erro seldom appears. But sometimes people may have declared the constructor but forget the definition and think the system will do it automatically. It is right that system may creat the default constructor if you don't declare it. But this doesn't work when the declaration has been made.

For the second case, if a class has a declared static member, because you cannot initialize it inside the class body (it belongs to the class, not the object), so if you forget defining this static member outside the body, the link error will also occur.

The thrid one is the well-known fallacy: templates behave similarly as ordinary classes and functions with respect to the separation between their declarations and definitions. This is not true. The reason is that a template actually is NOT real code. A good anologic example is: the MS-Word has some letter templates, but they are not real letters until you fill them out. Therefore, one thing we need to remember: templated functions and classes don't actually exist until you use them! A solution is: a header file including template declarations also constains their definitions. However, this seems to violate the rule of the separation of the declaration and definition.

Reference:
[1] http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=298&rl=1

Sunday, April 15, 2007

Cooperative Diversity for Wireless Networks

Cooperative diversity can emmulate an antenna array and then exploit spatial diversity in wireless networks with fading channels. It exploits the broadcast nature of the wireless medium and allows radios to jointly transmit information through relaying.

Traditionally, in ad hoc networks, packets are forwarded from the source to the destination through multi hops serially. The well-known capacity of wireless networks obtained by Gupta and Kumar in 2000 is with this strategy. By using Cooperative diversity, the source and the relay nodes may cooperate together for data transmission. The capacity of this kind of network has been investigated by Xie and Kumar.

The use of cooperative diversity is manifold:
1) Increase capacity (enlarge capacity region)
2) Improve reliability in terms of diversity gain
3) Diversity-multiplexing tradeoff

Different algorithms can be applied for cooperative communication, some examples are:

1) Amplify-and-Forward
In this case, relays just simply amplify the received signal with a linear transformation.
2) Decode-and-Forward
Relays first detect and decode the received signals and then re-encode them. This decoding and re-encoding procedure can be considered as a non-linear transformation.
3) Selection and dynamic relaying
In this case, cooperative terminals adapt their transmission format according to the measured channel state information.
4) Incremental relaying
This scheme exploits limited feedback from the destination terminal for relaying.

Incorporating the cooperative diversity into the network is still an open problem.

Reference:
[1] J. Nicholas Laneman, "Cooperative diversity: models, algorithms and architectures," Cooperation in wireless networks, Springer, 2006

Wednesday, April 11, 2007

Adaptive modulation v.s. High order diversity

Today's learning: adaptive modulation may become unnecessary as the diversity order is increased. It can be viewed as a lower-complexity alternative to diversity technologies, such as MIMO.

Remember, adaptive modulation or diversity only offers advantages over fading channels. Adaptive modulation can employ high-order modulation schemes to adapt to the channel state and then increase the system throughput. Diversity utilizes the independent property between two or more links. When only one receiver is provided, adaptive modulation can be employed. But when more than two receivers are available, it is better to use diveristy technologies.