Tuesday, April 24, 2018

Trinity of Web: HTML + CSS + JavaScript



At the heart of modern web applications there lays 3 main components which helps/guides users to do shopping on Amazon web site, purchase air tickets from Delta Airlines, connect friends worldwide through Facebook, transfer money from your account to a friend via Bank of America and many other services to better/improve the standard of living of humans.
Let’s briefly go through each component, understand what it means and what it does:

HTML

Hyper Text Markup Language, here markup means marking a word bold or italic or underline or make paragraph by markups like
, PS, HTML is the product of printing technology. So that’s where the word markup came from. In general HTML helps to structures the data or holder of the data.  So if user wants to see their data structured then they should format their data according to html tags/elements.

CSS

Cascading Style Sheets, it’s the styling language used to do designing/presentation/formatting of structured data aka HTML tags/elements. In simple words, via CSS we can say what is the color of font/ size, how and where to position the images, what type of fonts, size of the grid/table etc. User must follow the rules of CSS styling language.

JavaScript

Plays behavioral role or it interacts with the user, for ex: Alerting users through message boxes, or when user clicks on submit button, JavaScript validates user has entered all the required/mandatory field before submitting data to sever, etc. Through JS user can request data from server for ex: their checking account balances or transaction data.

Each of the above components are worth of a book or more. But in general it is simple, Structure + Present + Behavior combined all these three makes the web working and helps human to improve their standard of living or simplify.

A very simple/real working example of all of the above components is as follows:
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Simple web app</title>
    <style>
        button
        {
            color: white;
            background-color: lightblue;             
        }

    </style>
    <script type="text/javascript">

        function Hello() {
            alert("Thanks for clicking me!");
        }

    </script>
</head>

<body>
    <div>
        <button onclick="Hello();">Please Click On Me!</button>
    </div>
</body>
</html>

You can copy and paste it on a notepad/textpad and open it from a browser, then you should see a screen like below (I opened it through Google chrome)


Wednesday, January 31, 2018

What is PLC, DCS, SCADA, IoT?

What is Programmable logic controller?

PLC’s are everywhere, inside your washing machine, elevators, car manufacturing, making your favorite iPhone or Samsung galaxy phones, bundling toilet papers, etc. Simply PLC means automation of a process.

“A programmable logic controller (PLC), or programmable controller is an industrial digital computer which has been ruggedized and adapted for the control of manufacturing processes” – Wiki

PLC is basically “a digital computer” used for Industrial automation of electromechanical processes. So Unlike Personal computer, they are ruggedized and have electrical noise immunity, vibration and impact resistance, varied temperature ranges, etc.

Programmable: We can write a custom program, to interpret inputs (motor switched on) and how to output (to start motor). Later, we can change, and update or replace a program according to our future requirement so it’s called programmable.

Logic: If two conditions are met or A and B conditions are true do something. For ex: If 60 seconds over and no object in front of the gate, closed the gate. At the heart of microprocessor there are billions of transistors which is nothing but switches, opens or close the circuits based on logics or gates.

Controller: at the heart of PLC resides a Microcontroller, it is very much like a microprocessor, except that it has been designed specifically for use in embedded systems. Microcontrollers typically include a CPU, memory (a small amount of RAM, ROM, or both), and other peripherals in the same integrated circuit. If you purchase all of these items on a single chip, it is possible to reduce the cost of an embedded system substantially.

In laymen words, PLC is an electronic device, electronic means technique to control flow of electrons via semi-conductors like transistors. Transistors is like switches, which allow electrons to flow or stop. Once we have the power to control the flow of electrons, we can use that for logic purpose or decision making, that’s all.

History:
General motors issued a RFP to replace hard wired Relay based machine control systems (before the dawn of transistors, relay system was used to automate the process). Bedford associates, created the first PLC by implementing GM’s specification.

PLC System:







How to automate an Industry:

To automate an Industry, you requires minimu two things:

