Jekyll2022-09-30T00:54:03+00:00https://blog.shuvangkardas.com/feed.xmlShuvangkar Das’ BlogLifestyle, Productivity & ResearchShuvangkar Dasshuvangkarcdas@gmail.comGetting Started With Latex in 5 Minutes2022-09-29T00:00:00+00:002022-09-29T00:00:00+00:00https://blog.shuvangkardas.com/Getting-Started-with-Latex<p>I started my Ph.D. last year at Clarkson University. I need to learn a lot of tools to cope with my research project and publish research articles. Latex is a new addition to my skill set, I have recently learned Latex to write my first paper during Ph.D. Actually, I have written multiple <a href="https://scholar.google.com/citations?user=ebLUEXQAAAAJ&hl=en">papers</a> before. MS word was my way to go on these papers. Frankly speaking, it is really tempting to use MS word for writing papers as it seems easy to get started. Pain starts when you have written down a few pages and want to format the figure, refer to the figures and cite the paper. There is no easy of in MS word for these. Here comes the Latex to rescue.</p>
<p>In <code class="language-plaintext highlighter-rouge">LaTex</code>, you only need to focus on the content, the Latex engine handles the formatting for you. Your main job is to focus on writing not on formatting. Also managing references is very easy in latex. Here are the basic things you need to know to get started with Latex</p>
<h3 id="class">Class</h3>
<p>Controls the overall appearance of the document. This is the first thing you need to set for your project.</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">\documentclass{article}</code>: An example article class</li>
<li><code class="language-plaintext highlighter-rouge">\documentclass[12pt, letterpaper]{article}</code>: Class takes additional parameter like font size and paper</li>
<li>Extension <code class="language-plaintext highlighter-rouge">.cls</code>.</li>
<li><a href="https://www.ctan.org/topic/class">Official Class List</a></li>
</ul>
<h3 id="package">Package</h3>
<p>Add more functionalities to the document.</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">\usepackage{graphicx}</code>: Package to import external graphics files</li>
<li>Extension: <code class="language-plaintext highlighter-rouge">.sty</code></li>
</ul>
<h3 id="body">Body</h3>
<p>body of the document is written between the <code class="language-plaintext highlighter-rouge">\begin{document}</code> and <code class="language-plaintext highlighter-rouge">\end{document}</code> tags.</p>
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\documentclass</span><span class="p">{</span>article<span class="p">}</span>
<span class="nt">\begin{document}</span>
First document. This is a simple example, with no
extra parameters or packages included.
<span class="nt">\end{document}</span>
</code></pre></div></div>
<h3 id="preamble">Preamble:</h3>
<p>Everything before the <code class="language-plaintext highlighter-rouge">\begin{document}</code> is called setup or preamble</p>
<ul>
<li>Class and packages used in the document</li>
<li><code class="language-plaintext highlighter-rouge">\title{My first LaTeX document}</code>: the document title</li>
<li><code class="language-plaintext highlighter-rouge">\author{Shuvangkar Das}</code>:</li>
<li><code class="language-plaintext highlighter-rouge">\date{August 2022}</code>:</li>
</ul>
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\documentclass</span><span class="na">[12pt, letterpaper]</span><span class="p">{</span>article<span class="p">}</span>
<span class="k">\title</span><span class="p">{</span>Article on Latex By Shuvangkar Das<span class="p">}</span>
<span class="k">\author</span><span class="p">{</span>Shuvangkar das<span class="p">}</span>
<span class="k">\date</span><span class="p">{</span>August 2022<span class="p">}</span>
</code></pre></div></div>
<h3 id="a-basic-latex-file">A Basic Latex File</h3>
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\documentclass</span><span class="na">[12pt, letterpaper]</span><span class="p">{</span>article<span class="p">}</span>
<span class="k">\title</span><span class="p">{</span>My first LaTeX document<span class="p">}</span>
<span class="k">\author</span><span class="p">{</span>Hubert Farnsworth<span class="k">\thanks</span><span class="p">{</span>Funded by the Overleaf team.<span class="p">}}</span>
<span class="k">\date</span><span class="p">{</span>August 2022<span class="p">}</span>
<span class="nt">\begin{document}</span>
We have now added a title, author and date to our first <span class="k">\LaTeX</span><span class="p">{}</span> document!
<span class="nt">\end{document}</span>
</code></pre></div></div>
<h3 id="bold-italics-and-underlining">Bold, italics and underlining</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">\textbf{bold text}</code></li>
<li><code class="language-plaintext highlighter-rouge">\textit{Italic Text}</code></li>
<li><code class="language-plaintext highlighter-rouge">\underline{Underline Text}</code></li>
</ul>
<h3 id="add-figures">Add Figures</h3>
<ul>
<li>Need two packages to handle images/figures efficiently
<ul>
<li><code class="language-plaintext highlighter-rouge">\usepackage{graphicx}</code>: Package for using graphics</li>
<li><code class="language-plaintext highlighter-rouge">\graphicspath</code>: Latex look for images in the mentioned folder</li>
</ul>
</li>
<li><code class="language-plaintext highlighter-rouge">\includegraphics{myimage.jpg}</code>: load <code class="language-plaintext highlighter-rouge">myimage.jpg </code></li>
<li><code class="language-plaintext highlighter-rouge">\includegraphics[width=15cm]{myfigure.pdf}</code>: You can mention the figure absolute or relative dimension. More details in [[Latex Figure]]</li>
<li>To add caption, label and reference with the figure, the <code class="language-plaintext highlighter-rouge">figure</code> environment is used
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{figure}</span>[h]
<span class="k">\centering</span>
<span class="k">\includegraphics</span><span class="na">[width=0.75\textwidth]</span><span class="p">{</span>myfigure.png<span class="p">}</span>
<span class="k">\caption</span><span class="p">{</span>Figure Example by shuvangkar Das<span class="p">}</span>
<span class="k">\label</span><span class="p">{</span>fig:referenceLink<span class="p">}</span>
<span class="nt">\end{figure}</span>
</code></pre></div> </div>
</li>
</ul>
<h3 id="list">List</h3>
<ul>
<li>Unordered list: <code class="language-plaintext highlighter-rouge">itemize</code> environment is used
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{itemize}</span>
<span class="k">\item</span> First list
<span class="k">\item</span> Second list
<span class="nt">\end{itemize}</span>
</code></pre></div> </div>
</li>
<li>Ordered List: <code class="language-plaintext highlighter-rouge">enumerate</code> environment is used
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{enumerate}</span>
<span class="k">\item</span> First list
<span class="k">\item</span> Second list
<span class="nt">\end{enumerate}</span>
</code></pre></div> </div>
</li>
</ul>
<h3 id="math-equation">Math Equation</h3>
<p>For writing math, you do not need to load any package. It is by default supported. you can write math equations in-line with text and individual equations in display mode.</p>
<ul>
<li>Inline math
<ul>
<li><code class="language-plaintext highlighter-rouge">$E=mc^2$</code> or <code class="language-plaintext highlighter-rouge">begin{math} E=mc^2 end{math}</code> or <code class="language-plaintext highlighter-rouge"> </code>( E=mc^2<code class="language-plaintext highlighter-rouge"> \)</code>: Three command produce the same results</li>
</ul>
</li>
<li>Display math mode
<div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{equation}</span>
E=mc<span class="p">^</span>2
<span class="k">\label</span><span class="p">{</span>eq2<span class="p">}</span>
<span class="nt">\end{equation}</span>
</code></pre></div> </div>
<p>If you want to refer to the equation, use label-text.</p>
</li>
</ul>
<h3 id="paragraph-and-new-line">Paragraph and New Line</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">enter</code> key twice create paragraph or use <code class="language-plaintext highlighter-rouge">\\</code></li>
</ul>
<hr />
<p>-Shuvangkar Das, Potsdam, New York</p>
<h3 id="interesting-things-i-am-doing-currently">Interesting Things I am Doing Currently</h3>
<p>Everyone does some form of knowledge work but most of the time does that inefficiently. As a result, despite working hard, we ended up with questionable results. So to address that I am working on a very exciting project name Smart Personal Knowledge Management(SPKM). In fact, I am making a YouTube video series on it. You can get update about the course in two ways, (1) by subscribing to my <a href="https://www.youtube.com/ShuvangkarDas">YouTube</a> channel or (2) by subscribing my <a href="http://newsletter.shuvangkardas.com/">newsletter</a></p>
<h3 id="connect-with-me">Connect with me</h3>
<ul>
<li>Twitter: <a href="https://twitter.com/shuvangkar_das">https://twitter.com/shuvangkar_das</a></li>
<li>LinkedIn: <a href="https://www.linkedin.com/in/ShuvangkarDas/">https://www.linkedin.com/in/ShuvangkarDas/</a></li>
<li>YouTube: <a href="https://www.youtube.com/ShuvangkarDas">https://www.youtube.com/ShuvangkarDas</a></li>
</ul>
<h3 id="references">References</h3>
<ol>
<li>https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes</li>
</ol>Shuvangkar Dasshuvangkarcdas@gmail.comI started my Ph.D. last year at Clarkson University. I need to learn a lot of tools to cope with my research project and publish research articles. Latex is a new addition to my skill set, I have recently learned Latex to write my first paper during Ph.D. Actually, I have written multiple papers before. MS word was my way to go on these papers. Frankly speaking, it is really tempting to use MS word for writing papers as it seems easy to get started. Pain starts when you have written down a few pages and want to format the figure, refer to the figures and cite the paper. There is no easy of in MS word for these. Here comes the Latex to rescue.How I Deal with Contradictions2022-09-11T00:00:00+00:002022-09-11T00:00:00+00:00https://blog.shuvangkardas.com/How-I-Deal-with-Contradictions-Everyday<hr />
<p>It was 2003/2004, I was 11 years old and bought an English to Bangla dictionary for the first time.
One day while looking around the back pages I found there was a chapter for proverbs. I found these very interesting and started reading them instantly.
At one point I found these two proverbs on two opposite pages.</p>
<ul>
<li>Something is better than nothing(In Bangla: নেই মামার চেয়ে কানা মামা ভালো)</li>
<li>Nothing is better than something(In Bangla: দুষ্ট গরুর চেয়ে শূন্য গোয়াল ভালো)<br />
This is not the first time, I encountered such contradictions. The list is very long.</li>
<li>Some will say “enjoy life why so serious.” Other says “build carrier at anyhow.”</li>
<li>“Money is numbers, and numbers never end. If it takes money to be happy, your search for happiness will never end.”― Bob Marley</li>
<li>Some says “money does not matter”, some say you cannot buy happiness without money, and it is better to cry inside Mercedes instead of a hut.<br />
When I see social media post on a topic, I agree with the points. Later I see counterarguments, and I also agree with that. Then I ask myself which one is true. Sometimes I find both are true with their perspective, and sometimes true partially.</li>
</ul>
<p>There is no absolute truth or lie in the world; everything is relative. What is suitable for some people is bad for others. What is good for now might be bad for a few days later. What is good for one country is not suitable for another country. So it is better not to compare everything.</p>
<ul>
<li>Money cannot buy happiness for some people, but it does buy happiness for others.</li>
<li>Whether money brings happiness or not depends on how you define your happiness; not how Bob Marley defined his happiness. Are you happy buying a new iPhone? Then it surely does.</li>
</ul>
<p>Then which one do I follow? The one that works best for me, not the one that works best for others. So it’s your life. You should think for yourself. If you got good advice from other people and directly apply that in your life and ended up with bad results that are not the fault of other people. That identifies that you are not living your life. You are living other people’s life. If you do, you put a thought into the advice and change it according to your requirements. So my final word would be, take what works for you.</p>
<p>-Shuvangkar Das, Potsdam, New York</p>
<h2 id="announcements">Announcements</h2>
<p>Everyone does some form of knowledge work but most of the time does that inefficiently. As a result, despite working hard, we ended up with questionable results. So to address that I am working on a very exciting project name Smart Personal Knowledge Management(SPKM). In fact, I am making a YouTube video series on it. You can get update about the course in two ways, (1) by subscribing to my <a href="https://www.youtube.com/ShuvangkarDas">YouTube</a> channel or (2) by subscribing my <a href="http://newsletter.shuvangkardas.com/">newsletter</a></p>
<h2 id="connect-with-me">Connect with me</h2>
<ul>
<li>Twitter: <a href="https://twitter.com/shuvangkar_das">https://twitter.com/shuvangkar_das</a></li>
<li>LinkedIn: <a href="https://www.linkedin.com/in/ShuvangkarDas/">https://www.linkedin.com/in/ShuvangkarDas/</a></li>
<li>YouTube: <a href="https://www.youtube.com/ShuvangkarDas">https://www.youtube.com/ShuvangkarDas</a></li>
</ul>Shuvangkar Dasshuvangkarcdas@gmail.comWhen I see social media post on a topic, I agree with the points. Later I see counterarguments, and I also agree with that. Then I ask myself which one is true.Professional Presentation Technique2022-09-10T00:00:00+00:002022-09-10T00:00:00+00:00https://blog.shuvangkardas.com/Professional-Presentation-Technique<p><img src="/assets/images/professional-presentation.png" alt="Professional Presentation Methods" />
Last week I participated a workshop on professional presentation by Mark Dougherty organized by “Knight Class Workshop, Clarkson University”. I found the workshop very helpful for presenting in professional environment. So here are the summary:</p>
<ul>
<li>Always Keep your presentation simple. It is not about using power point presentation and complex template. By the end of the day our goal is to effective communication. Template is the last thing you will consider. This idea is also called stay away from power point junk.</li>
<li>First identify the purpose of the presentation before making it.
<ul>
<li>If the goal is to educate: How do you convey correct information?</li>
<li>Information: What is the information the audience is interested in?</li>
<li>Decision making: Funding presentation, Motive is to provide the right information and different options and recommendations so the audience can reach to a decision at the end of you presentation.
<blockquote>
<p>The flow of story should tie to your purpose.</p>
</blockquote>
</li>
</ul>
</li>
<li>Preparation
<ul>
<li>Storyboarding: This is important, You presentation should have a consistent story</li>
<li>Planning your time: Make slide according to time allocation.</li>
<li>Knowing your audience: Adjust the content based on audience. Never make an assumption that your preferred style is your audience style.</li>
</ul>
</li>
<li>Presentation is a story but don’t make it mystery. Clarify things as much as possible</li>
<li>Three rules for effective communication
<ol>
<li>Tell them what you are going to say/outline at the beginning</li>
<li>Tell them details: I told you what I will say, Now I will break down the topic by topic.</li>
<li>Tell them: What you said/ summary/ this is what I told you. Some may not prefer this method. So know your audience first.</li>
</ol>
</li>
<li>Less is more, less words, bullets, content per slide. You don’t want to read the slide, you want to present the slide. It is good to keep less than 3 bullets per slide.</li>
<li>A few notes
<ul>
<li>Be aware of group expectation -> format, branding, etc.</li>
<li>Different topics will call for different levels of details</li>
<li>Does the presentation need to stand-alone without verbal pitch? From my opinion, course lecture should stand-alone without verbal pitch.</li>
<li>Create clarity with figures -> axes, scales, labeling, titles, legends</li>
<li>Spelling!! It is dangerous. It may spoil your good presentation. This happened with me once.</li>
</ul>
</li>
<li>Presence
<ul>
<li>Command the room</li>
<li>Body language</li>
<li>Eye contact -> with people and camera. Just like driving a car.</li>
<li>Volume, tone, cadence. Can everybody hear me? make sure that beforehand.</li>
</ul>
</li>
</ul>
<p>Finally, think about what are the questions your audience might ask and prepare keeping that in mind.</p>
<p>-Shuvangkar Das, Potsdam, New York</p>
<h2 id="announcements">Announcements</h2>
<p>Everyone does some form of knowledge work but most of the time does that inefficiently. As a result, despite of working hard, we ended up with questionable results. So to address that I am working on a very exciting project name Smart Personal Knowledge Management(SPKM). In fact, I am making a YouTube video series on it. You can get update about the course two ways, (1) subscribe my <a href="https://www.youtube.com/ShuvangkarDas">YouTube</a> channel (2) subscribe my <a href="http://newsletter.shuvangkardas.com/">newsletter</a></p>
<h2 id="connect-with-me">Connect with me</h2>
<ul>
<li>Twitter: <a href="https://twitter.com/shuvangkar_das">https://twitter.com/shuvangkar_das</a></li>
<li>LinkedIn: <a href="https://www.linkedin.com/in/ShuvangkarDas/">https://www.linkedin.com/in/ShuvangkarDas/</a></li>
<li>YouTube: <a href="https://www.youtube.com/ShuvangkarDas">https://www.youtube.com/ShuvangkarDas</a></li>
</ul>Shuvangkar Dasshuvangkarcdas@gmail.comAlways Keep your presentation simple. It is not about using power point presentation and complex template. By the end of the day our goal is to effective communication. Template is the last thing you will consider. This idea is also called stay away from power point junkTake Note Fast in Obsidian & Notion By Learning Markdown Basic Syntax2022-08-29T00:00:00+00:002022-08-29T00:00:00+00:00https://blog.shuvangkardas.com/Take-Note-Fast-in-Obsidian-&-Notion-By-Learning-Markdown-Basic<p>When I was a kid: WOW! MS word is great.<br />
When I was young: Evernote is awesome.<br />
When I started my Ph.D.: Notion is great.<br />
When I am 2nd years in Ph.D.: Nothing is better than Obsidian.<br />
When I am tittle experienced: Nothing can beat <strong>Markdown</strong> and plain text.</p>
<p>There are many note-taking apps in the personal knowledge management domain, e.g. Obsidian, Notion, Roam Research, Logseq, etc. You know, one thing is common in all of these note-taking apps. That is all these apps natively support Markdown. You might be wondering, if that is so useful why didn’t you hear it before?</p>
<p>That’s a legit question. But I do not have an answer for it. Markdown is a simple way of writing formatted text. Think about a situation when you want to write in MS word, you need to click a particular button to make a heading. It takes time. right? But in markdown you will write <code class="language-plaintext highlighter-rouge">#</code> and then space and your heading name, it will turn into heading automatically in these apps. That is so useful when you want to take notes fast. You do not need to hold your mouse for that. In this way, markdown makes writing formatted text. In knowledge gathering, the only thing matter is the knowledge instead of thinking about the format. Thinking about formatting is the job of old people who like MS word.</p>
<p>To get started with Obsidian you need to know a few markdown syntaxes.</p>
<ol>
<li>How to write a heading</li>
<li>How to write bullet</li>
<li>How to add a link</li>
</ol>
<h3 id="how-to-write-a-heading">How to write a heading</h3>
<p>There is a space between the hash and heading. So type <code class="language-plaintext highlighter-rouge">#</code> and then space. Then heading will be rendered automatically.</p>
<ul>
<li><code class="language-plaintext highlighter-rouge"># Heading1</code></li>
<li><code class="language-plaintext highlighter-rouge">## Heading2</code></li>
<li><code class="language-plaintext highlighter-rouge">### Heading3</code></li>
</ul>
<h3 id="how-to-write-bulleted-list">How to write bulleted list</h3>
<p>First press dash, then press space, and the dash turns into a bullet point. You have to do this for the first bullet. Pressing enter/return will create the next bullet.</p>
<ul>
<li>Bullet x (<code class="language-plaintext highlighter-rouge">- Bullet x</code>)</li>
<li>Bullet y (<code class="language-plaintext highlighter-rouge">- Bullet y</code>)</li>
<li></li>
</ul>
<h3 id="how-to-write-numbered-list">How to write numbered list</h3>
<p>Enter a number, then a dot and space will create the number list. You need to do this for the first list. Pressing enter/return will create the next list.</p>
<ol>
<li>List1 (<code class="language-plaintext highlighter-rouge">1. List1</code>)</li>
<li>List2 (<code class="language-plaintext highlighter-rouge"><return key> List2</code>)</li>
</ol>
<h3 id="how-to-connect-knowledge">How to connect knowledge</h3>
<p>You can learn better by connecting new knowledge with previous knowledge. The connection is important for learning. Our brain does that continuously. The idea here is, that if you put an external connection in a note-taking app, you are putting less pressure on your brain. The more connection you create, the more you remember things. Obsidian/Notion is very good at connecting knowledge.</p>
<p>Consider, that you have two notes, One is <code class="language-plaintext highlighter-rouge">Herd Immunity</code> and another one is <code class="language-plaintext highlighter-rouge">Vaccine</code>. Suppose your want to connect the <code class="language-plaintext highlighter-rouge">Vaccine</code> note to the <code class="language-plaintext highlighter-rouge">Herd Immunity</code> note.</p>
<ul>
<li>The simplest way to do this is to use double brackets on both sides of the note you want to connect. That is called a wiki-style link.</li>
<li>So you have to write <code class="language-plaintext highlighter-rouge">[[Vaccine]]</code> inside the <code class="language-plaintext highlighter-rouge">Herd Immunity</code> Note to connect both notes.</li>
</ul>
<p>This should be the start of your markdown. If you explore more you will learn more. But I believe to start with a thing simple way. These are the basic things you need to use in day-to-day life. In the next tutorial, I will bring up a more advanced topic. Subscribe to my <a href="https://newsletter.shuvangkardas.com/">newsletter</a> to get the latest update. Also, I am making a video series on YouTube on how to do knowledge management and research smartly. You can subscribe to my <a href="https://www.youtube.com/ShuvangkarDas">channel</a> for the upcoming course.</p>
<hr />
<p>Shuvangkar Das, Potsdam, New York<br />
Connect with me:<br />
Twitter: <a href="https://twitter.com/shuvangkar_das">https://twitter.com/shuvangkar_das</a><br />
LinkedIn: <a href="https://www.linkedin.com/in/ShuvangkarDas/">https://www.linkedin.com/in/ShuvangkarDas/</a><br />
YouTube: <a href="https://www.youtube.com/ShuvangkarDas">https://www.youtube.com/ShuvangkarDas</a></p>Shuvangkar Dasshuvangkarcdas@gmail.comWhen I was a kid: WOW! MS word is great. When I was young: Evernote is awesome. When I started my Ph.D.: Notion is great. When I am 2nd years in Ph.D.: Nothing is better than Obsidian. When I am tittle experienced: Nothing can beat Markdown and plain text.How To Remember Confusion Matrix; True Positive, True Negative, False Positive And False Negative2022-08-19T00:00:00+00:002022-08-19T00:00:00+00:00https://blog.shuvangkardas.com/How-To-Remember-Confusion-Matrix;-True-Positive,-True-Negative,-False-Positive-and-False-Negative<p>Every time I read about these four terms i.e. True Positive(TP), True Negative(TN), False Positive(FP), and False Negative, I thought that I got it. Later I get confused and mess up. I guess this happens with you too. Maybe this is the reason these four terms are called confusion matrix or Error Matrix.
<img src="/assets/images/Confusion-Matrix-Fun-Example.png" alt="Confusion Matrix,Image Source Reference 1" /></p>
<p>After Googling these terms I came into this medium blog<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup> of Sarang Narkhede. The picture you see at the top, taken from there and it is convincing. Still, I am not sure about remembering these terms. For remembering things, I always believe in connection. Connection is the best way to store things for the long term. If you read the book How to Take Smart Notes by Sönke Ahrens, you will get a good example of remembering the difference between artery and vein by creating connection with old knowledge. That’s my favorite example. Ok! lot of pep talk. Let’s come to the point.</p>
<p>The confusion matrix is a table of 4 different combinations of predicted and actual values<sup id="fnref:1:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup>. All these terms consist of two words. The first part consists of True/False and the second part Positive/Negative.
You need to remember two connections to understand the confusion matrix:</p>
<ol>
<li><strong>Second part(Positive/Negative) is the predicted value. That comes from your model or test</strong></li>
<li><strong>First part(True/False) verifies the second part. Whether the second part(prediction) is true or false.</strong></li>
</ol>
<p>Consider a hypothetical scenario. A pregnancy test was done on urine samples of a man and woman. The woman is pregnant. Also, look into the picture.</p>
<ul>
<li><strong>True Positive:</strong> The prediction is <strong>Positive</strong>(women pregnant) that is <strong>True</strong></li>
<li><strong>True Negative:</strong> The prediction is <strong>Negative</strong>(man not pregnant) that is <strong>True</strong></li>
</ul>
<p>This time the nurse forgetfully swapped the urine sample of the pregnant woman with a man :p</p>
<ul>
<li><strong>False Positive:</strong> The prediction is <strong>Positive</strong>(man pregnant) that is <strong>False</strong> and impossible!</li>
<li><strong>False Negative:</strong> The prediction is <strong>Negative</strong>(Women not pregnant) that is <strong>False</strong></li>
</ul>
<p>Now Read the two rules again. You will remember the confusion matrix for life.</p>
<hr />
<p>Shuvangkar Das, Potsdam, New York</p>
<p>Connect with me:</p>
<ul>
<li>Twitter: <a href="https://twitter.com/shuvangkar_das">https://twitter.com/shuvangkar_das</a></li>
<li>LinkedIn: <a href="https://www.linkedin.com/in/ShuvangkarDas">https://www.linkedin.com/in/ShuvangkarDas/</a></li>
<li>YouTube: <a href="https://www.youtube.com/ShuvangkarDas">https://www.youtube.com/ShuvangkarDas</a></li>
</ul>
<h2 id="references">References</h2>
<div class="footnotes" role="doc-endnotes">
<ol>
<li id="fn:1" role="doc-endnote">
<p>https://towardsdatascience.com/understanding-confusion-matrix-a9ad42dcfd62 <a href="#fnref:1" class="reversefootnote" role="doc-backlink">↩</a> <a href="#fnref:1:1" class="reversefootnote" role="doc-backlink">↩<sup>2</sup></a></p>
</li>
</ol>
</div>Shuvangkar Dasshuvangkarcdas@gmail.comEvery time I read about these four terms i.e. True Positive(TP), True Negative(TN), False Positive(FP), and False Negative, I thought that I got it. Later I get confused and mess up. I guess this happens with you too. Maybe this is the reason these four terms are called confusion matrix or Error Matrix.Marriage Anniversary Thanking To My Wife And Sine Wave Saga2022-08-05T00:00:00+00:002022-08-05T00:00:00+00:00https://blog.shuvangkardas.com/Marriage-Anniversary-Thanking-to-My-Wife-and-Sine-Wave-Saga<p><img src="/assets/images/Swati-Shuvangkar-3rd-Anniversary.png" alt="Swati Shuvangkar Third Anniversary" />
You will meet many types of people in your life. Some will say 3, some will say 5, and others will say 7 billion. Whatever the number is, I am sure, you will meet a type of person who will change your life and always be there for you, care for you and make your life smoother than before. Swati is that kind of person in my life.</p>
<p>I met Swati in 2018 on Facebook. It was the month of November and I was working on a project at EEE underground lab with Mahinur. We used to chat a lot at that time. It was like writing two lines of code and then instructing Mahinur to test and chat with Swati for another 10 minutes. Those were very good and enjoyable moments of my life. I used to say to Ashis Pal, why everything you do, is so smooth? That time, I also realized that things are smooth if you are with the right person. Finally, we got married after 7 months, 2019. Our marriage went well. Thanks to my sister, my in-laws, my friends, and juniors. And, Thanks to Abir Ahsan Akib. I never had the opportunity to tell you.</p>
<p>Getting married was always a fantasy for Swati and me it was like a lot of reality. I used to tell Swati that living together means you have to adjust a lot of things with your partner that you never know before. At that time, I had a bunch of bad habits that were not considered normal: Working late at night, getting up late after 11:00 AM, and Not knowing how to praise the food. Because we never did that to our mother or sister. We always take it for granted. One day, Swati asked, how is the cooking? I said “ভালই হয়েছে।” I never feel before that there is a huge difference between “ভালো হয়েছে” and “ভালই হয়েছে”।</p>
<p>Swati is always punctual in everything. She gets up early morning, plans everything, eats on time, and take bath on time. On the other hand, I used to be a master procrastinator, with indiscipline in every possible way. I do not have much family time. Do not eat on time and am always busier than I should be. I was such a pile of a mess at that time. O, God! I don’t know how did she like me!</p>
<p>I was such a master procrastinator that I completed my B.Sc. on 2017 and in 2019 I was still procrastinating to sit for GRE. You know, you have nothing to do when you have pressure from higher authority! Finally, I had to sit for GRE, let alone the score. We had a serious financial crisis after marriage. Also, I lost all interest on Job sector in Bangladesh after a bitter experience in my first job. And you know, I used to get up late and I thought that I could not change that. I was the kind of person having a fixed mindset. Swati pushed me to look for a job. I told you before, that you have nothing to do if you have pressure from higher authority.</p>
<p>After getting the job at Adorsho PraniSheba things changed a lot. I am always thankful to PraniSheba and will remember them all the time. COVID-19 hit at that time and I was working from home. COVID was a terrible experience for many people. But, for us, it was a kind of blessing. It was the first time after the marriage, we started to live happily. We together started improving our life gradually. We improved our food habits together. Cut carbohydrates and sugar from our diet as much as we can. One example is we used to use green papaya instead of potatoes on all menus. Everybody gained wait at that time but we did not. That’s a long story, I will write another day about how did we manage our weight and do cooking in a short time.</p>
<p>Then. I got admission in 2020 at Clarkson University for the fall semester. But, could not come due to COVID-19. I also lost my funding. We became sad again.</p>
<p>Finally, we came to the USA on 7th July 2021 after struggling for 1 and half years hoping to start a new life. I had to change my field of interest. Swati was also trying her best to manage admission and funding. Together we went through a lot of struggles. That’s a long story. Maybe another day.</p>
<p>It was April 2022. Swati got full funding admission at Clarkson University. Finally, her hard work paid off. We became so happy. Swati got more confident the before. I used to tell her, that people need only one success to become confident and have momentum in life. Finally, I felt that she got it. We planned a lot of things for the fall,2022 semester. Go for classes together, take the same course, buy a car, decorate our home, make YouTube videos on “Research Hack” that I have developed for doing research smartly, writing blogs on my site regularly. We went to Bangladesh this July for her visa with a lot of hopes. But, you know “Man proposes God disposes”. It is very frustrating when you have nothing to do in your favor.</p>
<p>I like the sine wave more than the cos wave because It always starts from zero and I always treat the cos wave-like “বেশী বুঝে” because it starts from the peak. I always thought that life is like a sine wave. There is no happily ever after things like movies or stories. You will have happy moments like the peak and sad moments like the valley. All that matter is, never stop the wave and try to make SNR(Signal-To-Noise Ratio) positive as much as possible so that you have more signal than noise.</p>
<p>That’s why I and Swati never wait to celebrate happy moments. We always tried to celebrate happy moments instantly. You never know what comes 10 minutes later.</p>
<p>From that opposite pole person, I am on the same pole as her. We get up at 5:00 AM, do everything properly, plan properly, do not procrastinate things, have a good life, maintain a healthy food habit, go for walk every day, tell stories every day after dinner and watch movies frequently, read books daily. Moreover, Not doing bad in my Ph.D. and coursework. Before I believed in the fixed mindset, Now I am improving my growth mindset. Before I had little family time, Now I have enough family time after doing all the professional responsibilities. Before I believe that working hard makes a person successful, Now I believe that working smartly makes people successful. You do not only need a little discipline and planning to manage everything but also need the right partner. I always regret that I should know her earlier. I would be in a better position than I am in now. Thanks a lot to YOU for making my life better and awesome in every possible way. Happy marriage anniversary LOVE <3 . We will be together soon.</p>
<p>Note:
I am starting <a href="https://www.getrevue.co/profile/shuvangkar_das">my newsletter</a>
Please subscribe to get weekly update.</p>Shuvangkar Dasshuvangkarcdas@gmail.comYou will meet many types of people in your life. Some will say 3, some will say 5, and others will say 7 billion. Whatever the number is, I am sure, you will meet a type of person who will change your life and always be there for you, care for you and make your life smoother than before. Swati is that kind of person in my life.Custom Data Structure Guide For Arduino And Microcontroller Project2022-06-26T00:00:00+00:002022-06-26T00:00:00+00:00https://blog.shuvangkardas.com/Custom-Data-Structure-Guide-For-Arduino-and-Microcontroller-Project<p>Data structure provides an efficient way of organizing data and functionality in the computer system. Good data structure design makes the system efficient and fast. It also helps to write modular code. You might be familiar with these types of data structure: Queue, Stack, Array, List, Tree. Apart from these standard data structures, you can design our custom data structure according to project requirements. It is very important to learn how to create custom data structures and build the functions around them. It will ease your firmware development and makes the code more portable and readable. </p>
<p>I learned embedded system programming in 2013. I used to use a lot of global variables at the beginning. As a result, I had no choice other than writing messy code at that time. Gradually, I have to master writing modular and efficient code simply by designing a good data struct or utilizing object-oriented programming. This data structure design pattern can be used with any microcontroller and Arduino project. Previously, I have employed these techniques in many projects including AVR microcontroller, PIC microcontroller, MSP430 microcontroller, ESP32, ESP8266, and ARM microcontrollers as well as Arduino.</p>
<h3 id="why-do-you-need-to-design-a-custom-data-structure">Why do you need to design a custom data structure?</h3>
<p>Consider you are going to design a toy data acquisition system for temperature and humidity. You will put the timestamp and device id with the sensor data. So, you need to allocate these four variables for this system. </p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">int</span> <span class="n">devideId</span><span class="p">;</span>
<span class="kt">uint32_t</span> <span class="n">unixTime</span><span class="p">;</span>
<span class="kt">float</span> <span class="n">temperature</span><span class="p">;</span>
<span class="kt">float</span> <span class="n">humidity</span>
</code></pre></div></div>
<p>Yes, you can use these variables as a global variable and build your whole system. In this way, you cannot make a modular system. Because, whenever you want to build any pure function you have to pass all the variables as a function parameter. A pure function is a type of function that does not depend on global variables. Moreover, you have to use these four variables in different files. That will result in less readable and maintainable code. Think about a scenario, where you want to send the sensor data to a web server and you have written a function as follows.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="nf">sendData</span><span class="p">(</span><span class="kt">int</span> <span class="n">devId</span><span class="p">,</span> <span class="n">uint32</span> <span class="n">time</span><span class="p">,</span> <span class="n">foat</span> <span class="n">temp</span><span class="p">,</span> <span class="kt">float</span> <span class="n">hum</span><span class="p">)</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="c1">//code for sending data to the server</span>
<span class="p">}</span>
</code></pre></div></div>
<p>See!, you have to pass a bunch of variables to design a send function. When you have a lot of data, it would be very difficult to deal with. Of course, you can put all the variables into an array and pass the pointer. But that is less intuitive. Also, you can use a global variable for the data and use that variable in the send function. Remember one thing, the more you use global variables in your system, the more your code loses readability and portability. Also global variable performs slower than the local variable. So it is not a good programming practice to use many global variables in any project. Of course, you cannot neglect global variables in embedded system design because you also have to care about the RAM. Nevertheless, you should avoid using too many global variables.</p>
<h3 id="how-do-you-design-custom-data-structure">How do you design custom data structure?</h3>
<p>Designing custom data structures in C and C++ is fairly straightforward. You can use <code class="language-plaintext highlighter-rouge">structure</code> to design the data structure for your toy data acquisition system.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">struct</span> <span class="n">sensorData_t</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="kt">int</span> <span class="n">deviceId</span><span class="p">;</span>
<span class="err"> </span> <span class="err"> </span><span class="kt">uint32_t</span> <span class="n">unixTime</span><span class="p">;</span>
<span class="err"> </span> <span class="err"> </span><span class="kt">float</span> <span class="n">temperature</span><span class="p">;</span>
<span class="err"> </span> <span class="err"> </span><span class="kt">float</span> <span class="n">humidity</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></div></div>
<p>Now <code class="language-plaintext highlighter-rouge">sensorData_t</code> structure holds all the related variables. You also need to remember carefully that <code class="language-plaintext highlighter-rouge">struct sensorData_t</code> is a derived structure data type, not a structure variable, just like <code class="language-plaintext highlighter-rouge">int</code> data type. using the <code class="language-plaintext highlighter-rouge">struct sensorData_t</code> data type you can declare as many variables as you want. </p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">struct</span> <span class="n">sensorData_t</span> <span class="n">sensorData1</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">sensorData_t</span> <span class="n">sensorData2</span>
</code></pre></div></div>
<p>Now the question is how can you use this simple data structure to modularize your whole system? We are going to explore that in the subsequent discussion. </p>
<h3 id="how-to-apply-data-structure-for-building-fuctions">How to apply data structure for building fuctions</h3>
<p>Let’s consider that you have implemented these functions to read all the sensors and store the variables. You also performed unit testing on these functions to make sure everything is working fine.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">int</span> <span class="nf">getDeviceId</span><span class="p">();</span>
<span class="kt">uint32_t</span> <span class="nf">getUnixTime</span><span class="p">();</span>
<span class="kt">float</span> <span class="nf">readTemperature</span><span class="p">();</span>
<span class="kt">float</span> <span class="nf">readHumidity</span><span class="p">();</span>
</code></pre></div></div>
<p>Now I am going to utilize these functions to build a sensor read function for your toy data acquisition system. I discussed earlier that <code class="language-plaintext highlighter-rouge">struct sensorData_t</code> is the derived data type and <code class="language-plaintext highlighter-rouge">sensorData</code> is the variable of that type. So don’t be confused about function parameters. If you do, please put your comment below. </p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="nf">readSensors</span><span class="p">(</span><span class="k">struct</span> <span class="n">sensorData_t</span> <span class="n">sensorData</span><span class="p">)</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorData</span><span class="p">.</span><span class="n">deviceId</span> <span class="o">=</span> <span class="n">getDeviceId</span><span class="p">();</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorData</span><span class="p">.</span><span class="n">unixTime</span><span class="o">=</span> <span class="n">getUnixTime</span><span class="p">();</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorData</span><span class="p">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="n">readTemperature</span><span class="p">();</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorData</span><span class="p">.</span><span class="n">humidity</span> <span class="o">=</span> <span class="n">readHumidity</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Now, you can write the <code class="language-plaintext highlighter-rouge">readSensor()</code> function to collect all the sensor’s data and metadata. Consider, in your system, you are collecting data every second and after a one-minute interval, you will send all the data to the server because you want to reduce the communication burden. Moreover, it is not efficient to communicate with the server every second.
Let’s write the pseudocode to collect one minute(60 seconds) of data.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">//for 60 seconds 60 buffers of sensorData_t</span>
<span class="k">struct</span> <span class="n">sensorData_t</span> <span class="n">sensorBuffer</span><span class="p">[</span><span class="mi">60</span><span class="p">];</span><span class="err"> </span>
<span class="k">for</span><span class="p">(</span><span class="kt">uint8_t</span> <span class="n">i</span><span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o"><</span> <span class="mi">60</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="n">readSensors</span><span class="p">(</span><span class="n">sensorBuffer</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="err"> </span> <span class="err"> </span><span class="c1">//using delay is not efficient. This is just for demo</span>
<span class="err"> </span> <span class="err"> </span><span class="n">delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span><span class="err"> </span>
<span class="p">}</span>
</code></pre></div></div>
<p>After one minute interval, you will have a big buffer that contains data for the last 60 seconds. Here, the big! is considered concerning a microcontroller. This is how you simplify all the data management using a simple structure. Most newbies in the embedded systems are supposed to use big arrays for different variables. Now you can send this <code class="language-plaintext highlighter-rouge">sensorBuffer</code> using any communication channels such as a Wi-Fi module(ESP32), SIM module(SIM800L), or any custom radio module such as nRF24L01, ZigBee, etc.</p>
<p>But still, there is a problem with this approach. Whenever your data structure has a lot of variables and strings, it is not going to work depending on our microcontroller register size. If you look into the <code class="language-plaintext highlighter-rouge">void readSensors(struct sensorData_t sensorData)</code> function, you may observe that every time, you are calling the function it is passing the 14 bytes(size of <code class="language-plaintext highlighter-rouge">sensorData_t</code>) of data as the function input. This will be super slow and inefficient and what will happens if the data structure is bigger than the size of registers?</p>
<p>You can solve this problem easily by leveraging the pointer concept. If you are afraid of hearing the word pointer, I was in your shoe a few years back. Let me tell you a secret about the pointer. Pointer just keeps the location information of variable. That means the size of a pointer is the same irrespective of data type. For example, For <code class="language-plaintext highlighter-rouge">int</code> pointer variable size and a <code class="language-plaintext highlighter-rouge">float</code> pointer variable size is the same, 2 bytes for AVR/Arduino Uno microcontroller. I will write in detail about the pointer and plan to make a YouTube video on my channel. Up to this point, you don’t have to worry much about pointer. </p>
<p>Let’s redefine the <code class="language-plaintext highlighter-rouge">void readSensors(struct sensorData_t sensorData)</code> function using pointer. You need to remember one thing, in the case of accessing a member of a structure, before I useed dot(<code class="language-plaintext highlighter-rouge">.</code> )operator. For structure pointer, you have to use the right arrow( <code class="language-plaintext highlighter-rouge">-></code> )operator for accessing members. That’s the little change you have to accept for now, if you are afraid of the pointer. I believe you can do this. </p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">void</span> <span class="nf">readSensors</span><span class="p">(</span><span class="k">struct</span> <span class="n">sensorData_t</span> <span class="o">*</span><span class="n">sensorPtr</span><span class="p">)</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="c1">//accesing deviceId member of the structure pointer</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorPtr</span><span class="o">-></span><span class="n">deviceId</span> <span class="o">=</span> <span class="n">getDeviceId</span><span class="p">();</span><span class="err"> </span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorPtr</span><span class="o">-></span><span class="n">unixTime</span><span class="o">=</span> <span class="n">getUnixTime</span><span class="p">();</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorPtr</span><span class="o">-></span><span class="n">temperature</span> <span class="o">=</span> <span class="n">readTemperature</span><span class="p">();</span>
<span class="err"> </span> <span class="err"> </span><span class="n">sensorPtr</span><span class="o">-></span><span class="n">humidity</span> <span class="o">=</span> <span class="n">readHumidity</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Yeah!! now see, the new <code class="language-plaintext highlighter-rouge">readSensors()</code> function takes the pointer of the <code class="language-plaintext highlighter-rouge">struct sensorData_t</code> type as input. If you analyze the size of input that should not be more than 4 bytes depending on the CPU architecture. For the AVR microcontroller, the pointer size is 2 bytes. That is far less than the previous 14 bytes as whole structure input. Let’s rewrite the previous code for reading sensor data in 60 seconds intervals.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">//for 60 seconds 60 buffers of sensorData_t </span>
<span class="k">struct</span> <span class="n">sensorData_t</span> <span class="n">sensorBuffer</span><span class="p">[</span><span class="mi">60</span><span class="p">];</span><span class="err"> </span>
<span class="k">for</span><span class="p">(</span><span class="kt">uint8_t</span> <span class="n">i</span><span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o"><</span> <span class="mi">60</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="c1">//Just & operator for passing pointer of sensorbuffer[i]</span>
<span class="err"> </span> <span class="err"> </span><span class="n">readSensors</span><span class="p">(</span><span class="o">&</span><span class="n">sensorBuffer</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="err"> </span> <span class="err"> </span><span class="n">delay</span><span class="p">(</span><span class="mi">1000</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
<p>See!, you just need to do one single change to get the code memory efficient and faster than before. Now you need to pass the pointer of each <code class="language-plaintext highlighter-rouge">struct sensorData_t</code> variable. If you use <code class="language-plaintext highlighter-rouge">&</code> operator before any variable, it means the address of that variable, not the variable itself. In this way, you can pass the pointer(address) of the variable.</p>
<h3 id="ease-debugging-using-data-structure">Ease debugging using data structure</h3>
<p>Now you have a custom data structure for sensor data payload. Leveraging the structure, you can build a bunch of functions for doing the different tasks on the sensor data. For debugging the data, you need a print function. So that you can use the same function throughout the whole codebase for debugging the sensor data. Let’s see, how can we write such a function for doing such a task? For demonstrating the printing, I am going to use the Arduino default print function, but the method is the same for different microcontroller platforms.</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">printSensor</span><span class="p">(</span><span class="k">struct</span> <span class="n">sensorData_t</span> <span class="o">*</span><span class="n">sensorPtr</span><span class="p">)</span>
<span class="p">{</span>
<span class="err"> </span> <span class="err"> </span><span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s">"<---------Sensor Data----------------->"</span><span class="p">));</span>
<span class="err"> </span> <span class="err"> </span><span class="n">Serial</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s">"Time: "</span><span class="p">));</span> <span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">sensorPtr</span><span class="o">-></span> <span class="n">unixTime</span><span class="p">);</span>
<span class="err"> </span> <span class="err"> </span><span class="n">Serial</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s">"Device ID: "</span><span class="p">));</span><span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">sensorPtr</span> <span class="o">-></span> <span class="n">deviceId</span><span class="p">);</span>
<span class="err"> </span> <span class="err"> </span><span class="n">Serial</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s">"Temperature: "</span><span class="p">));</span><span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">sensorPtr</span> <span class="o">-></span> <span class="n">temperature</span><span class="p">)</span>
<span class="err"> </span> <span class="err"> </span><span class="n">Serial</span><span class="p">.</span><span class="n">print</span><span class="p">(</span><span class="n">F</span><span class="p">(</span><span class="s">"Humidity: "</span><span class="p">));</span><span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">sensorPtr</span> <span class="o">-></span> <span class="n">humidity</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Voila! you can write any function using the same data structure. Now you can organize our code in a good manner no matter how many sensors you want to log. Another good point of using such a design pattern is that the code would be portable and manageable. Imagine, next time you need to add another sensor such as a voltage sensor, you don’t have to change your whole codebase. You will just add the variable inside your data structure and makes changes inside the function. You don’t have to work on the upper layer function that you have already built on top of this file.</p>
<p>In the next part, I will add more functionality using the same data structure. Happy coding!!</p>
<p>-Shuvangkar Das, Potsdam, New York</p>
<h3 id="interesting-things-i-am-doing-currently">Interesting Things I Am Doing Currently</h3>
<p>Everyone does some form of knowledge work but most of the time does that inefficiently. As a result, despite working hard, we ended up with questionable results. So to address that I am working on a very exciting project name Smart Personal Knowledge Management(SPKM). In fact, I am making a YouTube video series on it. You can get update about the course in two ways, (1) by subscribing to my <a href="https://www.youtube.com/ShuvangkarDas">YouTube</a> channel or (2) by subscribing my <a href="http://newsletter.shuvangkardas.com/">newsletter</a></p>
<h3 id="connect-with-me">Connect with me</h3>
<ul>
<li>Twitter: <a href="https://twitter.com/shuvangkar_das">https://twitter.com/shuvangkar_das</a></li>
<li>LinkedIn: <a href="https://www.linkedin.com/in/ShuvangkarDas/">https://www.linkedin.com/in/ShuvangkarDas/</a></li>
<li>YouTube: <a href="https://www.youtube.com/ShuvangkarDas">https://www.youtube.com/ShuvangkarDas</a></li>
</ul>Shuvangkar Dasshuvangkarcdas@gmail.comIt is very important to learn how to create custom data structures and build the functions around them. It will ease your firmware development and makes the code more portable and readable. Linux Basic Commands Cheatsheet2022-06-25T00:00:00+00:002022-06-25T00:00:00+00:00https://blog.shuvangkardas.com/Linux-Basic-Commands-Cheatsheet<p>Working flawlessly with Linux mostly depends on how well we know the Linux commands. It really needs time to be good at all the Linux commands. The purpose of this document is to list all the basic commands so that anyone can get help.</p>
<h3 id="linux-command-structures">Linux Command Structures</h3>
<p>A command is a program that tells the system to do something. It has a structure like <code class="language-plaintext highlighter-rouge">command [options] [arguments]</code></p>
<ul>
<li>The command works on a particular argument. <code class="language-plaintext highlighter-rouge">arguments</code> are like extra pieces of information to perform the command. Here <code class="language-plaintext highlighter-rouge">arguments</code> are like function arguments that tell the command what to perform</li>
<li>On the other hand, <code class="language-plaintext highlighter-rouge">options</code> are used to control the command behavior.
<ul>
<li><code class="language-plaintext highlighter-rouge">options</code> are generally letter preceded by a hyphen(-). e.g. <code class="language-plaintext highlighter-rouge">ls -a</code> or word preceded by a double hyphen(—). e.g. <code class="language-plaintext highlighter-rouge">ls --help</code></li>
<li>More than one option can be used with a command in two forms. such as separate form and lumped form.</li>
<li>Separate form is like <code class="language-plaintext highlighter-rouge">command -[option] -[option] - [option]</code>. e.g. <code class="language-plaintext highlighter-rouge">ls -a -l -t</code></li>
<li>For most commands, more than one option can be lumped together to form <code class="language-plaintext highlighter-rouge">command -[option][option]</code>. e.g. <code class="language-plaintext highlighter-rouge">ls -alt</code>. One thing to remember is that not all commands support lumped options but most command supports.</li>
</ul>
</li>
</ul>
<h3 id="sudo">sudo</h3>
<p><code class="language-plaintext highlighter-rouge">sudo</code> means superuser do. whenever <code class="language-plaintext highlighter-rouge">sudo</code> is used before any command, it allows the current user to have root privilege temporarily for the current command.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo rm</span> <span class="nt">-rf</span> dir1# recursively delete the dir1 folder as root user privilege
</code></pre></div></div>
<h3 id="linux-file-system">Linux File System</h3>
<p>The computer organizes files in a tree-like structure that is known as the file system. Linux has a single file tree system that begins with the root directory(/). One thing we always have to remember is that in Linux almost everything is a file including a USB Device, Hard disk, etc.</p>
<ul>
<li>File names are not case sensitive</li>
<li>file begin with<code class="language-plaintext highlighter-rouge">.</code> used for the configuration file</li>
</ul>
<h3 id="linux-frequently-used-basic-commands">Linux frequently used basic commands</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">cd</code> - To change directory</li>
<li><code class="language-plaintext highlighter-rouge">mkdir</code> - make/create directory</li>
<li><code class="language-plaintext highlighter-rouge">pwd</code> - Print Current directory</li>
<li><code class="language-plaintext highlighter-rouge">ls</code> - List Directory Content</li>
<li><code class="language-plaintext highlighter-rouge">cp</code> - copy files and directory</li>
<li><code class="language-plaintext highlighter-rouge">mv</code> - Move or rename file</li>
<li><code class="language-plaintext highlighter-rouge">rm</code> - remove directory and files</li>
<li><code class="language-plaintext highlighter-rouge">rmdir</code> - Use to remove only empty directory. It does not delete directory that is not empty.</li>
<li><code class="language-plaintext highlighter-rouge">cat</code> - Concatenate and display the whole file</li>
<li><code class="language-plaintext highlighter-rouge">exit</code> to exit the terminal from the command line</li>
<li><code class="language-plaintext highlighter-rouge">clear</code> clear terminal</li>
</ul>
<h3 id="common-linux-flags">Common Linux Flags</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">-h</code> - Help flag</li>
<li><code class="language-plaintext highlighter-rouge">-v</code> - indicate verbosely.</li>
</ul>
<h3 id="directory-and-navigation">Directory and Navigation</h3>
<p>There are two ways to denote a path. relative path and absolute path. Relative path refers to a path relative to the current directory. On the other hand, the absolute path starts at the root(/) directory and we can reference it from anywhere in the file system.</p>
<ul>
<li>Shortcut notation to the directory
<ul>
<li><code class="language-plaintext highlighter-rouge">/</code> root directory</li>
<li><code class="language-plaintext highlighter-rouge">.</code> Current directory</li>
<li><code class="language-plaintext highlighter-rouge">..</code> Parent directory</li>
<li><code class="language-plaintext highlighter-rouge">~</code> Home directory</li>
<li><code class="language-plaintext highlighter-rouge">-</code> Previous directory</li>
</ul>
</li>
<li><code class="language-plaintext highlighter-rouge">pwd</code> Print the Current Working Directory</li>
<li><code class="language-plaintext highlighter-rouge">cd /</code> Go to the root directory</li>
<li><code class="language-plaintext highlighter-rouge">cd ..</code> Go to the parent directory</li>
<li><code class="language-plaintext highlighter-rouge">cd ~</code> Go to Home directory</li>
<li><code class="language-plaintext highlighter-rouge">cd -</code>Go to the previous directory</li>
<li><code class="language-plaintext highlighter-rouge">cd /dir1/dir2</code> Navigate to a particular directory</li>
</ul>
<h3 id="folder--file-create">Folder & File Create</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">mkdir dir1</code> Create directory named dir1 inside the current working directory</li>
<li><code class="language-plaintext highlighter-rouge">mkdir -p /dir1/testDir</code> Create a directory inside dir1. If dir1 does not exist the -p flag indicates that create parent directory <code class="language-plaintext highlighter-rouge">dir1</code> if needed.</li>
<li><code class="language-plaintext highlighter-rouge">touch shuvangkar.txt</code> Create a text file inside the current directory named shuvangkar.txt</li>
<li><code class="language-plaintext highlighter-rouge">touch /dir1/testfile</code> Create <code class="language-plaintext highlighter-rouge">testfile</code> file inside dir1</li>
</ul>
<h3 id="file-and-directory-listing">File and Directory Listing</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">ls</code> command options
<ul>
<li>-l = long listing</li>
<li>-a= list hiddent files</li>
<li>-r = list in reverse name</li>
<li>-t = list new files first</li>
<li>rt = list in reverse time(oldest first)</li>
</ul>
</li>
<li><code class="language-plaintext highlighter-rouge">ls -l /tmp/dir1/</code> show to long listing of all files inside <code class="language-plaintext highlighter-rouge">/tmp/dir1/</code></li>
</ul>
<p>Here is a example of file listing and what the different notations indicate.</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>drwxr-xr-x 2 pi pi 4096 May 25 20:47 Desktop
<span class="nt">-rw-r--r--</span> 1 pi pi 5781 Feb 3 07:07 ocr_pi.png
drwxrwxr-x 2 pi pi 4096 Mar 10 12:20 python_games
<span class="nt">--------</span> <span class="nt">-------</span> <span class="nt">-------</span> <span class="nt">--------</span> <span class="nt">------------</span> <span class="nt">-------------</span>
| | | | | |
| | | | | File Name
| | | | |
| | | | +--- Modification Time
| | | |
| | | +------------- Size <span class="o">(</span><span class="k">in </span>bytes<span class="o">)</span>
| | |
| | +----------------------- Group
| |
| +-------------------------------- Owner
|
+---------------------------------------------- File Permissions
</code></pre></div></div>
<h3 id="copy-files--directories">Copy Files & Directories</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">cp [option] [source] [destination]</code> Common format for <code class="language-plaintext highlighter-rouge">cp</code> command.</li>
<li>To perform the copy operation, the source must have read permission and the destination must have write permission. Otherwise, permission denied error is shown.</li>
<li>The source can be single or multiple files or directories. destination have to be single file or directory</li>
<li><code class="language-plaintext highlighter-rouge">cp file1 backfile1</code> copy <code class="language-plaintext highlighter-rouge">file1</code> content to <code class="language-plaintext highlighter-rouge">backupfile</code></li>
<li><code class="language-plaintext highlighter-rouge">cp file1.txt file2.txt dir1</code> copy <code class="language-plaintext highlighter-rouge">file1.txt</code> and <code class="language-plaintext highlighter-rouge">file2.txt</code> to the directory <code class="language-plaintext highlighter-rouge">dir1</code>. When copying multiple files the destination must be a directory.</li>
<li><code class="language-plaintext highlighter-rouge">cp -r -v /tmp/sourcedir desDir/</code> copy <code class="language-plaintext highlighter-rouge">sourcedir</code> into <code class="language-plaintext highlighter-rouge">destDir</code>. <code class="language-plaintext highlighter-rouge">-r</code> flag indicates recursively means copying whole directory contents. <code class="language-plaintext highlighter-rouge">-v</code> indicate show verbose output while copying</li>
</ul>
<h3 id="move--rename">Move & Rename</h3>
<p>Move command(mv) has two functions. By default Linux does not have rename option. So it rename file and folder. It default function is to move files and folder</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">mv [options] [source] [destination]</code> Default syntax</li>
<li><code class="language-plaintext highlighter-rouge">mv file1.txt diffname.txt</code> rename <code class="language-plaintext highlighter-rouge">file1.txt</code> to <code class="language-plaintext highlighter-rouge">diffname.txt</code></li>
<li><code class="language-plaintext highlighter-rouge">mv file1.txt file2.txt dir1</code> move both of the files in folder dir1</li>
<li><code class="language-plaintext highlighter-rouge">mv /tmp/testfile .</code> Move <code class="language-plaintext highlighter-rouge">testfile</code> to the current directory</li>
<li><code class="language-plaintext highlighter-rouge">mv *.txt dir2</code> move all text file to dir2 folder</li>
</ul>
<h3 id="delete-files--directory">Delete Files & Directory</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">rm /dir1/testfile</code> remove <code class="language-plaintext highlighter-rouge">testfile</code> from <code class="language-plaintext highlighter-rouge">dir1</code> folder</li>
<li><code class="language-plaintext highlighter-rouge">rmdir /tmp/testdir</code> remove <code class="language-plaintext highlighter-rouge">testdir</code> if it is empty</li>
<li><code class="language-plaintext highlighter-rouge">rm -r /tmp/testdir</code> recursively delete <code class="language-plaintext highlighter-rouge">testdir</code> folder</li>
<li><code class="language-plaintext highlighter-rouge">rm -rf /tmp/testdir</code> -f flag indicate force delete. -r indicate recursively</li>
</ul>
<h3 id="ubuntu-software-install-and-uninstall">Ubuntu Software Install and Uninstall</h3>
<p>In Linux, world software is the package. Different Linux distribution has different package management tools. RedHat has yum, Debian has apt. apt(Advanced Packaging Tool) is the default package management tool for Ubuntu</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">sudo apt update</code> update the local package list with the latest change made in the repositories</li>
<li><code class="language-plaintext highlighter-rouge">sudo apt upgrade</code> First update package index using update command and then this command upgrades all package</li>
<li><code class="language-plaintext highlighter-rouge">sudo apt install <package_name></code> Install a particular package from package_name</li>
<li><code class="language-plaintext highlighter-rouge">sudo apt install -y git</code> The option -y tells the apt to assume the answer to all prompts is yes</li>
<li><code class="language-plaintext highlighter-rouge">sudo apt remove <package_name></code> remove package but leave configs</li>
<li><code class="language-plaintext highlighter-rouge">sudo apt purge <package_name></code> remove package and configs. It may not be the desired effect. So use with caution</li>
<li><code class="language-plaintext highlighter-rouge">apt search filezilla</code> search <code class="language-plaintext highlighter-rouge">filezilla</code> package</li>
<li><code class="language-plaintext highlighter-rouge">apt autoremove</code> remove the unnecessary package file</li>
</ul>
<p>Note: While apt is a command-line tool, it is intended to be used interactively, and not to be called from non-interactive scripts. The apt-get command should be used in scripts (perhaps with the –quiet flag). For basic commands the syntax of the two tools is identical.</p>
<h3 id="install-package-from-deb-file">Install package from .deb file</h3>
<ul>
<li>download the .deb package. such as <code class="language-plaintext highlighter-rouge">sublime.deb</code></li>
<li>Go to the file directory and install the package using the command <code class="language-plaintext highlighter-rouge">sudo apt install ./sublime.deb</code></li>
</ul>
<h3 id="how-to-get-help">How To Get Help</h3>
<p>Linux manual is a great source of getting information related to any command. Here is multiple examples of how we can get information related to <code class="language-plaintext highlighter-rouge">gzip</code></p>
<ul>
<li><code class="language-plaintext highlighter-rouge">man -k gzip</code> finds gzip related manual</li>
<li><code class="language-plaintext highlighter-rouge">gzip --help</code> print quick list of manual</li>
<li><code class="language-plaintext highlighter-rouge">man gzip</code> Manual open</li>
</ul>
<h3 id="linux-networking">Linux Networking</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">ip -j -p addr show</code> To list network details in JSON format</li>
</ul>
<h3 id="generate-ssh-key-and-copy-on-the-clipboard">Generate SSH Key and Copy on the clipboard</h3>
<ol>
<li>/dev/zero is a special file that provides an endless stream of null characters that is used to create file or memory pages.</li>
</ol>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt <span class="nb">install </span>xclip <span class="nt">-y</span> <span class="c">#xclip will copy the ssh file</span>
<span class="nb">cat</span> /dev/zero | ssh-keygen <span class="nt">-t</span> ed25519 <span class="nt">-C</span> <span class="s2">"keyname"</span> <span class="nt">-q</span> <span class="nt">-N</span> <span class="s2">"passphrase"</span>
xclip <span class="nt">-sel</span> clip <~/.ssh/id_ed25519.pub
</code></pre></div></div>
<h3 id="more-commands">More commands</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">name -a</code> It prints all the system information in the following order: Kernel name, network node hostname, kernel release date, kernel version, machine hardware name, hardware platform, operating system</li>
</ul>
<h3 id="deal-with-executable">Deal with Executable</h3>
<ul>
<li><code class="language-plaintext highlighter-rouge">which mv</code> which command returns the path of executables. Here return the location of the move command</li>
</ul>
<h3 id="more-linux-command-documents">More Linux command documents</h3>
<p>Here is the list of cheat sheets we can explore more.</p>
<ol>
<li>IP command cheatsheet</li>
</ol>
<p><a href="https://access.redhat.com/sites/default/files/attachments/rh_ip_command_cheatsheet_1214_jcs_print.pdf"></a></p>
<h3 id="control-service">Control Service</h3>
<p><code class="language-plaintext highlighter-rouge">systemctl</code> and <code class="language-plaintext highlighter-rouge">service</code> are two commands to control services.</p>
<p><code class="language-plaintext highlighter-rouge">service</code> is high level command used for <code class="language-plaintext highlighter-rouge">start,</code> <code class="language-plaintext highlighter-rouge">restart</code>, <code class="language-plaintext highlighter-rouge">stop</code>, <code class="language-plaintext highlighter-rouge">status</code> of a service.</p>
<p>On the other hand <code class="language-plaintext highlighter-rouge">systemctl</code> can do lot more than <code class="language-plaintext highlighter-rouge">service</code>. It can load service parallel at startup, it can mask or unmask service and lot more.</p>
<ul>
<li><code class="language-plaintext highlighter-rouge">service script-name command</code> command can be <code class="language-plaintext highlighter-rouge">start,</code> <code class="language-plaintext highlighter-rouge">restart</code>, <code class="language-plaintext highlighter-rouge">stop</code></li>
<li><code class="language-plaintext highlighter-rouge">systemctl command servicename.service</code> command = start/stop/enable/reload/restart/</li>
</ul>Shuvangkar Dasshuvangkarcdas@gmail.comWorking flawlessly with Linux mostly depends on how well we know the Linux commands. It really needs time to be good at all the Linux commands. The purpose of this document is to list all the basic commands so that anyone can get help.Vagrant Cheatsheet2022-02-09T00:00:00+00:002022-02-09T00:00:00+00:00https://blog.shuvangkardas.com/Vagrant-Cheatsheet<ul>
<li><code class="language-plaintext highlighter-rouge">vagrant</code> Verify vagrant installation</li>
<li><code class="language-plaintext highlighter-rouge">vagrant init hashicorp/bionic64</code> This will create a <code class="language-plaintext highlighter-rouge">Vagrantfile</code> in current directory</li>
<li><code class="language-plaintext highlighter-rouge">vagrant up</code> start the virtual machine from the Vagrantfile configuration</li>
<li><code class="language-plaintext highlighter-rouge">vagrant halt</code> shutdown VM preserving content of the disk</li>
<li><code class="language-plaintext highlighter-rouge">vagrant reload</code> This will quickly restart your virtual machine, skipping the initial import step</li>
<li><code class="language-plaintext highlighter-rouge">vagrant reload --provision</code> The provision flag on the reload command instructs Vagrant to run the <code class="language-plaintext highlighter-rouge">provisioners</code>, since usually Vagrant will only do this on the first <code class="language-plaintext highlighter-rouge">vagrant up</code></li>
<li><code class="language-plaintext highlighter-rouge">vagrant supend</code> Stop the virtual machine and save the current state</li>
<li><code class="language-plaintext highlighter-rouge">vagrant ssh</code> SSH into the machine</li>
<li><code class="language-plaintext highlighter-rouge">vagrant destroy</code> Destroy the virtual machine</li>
<li><code class="language-plaintext highlighter-rouge">vagrant box list</code> show the list of downloaded box</li>
<li><code class="language-plaintext highlighter-rouge">vagrant box remove hashicorp/bionic64</code> vagrant destroy does not remove the downloaded box. remove command delete the downloaded box</li>
<li><code class="language-plaintext highlighter-rouge">ls /vagrant</code> Explore the sync folder between host and guest machine</li>
</ul>Shuvangkar Dasshuvangkarcdas@gmail.comvagrant Verify vagrant installation vagrant init hashicorp/bionic64 This will create a Vagrantfile in current directory vagrant up start the virtual machine from the Vagrantfile configuration vagrant halt shutdown VM preserving content of the disk vagrant reload This will quickly restart your virtual machine, skipping the initial import step vagrant reload --provision The provision flag on the reload command instructs Vagrant to run the provisioners, since usually Vagrant will only do this on the first vagrant up vagrant supend Stop the virtual machine and save the current state vagrant ssh SSH into the machine vagrant destroy Destroy the virtual machine vagrant box list show the list of downloaded box vagrant box remove hashicorp/bionic64 vagrant destroy does not remove the downloaded box. remove command delete the downloaded box ls /vagrant Explore the sync folder between host and guest machineTips For Sampling High Speed Analog Signal In Arduino2022-01-14T00:00:00+00:002022-01-14T00:00:00+00:00https://blog.shuvangkardas.com/Tips-For-Sampling-High-Speed-Analog-Signal-in-Arduino<p>It was 2013. I was doing my undergraduate at the Bangladesh University of Engineering and Technology(BUET). I had a power system course along with a lab course in my second year. I had to develop a hardware project on a power factor improvement plant as the requirement of the lab course. I was very excited about the project as it was my first hardware project as in undergraduate. The very next day I bought a bunch of components for the project. Potential transformer(PT), Current Transformer(PT), ATmega microcontroller, and many discrete components. I eagerly started experimenting with the sensors. As I had the experience of working with microcontrollers beforehand, I started everything smoothly.</p>
<p>The next day, I started my experiment by sampling a 50Hz sine wave and then transferring the signal into the PC through serial. My main goal was to visualize the 50Hz signal before measuring the current, voltage, and power factor. But unfortunately, I did not see the sine was as expected. Instead, it was like noise. I looked into the connections and code again and again, but could not figure out any potential flaws.</p>
<p>A few days later, looking into different blogs, I figured out the mistakes I was doing while sampling the signal. Later, I found that everyone does the same mistakes although it is easy to understand. The purpose of this blog is to explain common mistakes we do, while sampling analog signals and how to avoid them.</p>
<h2 id="common-mistake-in-sampling-analog-signal-using-adc">Common mistake in sampling analog signal using ADC</h2>
<p>I was sampling the 50Hs sine wave and sending the signal through serial communication. That was a very bad idea of sampling analog signals. I have also seen people working with kilo-hertz level signals and trying to visualize the signal in this way. The reason for getting a noisy signal instead of a sine wave because of delay due to the serial printing. This phenomenon is known as aliasing. The figure below is an example of aliasing. A solid high-frequency signal is my main signal to sample. Due to Serial printing, the sampling rate is low. As a result, I am getting the sample like the dotted signal.
<img src="/assets/images/Pasted-image-20220807084424.png" alt="Arduino Sampling and Aliasing" />
Consider the baud rate of serial communication is 9600 bits per second. If you want to send a single byte like character ‘X’ to the PC, it takes around 1ms for a 9600 baud rat. Here are 8 data bits, 1 start bit, and 1 stop bit. So comprises 10 bits including overhead for sending each byte of data. Therefore, 10 bits take around 1ms. That’s why it is not a good idea to print analog values just after sampling.</p>
<p>The same thing happens for people working with Line following robots or working with a robotic project for the first time. After reading the analog signal, they print a lot of serial logs into the terminal and expect everything will work fine. So it is very important to remember how to use serial printing in time-critical code.</p>
<h2 id="how-to-avoid-anti-aliasing-in-arduino">How to avoid anti-aliasing in Arduino</h2>
<p>One of the easiest tricks, I applied here, was to use a buffer for reading the samples and then process the signal from the buffer. So the steps are as follows.</p>
<ol>
<li>A buffer to hold all of your analog values. Such an array of 100 value int.</li>
<li>Read the analog value in a for loop and fill up the whole buffer of 100 integers.</li>
<li>Then create another for loop for printing out all of your data from the buffer</li>
</ol>
<p>In this way, you can sample signals at a higher speed in the range of 8KHz which is the sampling frequency of Arduino Uno. Here is the example code that I explained so far. I</p>
<div class="language-c++ highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">//Take a buffer so that you can store your sample in the buffer</span>
<span class="kt">int</span> <span class="n">analogBuffer</span><span class="p">[</span><span class="mi">500</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">setup</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">begin</span><span class="p">(</span><span class="mi">9600</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">loop</span><span class="p">()</span>
<span class="p">{</span>
<span class="c1">//First save the sample in a buffer using loop.</span>
<span class="c1">// Do not do other task during sampling</span>
<span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o"><</span><span class="mi">500</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">analogBuffer</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">analogRead</span><span class="p">(</span><span class="n">A0</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">//After taking sample do whatever you want to do with the sample</span>
<span class="c1">//Print or postprocess anything</span>
<span class="k">for</span><span class="p">(</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span> <span class="p">;</span> <span class="n">i</span><span class="o"><</span><span class="mi">500</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Serial</span><span class="p">.</span><span class="n">println</span><span class="p">(</span><span class="n">analogBuffer</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="c1">// int sensorValue = analogRead(A0);</span>
<span class="c1">// Serial.println(sensorValue);</span>
<span class="p">}</span>
</code></pre></div></div>
<p>I have also made a video on the topic on my YouTube channel. You find the video in the link <a href="https://youtu.be/lRmQTYLyB6E">here</a>.I hope the blog will help.
Happy coding!!</p>
<hr />
<p>Shuvangkar Das, Potsdam, New York</p>Shuvangkar Dasshuvangkarcdas@gmail.comIt was 2013. I was doing my undergraduate at the Bangladesh University of Engineering and Technology(BUET). I had a power system course along with a lab course in my second year. I had to develop a hardware project on a power factor improvement plant as the requirement of the lab course. I was very excited about the project as it was my first hardware project as in undergraduate. The very next day I bought a bunch of components for the project. Potential transformer(PT), Current Transformer(PT), ATmega microcontroller, and many discrete components. I eagerly started experimenting with the sensors. As I had the experience of working with microcontrollers beforehand, I started everything smoothly.