Wednesday, April 3, 2013

Moving Average Filter using MATLAB


%moving average filter
clear all;
close all;
clc;
fs=500000;
fm=10000;
t=1:200;
x=5*cos(2*pi*(fm/fs)*t);
z=awgn(x,5);
% adding White Gaussian noise to the input with S/N=5
plot(x,'g','linewidth',1.5);
hold on;
plot(z);
hold on;
for i=1:194;
y(i)=(z(i)+z(i+1)+z(i+2)+z(i+3)+z(i+4)+z(i+6))/6;
end
plot(y,'r','linewidth',1.5);
legend('Actual','Noisy','Filtered');
title('moving Average Filter','fontsize',12);
xlabel('---> time in 2us');
ylabel('---> volts'); 


OUTPUT:                                                                                            A Book to learn MATLAB

Frequency Modulation using MATLAB


%Frequency modulation
%fm=100;Am=5;
%fc=3000; Ac=5;

clear all;
close all;
clc;
fm=input('enter msg signal frequency fm=');
Am=input('enter msg signal amplitude Am=');
fc=input('enter carrier signal frequency fc=');
Ac=input('enter carrier signal amplitude Ac=');
fs=100000;
t=0:1/fs:0.05;
m=Am*cos(2*pi*fm*t);
c=Ac*cos(2*pi*fc*t);
subplot(311);
plot(m);
title('input msg signal','fontsize',14);
xlabel('--->time in 10us','fontsize',11);
ylabel('--->Amplitude in Volts','fontsize',11);
subplot(312);
plot(c,'r');
title('input carrier signal','fontsize',14);
xlabel('--->time in 10us','fontsize',11);
ylabel('--->Amplitude in Volts','fontsize',11);
B=(500*Am)/fm; % kf=500 < fc
s=Ac*cos(2*pi*fc*t + (B*sin(2*pi*fm*t)));
subplot(313);
plot(s);

title('output FM signal','fontsize',14);
xlabel('--->time in 10us','fontsize',11);
ylabel('--->Amplitude in Volts','fontsize',11);


OUTPUT: 

Amplitude Modulation using MATLAB



%Analog modulation
%fm=100;Am=5;
%fc=1000;Ac=5;
clear all;
close all;
clc;
fm=input('enter msg signal frequency fm=');
Am=input('enter msg signal amplitude Am=');
fc=input('enter carrier signal frequency fc=');
Ac=input('enter carrier signal amplitude Ac=');
fs=100000;
t=0:1/fs:0.1;
m=Am*cos(2*pi*fm*t);
c=Ac*cos(2*pi*fc*t);
subplot(311);
plot(m);
title('input msg signal','fontsize',14);
xlabel('--->time in 10us','fontsize',11);
ylabel('--->Amplitude in Volts','fontsize',11);
subplot(312);
plot(c,'r');
title('input carrier signal','fontsize',14);
xlabel('--->time in 10us','fontsize',11);
ylabel('--->Amplitude in Volts','fontsize',11);
u=Am*0.1;
y=Ac*cos(2*pi*fc*t) + ((u*Ac)/2)*((cos(2*pi*(fc+fm)*t)) + (cos(2*pi*(fc-fm)*t)));
subplot(313);
plot(y);
title('Output AM signal','fontsize',14);
xlabel('--->time in 10us','fontsize',11);
ylabel('--->Amplitude in Volts','fontsize',11);


OUTPUT:

Sine Wave to Square Wave conversion using MATLAB


%60Hz sine wave to 20Hz square wave conversion
clear all;
close all;
clc;
fm=input('enter msg frequency fm=');
fr=input('enter mult frequency fr=');
fs=2000;
t=0:1/fs:0.2;
x=5*sin(2*pi*fm*t);
f=(fm-fr);
y=5*sin(2*pi*t*f);
for i=1:401
if(y(i)>=0)
    s(i)=+5
else
    s(i)=-5
end
end

subplot(311);
plot(x,'-','linewidth',1);