a) Process or Business domain knowledge: here Process means, what are the activities occurs inside an automobile industry to produce a car. For ex: building frames, painting of the car, assembling engine parts, fixing tires etc. entire these steps or full life cycle of a car production are called as Processes or Business Domain of an Industry.
A good understanding of processes helps to understand the areas to automate or improve automation of production.
   
b) PLC (microcontroller):

Programming languages of PLC:

Ladder Diagram (is used for relay diagrams, so its easy for engineers to upgrade from relay to PLC)
Functional Block Diagram
Structured Text
Sequential Function Chart (SFC)

User IDE to write program, Ex: CODESYS. Usually PLC manufactures will provide IDE's

Steps to Setup and Deploy a PLC:

Understand the Process of an Industry
          Write custom program according to automate the process
Upload custom program into PLC

Different Process/Industrial Control Systems:

PLC:
PLCs are more suitable for local area control (plants, assembly plants, production lines, etc.)
PLC is for small industries, where discrete (means, we know how many phones we are going to manufacture in a day) input and output.

DCS (distributed control system):
DCS tends to be used on large continuous process plants where high reliability and security is important, and the control room is not geographically remote. DCS is for large, spread out industry like oil and refineries, mining. Unlike PLC DCS is analog/continuous input and output.
DCS uses RTU, it is based on microprocessor, because it support wireless, wider geographical telemetry, etc.

SCADA (Supervisory control and data acquisition)/HMI: This system is similar to DCS. is a control system architecture that uses computers, networked data communications and graphical user interfaces for high-level process supervisory management, but uses other peripheral devices such as programmable logic controllers and discrete PID controllers to interface to the process plant or machinery.” wiki

IoT: is modern or next generation SCADA. Recently Industrial giants started to think to exploit the potential of IoT. Its gamer changer, where imagination is the limit how much you can automate, user can control plants, etc.  Unlike SCADA we don't need a dedicated engineer in front of graphical control system and monitor the plant or machines. Field engineer, supervisor/manager or even a company CEO can access and control the plant from his mobile phone. That’s the power of the IoT
IoT provides TLS (transport layer security) inherited technology, which was missing in SCADA.


PS: PLC, DCS, SCADA, IoT, each worth couple of books materials or more. Here I am trying to briefly describe what is PLC and other systems.

One important mention here is unlike typical software industries, inside Industrial software go through lot of processes, more testing, each version will take years to release because they deal with life and death, environment and other issues.

Thursday, December 14, 2017

Hello world in Microsoft Quantum Computing #qsharp #quantum

This week Microsoft Quantum Computing research team released their first quantum development kit (free preview release).

Steps to play around Quantum!

a) You need Windows 64 bit
b) Visual Studio
c) Download quantum development kit, and install it (download link at the end)
d) Download the quantum library's & samples from git hub(download link at the end)
e) Compile and run any one of the samples.

I have compiled and ran the TeleportationSample project:



Link to github MS quantum libs and code: https://github.com/Microsoft/Quantum.git


Tuesday, November 28, 2017

Fundamentals of Wireless Communication 5G

 

What is wireless communication?

Data or information transferred from point A to B without any wire or dedicated cables is called wireless communication.

Mother Nature is doing wireless communication for millions of years*.  Let me give few real examples of how nature does wireless communication:
   a)   When you make an eye contact with other person, the light bouncing off from your body will enter into other person’s eyes, then inside their eyes millions of light sensitive rods and cones or photoreceptor neuron receives and transfers it to brain, where your actual picture is drawn.
   
   b)   When you are talking to other person, vocal cord\folds in your body, generates pressure in the air, that converted into sound waves and enters into the ears, then ear drum vibrates and converts into electrical signal then passed it to brain and different part of brain processes it.

In both the scenario, main point is humans are doing wireless communication unconsciously.

If you are one of the smart people, you might have asked this question, ‘how come I can hear and understand multiple sounds at a time, like car honking, hearing voices people passing by, etc. at the same time’ trick is all these sounds have different hertz or frequency of sound waves. So ear drum vibrates differently for different sounds waves’ frequency.

