Wednesday, April 3, 2013

ADC and DAC using MATLAB

         Here we add some Gaussian noise to the input sine wave and then will will convert that to digital signal. This digital signal sampled data will be used in Modelsim. In the modelsim we develop moving average filter using VHDL, this will filters the sampled data and writes into another file. Using the new updated sampled data we will regenerate the Analog signal.
 
                  

%ADC & DAC
clear all;
close all;
clc;
fs=500000;
% taking sampling frequency as 500kHz
fm=10000;
% input signal frequency 10kHz
t=1:200;     % displaying 200 samples
x=5*cos(2*pi*(fm/fs)*t);
%input sinusoidal signal
z=awgn(x,1);
% adding white Gaussian noise to the input signal with S/N=1
h=1:1000;
plot(t,x,'g','LineWidth',2);
% plotting input signal
hold on;
plot(t,z,'r','linewidth',1.5);
% plotting noisy signal
hold on;
stem(t,z);
hold on;     
Vd=-5:0.0390625:5; % step size =0.0390625, when n=8 bits
for i=1:256  
Vdelta(i)=(Vd(i)+Vd(i+1))/2;
% Quantization levels
end

 i=0:255;
binary= dec2bin(i);
% decimal to binary conversion
% Quantization of input signal

for i=1:200
    for j=1:256
        if(z(i)< Vd(1))
            z(i) = Vdelta(1);
        end
        if (z(i) > Vd(257))
            z(i) = Vdelta(256);
        end
        if(z(i) <= Vd(j+1) && z(i) >= Vd(j))
            z(i) = Vdelta(j);
        end
    end
end

% Encoding the Quantized data
for i=1:200
    for j=1:256
        if (z(i)==Vdelta(j))
            B_data(i,1:8) = binary(j,1:8);
        end
    end
end
% representing binary data in decimal
figure
for i=1:200
 B(i)=bin2dec(B_data(i,1:8));    
end


% First solution; writing Encoded data into ADC.txt file. The we will perfom
% Moving average filter operation in VHDL
f = fopen('ADC.txt', 'w');
for n = 1:200
    fprintf(f, '%s\n', B_data(n,1:8));
end
fclose(f);
subplot(221);
plot(x);
title('original sinwave','fontsize',12);
xlabel('--->time in 2us');
ylabel('--->amplitude in volts');
subplot(222);
plot(z);
title('noise signal','fontsize',12);
xlabel('--->time in 2us');
ylabel('--->amplitude in volts');
% After the moving avg filter the filtered data has been written to vhdl_out.txt file
f=fopen('vhdl_out.txt','r');
A = fscanf(f,'%g',[1 inf]);
fclose(f);

subplot(224)
plot(B)
title('signal with white gaussian noise','fontsize',12);
xlabel('--->time in 2us');
ylabel('--->amplitude in decimal');
%Digital to Analog conversion
for i=1:192
    for j=1:256
      if(A(i)== j )
          outpt(i)=Vdelta(j);
      end
    end
end

subplot(223);
plot(outpt);
title('filtered sine wave sinewave output','fontsize',12);
xlabel('--->time in 2us');
ylabel('--->amplitude in decimal');

RESULT: 
Output data files 

ECG Filtering using MATLAB


 GoldStandard.mat
 % fourth order bandpass filter
 % GoldStandard.mat is a preloaded database ECG signal
 % the original signal is first combined with gaussian noise
 % after noise added the signal will pass through 0.03Hz-1.1Hz bandpass
 % filter,is a 4th order filter

 clear all;
 close all;
 load('GoldStandard.mat')
 subplot(211);
 plot(signal);
 sound('GlodStandard.mat');
 title('the original ECG signal');
 necg=awgn(signal,1,'measured');
 b1=[1 0 -1];
 a1=[1 -1.9955735726528454        0.99558400680448189        ];
 bp1=0.049039538429966834       *filter(b1,a1,necg);
 b2=[1 0 -1];
 a2=[1 -1.8603604222618464        0.87003045759154718        ];
 bp2=0.049039538429966834      *filter(b2,a2,bp1);
 subplot(212);
 plot(bp2);
 title('after filter');
 figure
 subplot(211);
 plot(necg);
 title('after noise adding');
 subplot(212);
 plot(bp1);
 title('after 1st section filter');


RESULT:
 


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...