title('60Hz sine wave','fontsize',12);
xlabel('--->time in 0.5ms');
ylabel('--->Volts');
subplot(312);
plot(y,'g','linewidth',1.5);

title('20Hz sine wave','fontsize',12);
xlabel('--->time in 0.5ms');
ylabel('--->Volts');
subplot(313);
plot(s,'r','linewidth',1.5);

title('20Hz square wave','fontsize',12);
xlabel('--->time in 0.5ms');
ylabel('--->Volts');




RESULT:

Tuesday, February 12, 2013

2-point Butterfly FFT-DFT implementation using VHDL programming

 Implementing FFT-DFT using VHDL code. It uses many constraint models such as area, power and delay models, and also behavioral and structural model designing. These 2-point Butterfly blocks can be used to design many point FFTs.

click here to view and download 

Friday, December 7, 2012

RF remote controlled home loads.

RF remote controlled home loads
                As  I already mentioned earlier the basic need to build an embedded system is the desired application. First you decide what application you want. I chose my application that is  to build a system that can control the home loads through  remote.  I decided to do that project strongly, and what is next step ?  That Is our required functionality. Here I decided to control four home loads that might be fan, lights, TV, etc., .  
Then draw the basic block diagram of your application

I built my block diagram as I required.  Go through the required components, I chose                              

Transmitter Part:-
Ø  Since I am using wireless communication I required one receiver transmitter pair.

     Here am using RF Txr &Rxr pair which will be operated in 433MHz frequency band. These pair can operate in limited area  up to 80mtrs. Instead we can use IR transmission also but it can operate in line –of-sight conditions.
Ø  To operate the four loads I can choose 4-push buttons at the transmitter side. Since wireless communication is a serial communication we can’t transmit parallel data. So we require a Encoder which can convert parallel data to serial data. Here I chose HT12E encoder. With this I completed the basic requirements to build transmitter part. The total circuit will
      be shown later.
Receiver Part:-
Ø  Encoded data will be received through the RF receiver.  It has
    to convert from serial data to parallel data, for that  we need to
    use the compatible Decoder. I chose HT12D  decoder.
Ø  To control the actions we need one controller. I am choosing AT89C51 controller because am good at this.
Ø  Since we are controlling AC loads we need Relay circuits(SPDT single pole double threw 12-v)
Designing:-
Transmitter:-
HT12E is 18-pin dip it has 8-Address pins and 4 Data pins.


Pins 1-8 are address pins here we don’t need. 14-pin is floating pin. Pins 10-13 are data pins D8 to D11 respectively. 15 and 16 pins are oscillator pins.17th pin is Data out. S1-S4 are push buttons.
Receiver:-
          Receiver data flow:-
                       RF receiver à Decoder à microcontroller à relays à loads
Ø  The RF receiver part connection is same just like transmitter part. The parallel is fed to AT89C51 microcontroller. The resulted outputs are  fed to relays through transistors.





MicroController:-
 It is a 8-bit and 40-pin DIP micro controller developed by Atmel corporation. It has 4 ports
PORT-0: multiplexed  Address and Data lines floating pins
PORT-1: I/O port floating pins
PORT-2: higher order Address pins floating pins
PORT-3: I/O pins and have a special function to each pin
11.0592MHz crystal provides the Clock frequency to the Micro controller.
Relay:-
 1N4148 diode protects the transistor and relay from the damage and back emf.
FLOW CHART:-
        Flow chart will illustrates the total control functionality of the circuit






Initially all the inputs are assigned to ‘1’ and all the loads are assigned to ‘0’.      
  When switch1 is pressed at the Txr it generate 1110 data. This data is compared in the micro-controller. If it matches then load1 preformed XOR operation  with ‘1’. If initial value is ‘0’
 
                                   0 xor 1=1;                                                                                                                                                                                                                                                        When second time pressed the same switch-1 then (already load-1=’1’)
                                               1 xor 1=0;
 The same operation is performed to switches-1,-2 and -3.

Source Code:-