That’s it, wireless communication in simple sentences:

A gentleman says hello to a lady, his vocal cord generates a sound wave and her ear drum receives sound waves and processes it.

A transmitter antenna, encodes information and  generates radio waves by vibrating electrons, then radio waves travels at the speed of light , when it its receiver antenna, information will be decoded”.

Compare above both the sentences lot of similarities, isn’t it?  When you are stuck in traffic jam, you turn on the radio station. It follows same principle transmitter antenna broadcast and a receiver antenna in your car receives and plays it.
The very key point here is at what hertz the radio waves are broad casted. Don’t worry hertz is simple words for a second how many time it rotates or vibrates. Basically sender and receiver should know the language which they are talking about.

Let’s get little bit technical:

Electricity, Automation, Wireless communication … all these things boils down to “Electromagnetic Spectrum” after understanding this spectrum led to revolution in wireless communication.

There are two types of wireless communication, analog and digital. Analog, all nature communication is analog which is continuous in time and value, ex: sun light. Digital is discrete in both time and value.

After the dawn of transistors and integrated circuits, it revolutionized the wireless communication, after this point of time, wireless means mostly digital wireless.

Below flow path explains steps inside modern wireless communication system:
Analog Signal -> ADC -> Signal Processing -> DAC -> Analog Signal

What is this 1G, 2G, 3G, 4G and now 5G?

In simple words, A telecom company called X, which has setup of lot of cell sites or antennas, and users who want to pay for wireless service like talk or text, subscribes to X’s wireless services. With this setup is in place, here is all what that Gs does as follow:
1G (first generation): user can send and receive couple kb bytes – approx.
4G, user can send and receive few Megabytes – approx.
5G, user can send and receive few Giga bytes – approx.

So basically in 1G user can send and receive just text msg’s but in 5G user can send and receive HD videos, high res pics etc.


PS: I am trying to simplify the technology into simple English words and approximating the measurement or units. This is not for any references, just to create the abstraction of complex ideas into simple real life examples and intention is to reach technology to wider audiences.

Monday, November 6, 2017

Basic statistics/probability formulas using c#

Data science / Machine learning is all about statistics/probability, graphs and linear algebra.

Here are few basics stats functions in c# :

static decimal GetMean(decimal[] inputs)

{

    int count = inputs.Length;

    decimal avg = 0;

    for (int n = 0; n < count; n++)

    {

        avg += inputs[n];

    }

    return Math.Round(avg / count, 1);

}


static decimal GetMedian(int[] inputs)

{

    Array.Sort(inputs);

    int count = 0;


    if ((inputs.Length % 2) == 1)

    {

        count = (inputs.Length - 1) / 2;

        return inputs[count];

    }

    else

    {

        count = inputs.Length / 2;

        decimal a = inputs[count - 1];

        decimal b = inputs[count];

        return Math.Round((a + b) / 2, 1);

    }

}

static decimal GetMode(decimal[] inputs)

{

    //you can substitute below C# lambda express to hasttable technique

    return inputs.GroupBy(n => n).

        OrderByDescending(g => g.Count()).

        Select(g => g.Key).FirstOrDefault();

}


static decimal GetWeightedAvg(decimal[] avg, decimal[] weight)

{

    int count = avg.Length;

    decimal w = 0;

    decimal aAndW = 0;


    for (int n = 0; n < count; n++)

    {

      aAndW +=  avg[n] * weight[n];

      w += weight[n];

    }

    return  Math.Round( (aAndW / w), 1); 

}



static  double GetStandardDeviation(int[] inputs)

{
    int count = inputs.Length;
    int avg = 0; int sum = 0;

    for (int n = 0; n < count; n++)

    {

        sum += inputs[n];

    }

    avg = sum / count; //getting avg or mean

    int preSd = 0;

    for (int n = 0; n < count; n++)

    {

        int tmp = Math.Abs( ((inputs[n] - avg) )); //replace abs to sub and sub from higher to lower

        preSd += tmp * tmp ; 

    }

   return Math.Sqrt( preSd / count);


}

