0
\$\begingroup\$

I have already coded the phased array antenna radiation pattern for my university project with Matlab. I will probably do this again for my master's thesis (phased array patch antenna).

Is there any difference between coding this in C++ or Matlab?It seems to me that the difference is not that much, as it is all about mathematic formulas.

\$\endgroup\$
1

3 Answers 3

4
\$\begingroup\$

is there any difference between coding via the C++ and matlab?

It's two pretty different programming languages.

The ways you implement something in Matlab and C++ will be very different (or your C++ will be pretty bad).

Also, the tooling that Matlab offers on one hand is terribly bad (really. The matlab editor as is is an atrocity, and the fact that Matlab code never comes with any unit testing framework is a testament to how sub-par a lot of matlab code is, in terms of software quality. It really is.)

If you don't know how to program C++ yet, you will need to learn it; that takes time.

It makes sense to get a good, modern book, as the way you'd want to write C++ has changed a lot in the last couple of years. Don't get a book that teaches C. Don't get a book that promises results after N days. The oldest you should go is Lippman's "C++ Primer", 5th edition. If you already know programming in a larger context using "proper languages" (like, something interfacing with multiple libraries in Python, or Rust, or Go, NOT matlab scripts that do one thing from top to bottom and call three self-written functions or e.g., isolated PHP scripts), Stroustroup's "A Tour of C++" 2nd or 3rd edition will do. If Matlab is the language you feel most at home in, stick with "C++ Primer". Your university library should be able to get you a copy of the newest edition – ask them, and tell them it's considered the reference textbook on C++.

Your statement

it seems to me that the difference is not that much

is what I, as a repeat supervisor of student theses, would call "classic student overconfidence". Not a bad thing to be optimistic! But writing a complicated simulator in a language that has way fewer math tools built in than Matlab has is not as straightforward as you seem to think.

The fact that someone asks you to reimplement some Matlab as C++ as your master thesis is a strong indication that your supervisor doesn't think it'll be trivial to you: It would be a terrible waste of a master student to let them just do trivial code translation in their thesis. And the demand for a C++ version indicates your Matlab version isn't good enough in some aspect – probably speed. So, you'll be asked to not just deliver some mostly working C++, but actually an fast implementation. Not an easy task to beat Matlab at linear algebra! What C++ allows you to do much nicer is fast control structures and reasoning about complex objects, isolating them and allow for much better parallelization.

But that requires an algorithmic understanding of your problem that probably goes beyond what you've done in a project – which is fine, it's a Master thesis after all, so you will be given time to understand, implement and refine.

Have fun! C++ is a mighty, and sometimes daunting language, but the more "modern" you stay in style (i.e. the more you avoid copied-since-the-1990s answers from the internet), the easier, safer and better to parallelize you get.

\$\endgroup\$
3
  • \$\begingroup\$ Hi Marcus, thanks for answering me! What I will do is to design, fabricate and characrize a patch antenna unit in a reconfigurable intelligent surface. I know how to simulate a single patch antenna radiation pattern via MATLAB. Basically just typ in the formula given by the book and then plot it. I know C and java and I have done several projects with them. The reason I want to ask is the final result, radiation pattern will be the same as the one given by MATLAB? As they are calculating the mathematics.. \$\endgroup\$
    – YIL
    Commented Oct 8, 2022 at 8:21
  • \$\begingroup\$ sure, the "core" of your job is implementing a formula. Matlab and C++ offer very different ways of doing that. The formula's the same, but the things you need to build around it aren't. \$\endgroup\$ Commented Oct 8, 2022 at 8:37
  • \$\begingroup\$ Matlab is really optimized for letting you type in a formula without thinking much. C++ isn't optimized for making that as easy. But it doesn't suck at a lot of things that Matlab sucks at. You'll notice that in small things, like that Matlab will have a "point-wise" application for basically all functions when you throw in a vector, or that it has built-in linear algebra operators (i.e. you can just multiply a vector and a matrix. C++ doesn't even have a built-in matrix type). \$\endgroup\$ Commented Oct 8, 2022 at 8:45
0
\$\begingroup\$

MATLAB is easier than C++. Learning C++ may take a while although the effort usually pays off. If you just need to write algorithms for mathematical formulae or equations, you can use C instead of C++ or just use C-style C++ which may work well for your thesis. If you have lot of time, you can learn C++ with a primer book and The C++ programming language book and implement your project in C++. If you don't have time, implementing your project in C-style C++ may be best.

\$\endgroup\$
5
  • \$\begingroup\$ I strongly advise against using C for math implementations; you really want to have C++'s containers, and its extensive standard library of math functions. If you think C++ offers you nothing for math that C doesn't, then you haven't written modern C++. Don't write C++ as if it was C. That's a recipe for code that's bad at both, being C and being C++. \$\endgroup\$ Commented Oct 7, 2022 at 19:43
  • \$\begingroup\$ I too prefer that coding in C++ should be in C++ which use its full features. Sometimes when real time .performance is needed, C++ works best without stdlib. The phased array antenna or a radar is a real time system and it is probably better if implemented without stdlib. I'm not sure about this and perhaps if a coding standard exists for aeral tracking or radar equipment , then that standard can be applied . The signal processing here is done with a DSP I suppose and it is probably real time. \$\endgroup\$
    – Amit M
    Commented Oct 7, 2022 at 19:48
  • \$\begingroup\$ nah, that's got really nothing to do with it :) The STL doesn't make your code slow. Source: gnuradio.org; I'm the architect of GNU Radio. (in real-time systems, you need to avoid these features of the STL that allocate memory, but that's something very different than a general "don't use the STL") \$\endgroup\$ Commented Oct 7, 2022 at 19:49
  • \$\begingroup\$ If the software system in the processor is "soft real time" and if deadline misses of tasks by about 1 or 2 ms are acceptable, I think STL is fine to use. The decision to choose or not choose STL may not matter much in non hard realltme systems. I suppose GNU radio is a soft real time system.. I meant avoiding using features which use dynamic memory allocation and those which probably add a lot of code.. STL usage may just depend on system requirements. \$\endgroup\$
    – Amit M
    Commented Oct 7, 2022 at 20:09
  • \$\begingroup\$ Again, STL had nothing to do with real time or not. \$\endgroup\$ Commented Oct 7, 2022 at 23:02
0
\$\begingroup\$

Here's a slightly different perspective. In the early 70's, we (my company, not me personally) wrote pattern code in Fortran. We also wrote some E&M field solvers in Fortran to analyze high voltage breakdown.

After maybe 20 years of that, we started using MatLab to do the pattern analysis. We would take in the reams of data that came out of of our near field range systems and process it to determine the antenna beam pattern that was being created.

Recently, a lot of the recent grads (<10 years) have moved on to using Python to analyze and predict antenna patterns. But MLab is still used to process antenna range data.

I am not aware of anyone that wrote C (or C++) code to do this. One advantage Mlab had was the wealth of visualization tools that came with the program.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.