Friday, July 23, 2010

~ Soaring the Simulation

Salam alaik,

Thinking Vectors & Matrices.. its either my way or MATLAB's way..

On a semi-sarcastic side note though, Guys having C or Java background write a MATLAB script just as they'd do that in C, i.e. using loops.
MATLAB is all about vectors & matrices.. so loops could be avoided consideably.
To wit - Consider this simple example;

Lets say we've got two vectors, like so;

a = [1 2 3]' and, b = [4 5 6]'

Now if we wantna take the dot product in C, we would write something like this for loop in C;

c[i] = a[i]*b[i];

While in MATLAB its simply;

c = a'*b; %(a Transposed x b),

So, in essence it does the looping for us.. clean & simple.

Coming back to Simulations..
A cool tool for writing communication system simulations; MATLAB, offers two approaches to do so;

1. MATLAB scripting language.
2. Simulink blocksets.


The former is recommended for the proof_of_concept development usually required in academic & research projects, while the latter is for rapid prototyping in time-constrained industrial projects.
I, for one, usually use the first approach, as my work involves research & development.
The key to make a script time-efficient is to;

a. Think in vectors and matrices.
b. Avoid unnecessary loops here & there.
c. Initialize large vectors and matrices before use.

With these simple tips one could make life quite easy.

Happy scripting...

But wait..
Sometimes the curves you get from MATLAB simulations aren't smooth enough, even after several 100th of runs. I usually smooth them out using:

sgolayfilt(your_variable, m, F)
where m=2,F=21.

Result: cool looking curves, at the expense of one additional line in simulation section of your paper.

Furthermore, I also change the font size & width of the curves using;

h = plot(my_x, my_y); hold on; grid on;
set(h, 'linewidth', 3);
set(get(h, 'parent'), 'fontsize', 14);

Result: .. even cooler 
;o)

~*~*~*~*~~*~*~*~*~
blog comments powered by Disqus