Tuesday, October 10, 2017

opencv c++ visual studio 2017 configuration

In this article, download software's, configure visual studio for opencv and build hello world opencv app using c++ in visual studio 2017.

First download required softwares:

a) Download latest from opencv 3.3
b) Install visual studio 2017 with c++ packages

Then, lets setup global environment variables for opencv build:

a) Goto My computer -> Right click -> Properties
b) Click "Advance System Settings" -> click "Environment Variables"
c) Click "New" from System variables grid
d) Enter "Variable name:" = OPENCV_DIR  & "Variable value:" = C:\Program Files\opencv\build\ or opencv build path
e) Select Variable 'Path' from System variables grid
f) Edit append ";%OPENCV_DIR%\x64\vc14\bin" ; is delimiter to earlier paths

Last, we should configure Visual studio 2017 opencv project properties:

a) create a new c++ console project in visual studio 2017
b) click project properties
c) Goto -> Configuration Properties->C/C++->General->Additional Include Directories-> set "C:\Program Files\opencv\build\include"
 d)Goto -> Configuration Properties->Linker->General->Additional Library Directories-> set  "C:\Program Files\opencv\build\x64\vc14\lib"


e)Goto -> Configuration Properties->Linker->Input->Additional Dependencies-> add "opencv_world330.lib" "opencv_world330d.lib"










Woot woot , thats it, you are all set to develop amazing image processing app.

Here is the Test code:

#include "stdafx.h"
#include opencv2/core/core.hpp
#include opencv2/highgui/highgui.hpp
#include iostream

using namespace cv;
using namespace std;

int main()
{
Mat image;
image = imread("c:\\mahesh\\pics 110.jpg", IMREAD_COLOR); // Read the file
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.

waitKey(0); // Wait for a keystroke in the window
    return 0;
}

Monday, August 28, 2017

Digital Image Processing in a minute!

Digital Image Processing

 

What is DIP?

DIP means, processing digital images by means of a digital computer using math’s\signal processing algorithms. Digital image (jpg, png, gif, video’s) is nothing but a two dimensional array of pixels, basically a grid which contains RGB values.  Images can be generated by using Electromagnetic spectrum like visible light, X-rays, Gamma rays and also other waves like Acoustic (ultrasound).

 

Why DIP?

Simple answer, Automation & to Sense the information out of it.
a)   You want to search your baby\most cherished moment photos in the middle of hundreds of photos in your laptop instantly.
b)   FBI wants to track a fugitive criminal, they can scan automatically scan his photo against CCTVs across airport, streets …
c)    If Robots want to help humans in automation, it has learn to recognize humans, objects, animals etc.
d)   If you want to board airplane by just showing your face, no more boarding pass. DIP scans your face, processes and authenticates you.
e)   Instagram, Snapchat all making money because of DIP – filters
f)    Robots, can quickly take the inventory count for you.
The list goes on…

Processes inside DIP:


Inside Image processing series of process goes on, you can transform images from grayscale to color, apply filters, enhance the image color, delete a part of the images etc. They are as follow:
  1. Image Grabbing or acquisition
  2. Image Preprocessing
  3. Image Enhancement
  4. Image Compression
  5. Image Segmentation
  6. Image Representation and feature extraction
  7. Image Recognition and interpretation.

Image Compression, is a technique to compress and decompress the images\videos, may be lossy or lossless.
Image segmentation is the process of subdividing the given image into its constituent parts or objects. Basically identifying the edges in the images.
Image Restoration is a process that attempts to reconstruct or recover an image that has been degraded by using a priori knowledge of the degradation phenomenon.


Conclusion:


Image processing is part of parcel of modern human life. It started slowly with image transfer from London to New York in 1920’s, later with the advancement of computers, field of image processing is growing exponentially.
Image processing can solve lot of problems, improve human living standards, automate routine stuffs, etc.

References:


Digital Image Processing (3rd Edition) by Rafael C. Gonzalez, Richard E. Woods