#include<reg51.h>
sfr rfr=0x90;
sbit load1=P3^0;
sbit load2=P3^1;
sbit load3=P3^2;
sbit load4=P3^3;
unsigned int i;
void main()
{
rfr=0x0F;  // initialising as input port
load1=0;   // output pin
load2=0; // output pin
load3=0; // output pin
load4=0;  // output pin
while(1)  // super loop
{
if(rfr==0x0E // checks if switch-1 is pressed or not
{
  load1^='1';   //xor operation
for(i=0;i<50;i++);
}
else if(rfr==0x0D)  // checks if switch-2 is pressed or not
{
load2^='1';    //xor operation
for(i=0;i<50;i++);
}
else if(rfr==0x0B)   // checks if switch-3 is pressed or not
{
load3^='1'; //xor operation
for(i=0;i<50;i++);
}
else if(rfr==0x07)   // checks if switch-4 is pressed or not
{
load4^='1';  //xor operation
for(i=0;i<50;i++);
}

}
}









Propeller project.
#include<reg51.h>
  sfr leds=0xB0;
  unsigned int i;
  void main()
  {
   leds=0x00;
   while(1)
   {
    leds=0xFE;
leds=0x14;
leds=0x12;
leds=0x12;
leds=0x14;
leds=0xF8;
for(i=0;i<10;i++);
leds=0xFE;
leds=0x04;
leds=0x04;
leds=0x08;
leds=0x10;
leds=0x20;
leds=0xFE;
for(i=0;i<10;i++)
leds=0xFE;
leds=0x14;
leds=0x12;
leds=0x12;
leds=0x14;
leds=0xF8;
for(i=0;i<10;i++);
leds=0xFE;
leds=0x04;
leds=0x04;
leds=0x08;
leds=0x10;
leds=0x20;
leds=0xFE;
for(i=0;i<10;i++)
    leds=0xFE;
leds=0x82;
leds=0x44;
leds=0x38;
  }
}

Friday, November 9, 2012


One has to do these programs to use the specific controller in the real world applications

Friday, August 17, 2012

simple Secure data transmission using AT89C51


//--- data encryption and decryption---//
//--- same program for receiver and transmitter
#include<reg51.h>
sfr in=0x80;
sfr out=0x90;
void delay(void);
void main()
{
  in=0xFF;
  out=0x00;
  while(1)
  {
   unsigned int i,p1,seq,p2;
   p1=in;
   seq=~p1;
   p2=seq^0x55;
   out=p2;
   for(i=0;i<10;i++)
   {
   delay();
   }
   }
}
 void delay(void)
 {

  TMOD=0x10;
  TL1=0xFD;
  TH1=0x4B;
  TR1=1;
  while(TF1==0);
  TF1=0;
  }

Friday, July 20, 2012

PART-1:- Basic embedded system designing 
   In a simple manner  embedded system is a system that can control some specific devices automatically or manually.To design an embedded system we need to follow these steps

1).  For any embedded system design the first requirement is the application, which we want to design
in practical.

2). Select the input and output devices which you want to interface (like input devices are sensors, switches etc., and output devices are motors, lcd display etc.,).

3).The input and output devices must be selected as per our requirements only.

4). Take out your required functioning and draw the simple block diagram of the system.

5). Draw the flow chart

6). Select the I/O devices and controller for your system.

7). write the functioning code in Embedded-C or in any language.. and check the functionality in KEIL simulation software.

8). Design your own circuit now. There are some important things while designing the circuit.
     i). Study the datasheets of the selected devices and find the operating voltage and current levels.
     ii). find if there is any requirement of oscillatory circuit.
     iii). choose the predefined parameters for the device for the  basic functionality. These predefined
          parameters are available in datasheets.
    iv). solder the main blocks first and do not insert any IC's into the baser until you check the voltage and
        currents in the baser.
    v). if every thing is properly soldered then insert IC's and then dump the program into the controller.
     vi). now check the functionality of the circuit.
        These steps will be explained with example in the PART-2...

