22 June 2020
How to read a CSV file in R | Lecture 4
Arrays and Matrices in R | Lecture 3
![]() |
| Array in R |
How to Use R as a Calculator | Lecture 2
Basics of R | Lecture 1
- Its based on object oriented design
- R Commands can be included or embedded with other software or applications or programming languages namely C++. Java and other commercial tools.
- It supports multiple Operating systems like Windows, Linux, Mac OS, etc.
- Good community to help
- Works in a interactive way
- Plotting and graphs are easy to plot using the libraries.
- New libraries can be easily generated.
- Its completely modular and object oriented.
18 June 2020
Printing Linux Environment using C Program
Linux provides each running program with an environment. The environment is a collection of variable/value pairs. Both environment variable names and their values are character strings. By convention, environment variable names are spelled in all capital letters. You’re probably familiar with several common environment variables already.
For instance:
USER contains your username.
HOME contains the path to your home directory.
PATH contains a colon-separated list of directories through which Linux searches for commands you invoke.
DISPLAY contains the name and display number of the X Window server on which windows from graphical X Window programs will appear.
//Printing the Execution Environment
#include <stdio.h>
/* The ENVIRON variable contains the environment. */
extern char** environ;
int main ()
{
char** var;
for (var = environ; *var != NULL; ++var)
printf (“%s\n”, *var);
return 0;
}
Printing the Uptime and Idle Time of processor (Linux)
/proc/uptime file contains only two values in seconds, one is the Uptime of the processor (the time upto which the processor was on) and another is the idle time of all the processors (cores).
So idle is always higher than the uptime in case of multicore processors.
The following C program shows the uptime and idle time in terms of days hours and minutes. This is a very simple program just tells you how to convert a given time in days, hours, minutes and seconds.
using C FILE concept, the /proc/uptime file is been read using the “r” mode and values are fetched and then converted into days, hours and seconds.
1: // printing the uptime and idle time
2: #include <stdio.h>3: /* Summarize a duration of time to standard output. TIME is the
4: amount of time, in seconds, and LABEL is a short descriptive label. */
5: void print_time (char* label, long time)
6: {7: /* Conversion constants. */
8: const long minute = 60;
9: const long hour = minute * 60;
10: const long day = hour * 24;
11: /* Produce output. */
12: printf (“%s: %ld days, %ld:%02ld:%02ld\n”, label, time / day, 13: (time % day) / hour, (time % hour) / minute, time % minute); 14: }15: int main ()
16: { 17: FILE* fp;18: double uptime, idle_time;
19: /* Read the system uptime and accumulated idle time from /proc/uptime. */
20: fp = fopen (“/proc/uptime”, “r”); 21: fscanf (fp, “%lf %lf\n”, &uptime, &idle_time); 22: fclose (fp);23: /* Summarize it. */
24: print_time (“uptime “, (long) uptime);
25: print_time (“idle time”, (long) idle_time);
26: return 0;
27: }Square and Sinusoidal Waveform in 8051 Microcontroller
Square Wave
To create a square wave generation using Delay.
let us say we want to construct a 1khz square waveform
the processor instruction cycle of 8051 is 1.085microseconds
so for 1khz (1milli seconds =1/1khz), is 1ms/1.085microseconds = 921.6 (this value is set to the for loop)
#include <reg51.h>Sine Wave generation
void delay()
{
int i=0;
for(i=0;i<922;i++)
}
void main()
{
P0=0xff;
delay();
P0=0x00;
delay();
}
Since sine wave is plotted in a digital device the number of samples determines the smoothness, hence in this case, more the samples, smoother is the waveform. so a lookup table is been created to get the samples. in the following examples, there are totally 36 samples are taken, starting from 0 degrees to 360 degrees with a step of 10 degrees
| Degrees | A = 5 (1+Sin theta) Where 5 is the full scale voltage | DAC = 25.6 * A |
| 0 | 5 | 128 |
| 30 | 7.5 | 192 |
| 60 | 9.3 | 239 |
| 90 | 10 | 256 |
| etc…like this we need to calculate for 13 samples with a step of 30degree |
// SINE WAVE
#include<reg51.h>
int main()
{
int j;
int c[37]={128,150,172,192,210,226,239,248,254,255,254,248,239,226,210,192,172,150,128,106,84,64,46,30,17,8,2,0,2,8,17,30,46,64,84,106,128};
while(1)
{
for(j=0;j<36;j++)
{
P1=c[j];
}
P1=128;
}}
Triangular Waveform
//Triangular wave
#include<reg51.h>
void main()
{
int j;
while(1)
{
for(j=0;j<256;j++)
{
P0=j;
}
for(j=255;j>0;j=j-2)
{
P0=j;
}
}
}
Saw tooth or Ramp Waveform
// SAWTOOTH WAVE
#include<reg51.h>
void main()
{
int j;
while(1)
{
for(j=0;j<256;j++)
{
P1=j;
}}}
Pulse Width Modulation (PWM) Generation in 8051
#include <reg51.h>
sbit pinpwm = P2^0;
unsigned char PWM = 0;//PWM is the variable to alter the pulse width from 0 to 255
unsigned int temp = 0;
int main(void)
{
P2=0x00;
PWM = 0; //0% duty cycle
//Initialize the timer
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = 0x00;
TL0 = 0x00;
ET0 = 1; //enable timer interrupt
EA = 1; //enable all interrupts
TR0 = 1; // Start Timer 0
PWM = 220; //a duty cycle of 220/256
while(1)
{}
}
// Timer0 ISR
void Timer0_ISR (void) interrupt 1
{
TR0 = 0; // Stop Timer 0
if(pinpwm) // if high
{
pinpwm= 0;
temp = (255-PWM); //this is in decimal
TH0 = 0xFF;
TL0 = 0xFF - temp&0xFF; //to handle in hex
}
else // else if low
{
pinpwm = 1;
temp = PWM;
TH0 = 0xFF;
TL0 = 0xFF - temp&0xFF;
}
TF0 = 0; // Clear the interrupt flag
TR0 = 1; // Start Timer 0
}
Here the PWM Waveform is generated with a duty cycle of 220/256(86%) duty cycle. PWM are advantageous in controlling the power to machines be reducing the supply voltage by altering the pulse width.
Duty Cycle means, the time percentage for which the duty is done. in the image show above, the high waveform for 86% and low waveform (0) for 14%.
Pradeep Kumar TS
Terminal Based Youtube downloader for Linux (youtube-dl)
But there is a tool that is available in the command line (Terminal based) on Linux Operating Systems.
That is youtube-dl, this is a python based code and can be executed in linux OS without any hassles.
youtube-dl in windows or Mac OS can be achieved by installing python interpreter and try it.
for installing in linux, the command is
$prompt] sudo yum install youtube-dl (in redhat or centos or fedora)
$prompt] sudo apt-get install youtube-dl (ubuntu or linux mint)
See the image for downloading in Fedora 20
![]() |
| Youtube-dl in Fedora 20 |
In ubuntu, you can update the sudo package before installing the youtube-dl.
sudo apt-get update
To download videos
$prompt] youtube-dl http://www.youtube.com/watch?v=D980jXvyKUY
the above command will download the video in the best possible format. See the image below.
The video downloaded is of the format webm (Its a Web Movie format from Google for optimized view in web browsers)
![]() |
| Youtube-dl |
$prompt] youtube-dl -F http://www.youtube.com/watch?v=D980jXvyKUY
[youtube] Setting language
[youtube] D980jXvyKUY: Downloading webpage
[youtube] D980jXvyKUY: Downloading video info webpage
[youtube] D980jXvyKUY: Extracting video information
[info] Available formats for D980jXvyKUY:
format code extension resolution note
139 m4a audio only DASH audio , audio@ 48k (worst)
140 m4a audio only DASH audio , audio@128k
160 mp4 192p DASH video
133 mp4 240p DASH video
17 3gp 176x144
36 3gp 320x240
5 flv 400x240
18 mp4 640x360
43 webm 640x360 (best)
The above is output and to download the corresponding video format, then here is the command
$prompt] youtube-dl -f 18 http://www.youtube.com/watch?v=D980jXvyKUY
The above command will download the file in the mp4 format as specified in the option obtained in the previous command.
if you need any help on the commands, you can use the following command
$prompt] youtube-dl --help
Often, youtube-dl is updated, it can be easily updated as given below,
$prompt] sudo youtube-dl -U
Also now youtube-dl supports various other video streaming sites also, to name a few, vimeo.com, dailymotion.com, etc.
If you are behind the proxy, type the command in the terminal
export http_proxy=172.16.1.1:8080/
or copy the above line in /etc/profile.d/proxy.sh (this will be set for all the users of the computer, also need root password)
Download and Enjoy!!!
Pradeep Kumar TS
nohup command in Linux/Unix
Often you come across a situation where you try to open a machine remotely using ssh and try to start a server or run a command indefinitely. But once you close the ssh session, your session also terminates and the background process also terminates. So here is a solution.
To open ssh remotely,
prompt $] ssh username@machinename
Ex: ssh root@172.16.1.1
Ex: ssh root@example.com
prompt $] ssh -X username @machinename
Ex. ssh -X root@172.16.1.1
(this -X indicates the remote session can be opened in X window (GUI) mode)
Assume we need to start a httpd server in the remote machine.
we can issue the command like this
usage:
prompt$] nohup command
if any error or log information may be stored in the nohup.out file. if you want to redirect to a file use the redirected symbol (1> indicates standard output and 2> indicates standard Error). Specify the filenames for the output. Here is the typical nohup command to start the httpd server.
prompt $] nohup /etc/init.d/httpd start 1> file.out 2> file.err &
nohup is the command simply tells "no hangup". This will send the output to non-tty.
The above command will start the httpd server and any error or output will be written on to the files file.err and file.out respectively (The & indicates the background process that closes the current terminal and prompts for further inputs).
![]() |
| nohup in Linux |
This command I learnt when i try to deploy Sage math libraries in a IBM Blade Server. We were really struggling to run the notebook in sagemath library. But finally accomplished using the nohup command.
The alternative to nohup is crontab or cronjob can be used.
Pradeep Kumar TS
How to display the Product name and System Vendor name in Linux
Product Name
- System Vendor Name
![]() |
| Printing the System Vendor and Product Name |
Pradeep Kumar TS
time command in Linux
The time command usage is as follows
prompt $] time <commandname>
Example
prompt $] time ls
The output will be
real 0m0.002s
user 0m0.004s
sys 0m0.000s
Desktop Documents Downloads examples.desktop Music Pictures Public Templates Videos
Command being timed: "ls"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 400%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3600
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 286
Voluntary context switches: 1
Involuntary context switches: 0
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
How to open Ports in CentOS using i-tables
This post tells you about the usage of CentOS when web servers are installed and accessed from remote machines.
CentOS is a Server based OS and most of the ports are closed by default and you need to open it for access from outside (remote).
For ex. if wordpress is installed in CentOS with a hostname http://127.0.0.1/wordpress which is very well accessed within the server. When the same is tried from outside like (http://192.168.54.3/wordpress), then it will not get accessed.
The problem is the closure of ports in CentOS. So you need to open it and save it to iptables, here are the commands that will help you to do that.
![]() |
| CentOS |
$prompt] ifconfig (find out which interface uses the assigned ip, eth1, eth0, etc)
$prompt] iptables --line -vnL
(See which line the input has to be accepted and in my case it is 6) and give the following command
$prompt] iptables -I INPUT 6 -i eth1 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
$prompt] service iptables save (Save and restart the IP Tables)
$prompt] service iptables restart
Change InnoDB file format to Barracuda
so it will be advised to change the file format to Barracuda. There are various options to do that. Here is a small workaround to change it to barracuda.
Open Mysql from the command prompt and execute the commands one by one
$] mysql -u root -p
The username is root here
It will ask for the password: (Input the password here).
mysql> select version();
mysql> show variables like "%innodb_file%";
The output will be like this
+--------------------------+----------+
| Variable_name | Value |
+--------------------------+----------+
| innodb_file_format | Antelope |
| innodb_file_format_check | ON |
| innodb_file_format_max | Antelope |
| innodb_file_per_table | ON |
+--------------------------+----------+
4 rows in set (0.00 sec)
mysql> SET GLOBAL innodb_file_format = barracuda;
mysql> show variables like "%innodb_file%";
+--------------------------+-----------+
| Variable_name | Value |
+--------------------------+-----------+
| innodb_file_format | Barracuda |
| innodb_file_format_check | ON |
| innodb_file_format_max | Antelope |
| innodb_file_per_table | ON |
+--------------------------+-----------+
4 rows in set (0.00 sec)
![]() |
| Barracuda |
How to access ext2, ext3 and ext4 filesystems in windows 10
But accessing Linux EXT2, EXT3 and EXT4 files within Windows can be done only through an external software.
EXt2FSD is a software that does this job. you can download the software from this link
Once installed, its as easy as possible to “assign a drive letter ” to the partition. Figure below shows that.
![]() |
| Ext2FSD |
![]() |
| Ext2FSD |
Its just a simple process to access the linux files within windows. This is really helpful for the machines with UEFI partition. When Linux Boot loader is deleted, this will help to retrieve the files.
Any other info, please comment below.
vokoscreen - a screen recorder for Linux
So, there should be some alternatives to control the video, audio, web camera, etc. Two such tools are available.
- Simple Screen Recorder (for installing and configuring in Linux, click here)
- vokoScreen is the other tool that works nicely in Linux
$] sudo add-apt-repository ppa:vokoscreen-dev/vokoscreen-daily
$] sudo apt-get update
$] sudo apt-get install vokoscreen
But in the latest version of Ubuntu (16.04), it can given directly as
$] sudo apt install vokoscreen
Once installed, its very easy to use as shown in the following figures
![]() |
| vokoscreen Video configuration |
![]() |
| Vokoscreen Audio Control |
![]() |
| vokoscreen webcamera control |
![]() |
| vokoscreen |
09 June 2020
Installation of NS2 (ns-2.35) in Ubuntu 20.04
About Me
Featured Post
5G Network Simulation in NS3 using mmWave | NS3 Tutorial 2024
5G Network Simulation in NS3 Using mmWave This post shows the installation of ns3mmwave in Ubuntu 24.04 and simulates 5G networks in ns3. In...
Contact form
Total Pageviews
Search This Blog
Categories
- 5G
- 8051
- ADA
- Analytics
- Android
- Animator
- AODV
- Apache
- ARM
- AWK
- C
- C++
- CentOS
- Cloud
- CMS
- Computer Networks
- Contiki
- CPS. Cyber Physical Systems
- CSMA
- Data Structures
- Deep Learning
- Digital Electronics
- elearning
- Electrical Engineering
- Embedded Systems
- EmbeddedSystems
- Energy
- Errors
- Fedora
- Flow Monitor
- gnuplot
- HowTos
- Installation
- Internet of Things
- IOT
- IoT Tutorials
- Javascript
- Kali Linux
- Linux
- Linux Commands
- Linux Kernel Programming
- Linux Mint
- Mac OS
- MANETs
- Moodle
- MySQL
- NetAnim
- Network Analyser
- Network Analysis
- Network Simulation
- Network Simulator 2
- Network Simulator 3
- Node JS
- ns-3 Tutorial
- ns-3.44
- NS2
- NS2 Errors
- NS2 Lecture Series
- NS2 Tutorial
- NS3
- nsnamcom
- Omnet
- Omnet++
- Open Source
- Optical Networks
- Perl
- PHP
- Point to Point
- Presentation
- Protocol
- Python
- PyTorch
- R
- RealTimeSystems
- Research
- Research Tools
- Robotics
- ROS
- routing
- RTOS
- SDN
- Sensor Networks
- Shell
- Software Engineering
- Special
- Stone Letters
- TCL
- Testing
- Tracegraph
- Ubuntu
- VANET
- VHDL
- Videos
- Visualizer
- Windows 10
- Windows 11
- Windows 7
- Windows 8
- Windows7
- Wired network
- wireless
- Wireshark
- wordpress
- xgraph
- Youtube
Pages
Pages
Pages - Menu
Most Popular
-
How to create a new agent in NS2. You can use any version of the Simulator. The following codes will make you to understand the writing of a...
-
This post will help you in installing Network Simulator 2 version NS2.35 in Ubuntu 11.10 Instructions Install Ubuntu Download NS-2.35 (...
-
Aim: To design and simulate a DNS query-response mechanism over UDP sockets using NS3. The client sends QUERY:<domain> packets to a ...
Popular Posts
-
How to create a new agent in NS2. You can use any version of the Simulator. The following codes will make you to understand the writing of a...
-
This post will help you in installing Network Simulator 2 version NS2.35 in Ubuntu 11.10 Instructions Install Ubuntu Download NS-2.35 (...
-
Aim: To design and simulate a DNS query-response mechanism over UDP sockets using NS3. The client sends QUERY:<domain> packets to a ...















.png)