Thursday, July 5, 2012



source code:-


//----- reading the char or no from the keyboard----//
#include<reg51.h>
sfr ROW=0x80; //assigning PORT-0 to read rows
sfr COL=0xA0; //assigning PORT-2 to read colomns
sfr ldata=0x90; //assigning PORT-1 for LCD data
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
sbit busy=P2^7;
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdready(void);
void msdelay(unsigned int itime);
void lcddisplay(unsigned char ch);
  void clear(void);

void main()
{
unsigned char dat[4][4]={'7','8','9','%', // assigning key matrix
                          '4','5','6','*',
  '1','2','3','-',
  'C','0','=','+'};
 unsigned char colloc,rowloc;
 COL=0xFF;
 ROW=0x00;
 rs=0;
 rw=0;
 en=0;
 busy=0;
 /* setting LCD screen*/
 ldata=0x00;
 lcdcmd(0x38);
 lcdcmd(0x0E);
 lcdcmd(0x01);
 lcdcmd(0x06);
 lcdcmd(0x80);
 while(1)
 {
/* reading character from keyboard */
   do
   {
    ROW=0x00;
    colloc=COL;
colloc&=0x0F;
}while(colloc!=0x0F);
do
{
do
{
 msdelay(25);
 colloc=COL;
 colloc&=0x0F;
 }while(colloc==0x0F);
 msdelay(25);
 colloc=COL;
 colloc&=0x0F;
 }while(colloc==0x0F);
    while(1)
{
ROW=0xFE;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
 rowloc=0;
 break;
 }
 ROW=0xFD;
 colloc=COL;
 colloc&=0x0F;
  if(colloc!=0x0F)
  {
   rowloc=1;
break;
}
 ROW=0xFB;
 colloc=COL;
 colloc&=0x0F;
  if(colloc!=0x0F)
  {
   rowloc=2;
break;
}
 ROW=0xF7;
 colloc=COL;
 colloc&=0x0F;
if(colloc!=0x0F)
 {
     rowloc=3;
     break;
   }
  }
   if(colloc==0x0E)
   lcddisplay(dat[rowloc][0]);
   else if(colloc==0x0D)
   lcddisplay(dat[rowloc][1]);
   else if(colloc==0x0B)
   lcddisplay(dat[rowloc][2]);
   else
    lcddisplay(dat[rowloc][3]);
}
  }
  /*displaying char on LCD screen*/
void lcddisplay(unsigned char x)
{
 if(x=='C')
  {
   clear();
    }

 else
 lcddata(x);
   }
 /* sending commands to  LCD display to act in command mode */
void lcdcmd(unsigned char value)
{
 lcdready();
 ldata=value;
 rs=0;
 rw=0;
 en=1;
 msdelay(1);
 en=0;
 }
 /* sending commnad to LCD to display characters*/
void lcddata(unsigned char value)
{
 lcdready();
 ldata=value;
 rs=1;
 rw=0;
 en=1;
 msdelay(20);
 en=0;
 }
 /* checking LCD buffer for free */
void lcdready(void)
{
 busy=1;
 rs=0;
 rw=1;
 if(busy==1)
  {
   en=0;
   msdelay(20);
   en=1;
   }
}
/* generating delay*/
void msdelay(unsigned int value)
{
 unsigned int i,j;
 for(i=0;i<value;i++)
 for(j=0;j<100;j++);
 }
 void clear(void)
 {
  lcdcmd(0x01);
  }






                 This circuit can serve the pumping motor for 5-6sec when the push button was closed. This is a good thing of this circuit. so we can use it for decoration purposes. I made it for pouring milk and water on lord ganapathi head when somebody placed 5Rs/- coin in a money box.

 Working:- It is a Monotable Multivibrator circuit. The components R3 and C3 provides the Triggering to the IC555 timer. The push button is located at the coin entry level. so when somebody placed a coin the coin box it touches the push button. so that it can activate the triggering circuit. C3 and R3 provides the output pulse duration.