Wednesday, 18 June 2014

code for the generation of signals in matlab

Dear friends generation of signals in matlab is very simple method once you understand the code you can easily plot any kind of signal for your engineering works etc , here is some code and prepare plot signals along with diagram, read it carefully and try to understand each and every point of it,
PLOTTING A CONTINUOUS TIME COMPLEX EXPONENTIAL SIGNAL
 



c=10;
f=5;
ph=pi/2;
T=1/f;
t=0:T/40:10*T; %10 cycles
x=c*cos(2*pi*f*t+ph);
a=input('enter 1,0 or -1;a='); %enter either positive, negative, zero
y=exp(a*t);
z=y.*x;
plot(t,z),
xlabel('t'),
ylabel('z'),
title('PLOTTING A CONTINUOUS TIME COMPLEX EXPONENTIAL SIGNAL'),
grid on



 
   







TASK-3:
TO PLOT A PIECE-WISE SIGNAL





%for first segment
t0=-2:0.01:0;
x0=t0;
%for second segment
t1=0:0.01:3;
x1=4*ones(size(t1));
%for third segment
t2=3:0.01:4;
x2=-3*t2+4;
x=[x0 x1 x2 ];
t=[t0 t1 t2 ];
plot(t,x,'red','linewidth',3);
xlabel('time');
ylabel('x(t)');
title('PLOTTING PIECEWISE CONTINUOUS TIME SIGNAL');
axis([-3 4 -10 5]);
grid on;

 
TASK-4:
TIME TRANSFORMATION OFF A PIECE WISE SIGNAL

%for first segment
t0=-2:0.01:0;
x0=t0;
%for second segment
t1=0:0.01:3;
x1=4*ones(size(t1));
%for third segment
t2=3:0.01:4;
x2=-3*t2+4;
x=[x0 x1 x2 ];
t=[t0 t1 t2 ];
subplot(2,1,1),
plot(t,x,'red','linewidth',5), 
xlabel('time'),
ylabel('x(t)'),
title('TIME TRANSFORMATION OF CT SIGNAL(ORIGINAL SIGNAL)'),
grid on,
axis([-4 8 -10 5]);
%TIME TRANSFORMATION (Shifting, Scaling, Reversal)
t4=-2*t+4;
subplot(2,1,2),
plot(t4,x,'black','linewidth',5),
xlabel('time'),
ylabel('x(t)'),
title('TIME TRANSFORMATION OF CT SIGNAL(TRANSFORMED SIGNAL)'),
grid on,
axis([-4 8 -10 5]);
 

TASK-5:
3D PLOT OF  CONTINUOUS TIME EXPONENTIAL SIGNAL

t=0:0.0001:10;
x=20*exp(i*5*t);
subplot(2,2,1),
plot(t,real(x)),
xlabel('time'),
ylabel('real part'),
title('PLOTTING REAL PART');
subplot(2,2,2),
plot(t,imag(x)),
xlabel('time'),
ylabel('imag part'),
title('PLOTTING IMAGINARY PART');
subplot(2,2,3),
plot(t,x),
xlabel('time'),
ylabel('x'),
title('PLOTTING(X)');
subplot(2,2,4),
plot3(real(x),imag(x),t),
xlabel('real part'),
ylabel('imag part'),
zlabel('time'),
title('3D PLOT OF A CONTINUOUS TIME SIGNAL');

 TASK-6:
A)PLOTTING  CONTINUOUS TIME SQUARE WAVE USING FOURIER SERIES
B)PLOTTING CONTINUOUS TIME TRIANGULAR WAVE USING FOURIER SERIES






% Square Wave
t=-10:0.001:10;
dc=1/2;
sum=0;
for k=1:2:200;
    sum=sum+(3/(k*pi))*sin(k*t);
end
x=sum+dc;
subplot(2,1,1),
plot(t,x),
xlabel('time'),
ylabel('magnitude'),
title('square wave'),
 
%Triangular Wave
t=0:0.01:5;
sum=0;
for k=1:2:200;
    sum=sum+(-16/(k^2*pi^2))*cos(6*pi*k*t);
end
subplot(2,1,2),
plot(t,sum),
xlabel('time'),
ylabel('magnitude'),
title('triangular wave')
 
 

 












TASK-7:
SOLVING DERIVATIVES, INTEGRALS & DIFFERENTIAL EQUATIONS

% DERIVATIVE
syms x a b c f 
f=3*x^3-4*x^2+6*x-3;
a=diff(f,x)
b=diff(a,x)
c=diff(b,x)
RESULT:
%a = 9*x^2 - 8*x + 6
%b = 18*x - 8
%c = 18

% PARTIAL DERIVATIVE
f=x^2*y+x*y^3-x^3+y^2;
a=diff(f,x)
b=diff(f,y)
RESULT:
%a = - 3*x^2 + 2*x*y + y^3
%b =  x^2 + 3*x*y^2 + 2*y




%INTEGRALS
PART-A:
f=3*x^3-4*x^2+5*x-3;
a=int(f,x)
b=int(f,x,0,5)
RESULT:
% a = (3*x^4)/4 - (4*x^3)/3 + (5*x^2)/2 - 3*x
% b = 4195/12
PART-B:
f=cos(x)*sin(y);
a=int(f,x,pi/2,pi)
b=int(a,y,0,2*pi)
RESULT:
 % a = -sin(y)
 % b = 0

%DIFFERENTIAL EQUATION
PART-A:
d=dsolve('D2y+3*Dy+2=sin(t)','t')
RESULT:
% d =C18 - (2*t)/3 - (3*cos(t))/10 - sin(t)/10 + C19/exp(3*t) + 2/9
PART-B:
f=dsolve('3*D2y+4*Dy=sin(t)','t')
RESULT:
%f =C25 - (4*cos(t))/25 - (3*sin(t))/25 + C26/exp((4*t)/3)
PART-C:
g=dsolve('D2y+2*Dy+3=sin(x)','y(0)=0','x')
RESULT:
%g =C30/exp(2*x) - (3*x)/2 - (2*cos(x))/5 - sin(x)/5 - C30 + 2/5
TASK-8:
EVALUATING LAPLACE TRANSFORM AND Z-TRANSFORMS
% LAPLACE TRANSFORM
>> syms f a t F  C b
f=exp(-a*t)*heaviside(t); 
// heaviside(t), 0 for t<0, 1 for t>0 and 0.5 for t==0
F=laplace(f)
RESULT:
% F = 1/(a + s)
>> syms x h t X H Y y
x=sin(t);
h=10*exp(10*t);
X=laplace(x)
H=laplace(h)
Y=H*X;
y=ilaplace(Y) // inverse laplace 
RESULT:
% X = 1/(s^2 + 1)
%H  = 10/(s - 10)
%y  =(10*exp(10*t))/101 - (10*cos(t))/101 - (100*sin(t))/101
% z-transform
>>syms x h X H Y y a n
x=a^n;
h=b^(-n);
X=ztrans(x)
RESULT:
% X = -z/(a - z)
TASK-9:
DISCRETE TIME SIGNAL 
PLOTTING

 % DISCRETE TIME SEQUENCE
n=-4:4;
x=[9 1 -2 4 -5 6 -1 7 -8];
stem(n,x);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT Sequence');
axis([-5 5 -10 10]);

 



% DISCRETE TIME EXPONENTIAL SIGNAL (n>=0)
% case 01(a>1)
c=2;
a=5;
n=0:15;
x=c*a.^n;
subplot(3,2,1);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a>1');
grid on;
%case 02(0<a<1)
c=2;
a=0.5;
n=0:15;
x=c*a.^n;
subplot(3,2,3);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when 0<a<1');
grid on;
%case 03(a=1)
c=2;
a=1;
n=0:15;
x=c*a.^n;
subplot(3,2,5)
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a=1');
grid on;
%case 04(a<-1)
c=4;
a=-2;
n=0:60;
x=c*a.^n;
subplot(3,2,2);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a<-1');
grid on;
%case 05(-1<a<0)
c=2;
a=-0.5;
n=0:30;
x=c*a.^n;
subplot(3,2,4);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when -1<a<0');
grid on;
%case 06(a=-1)
c=2;
a=-1;
n=0:15;
x=c*a.^n;
subplot(3,2,6)
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a=-1');
grid on;

 

% DISCRETE TIME EXPONENTIAL SIGNAL (n<=0)
% case 01(a>1)
c=2;
a=5;
n=-15:0;
x=c*a.^-n;
subplot(3,2,1);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a>1');
grid on;
%case 02(0<a<1)
c=2;
a=0.5;
n=-15:0;
x=c*a.^-n;
subplot(3,2,3);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when 0<a<1');
grid on;
%case 03(a=1)
c=2;
a=1;
n=-15:0;
x=c*a.^-n;
subplot(3,2,5)
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a=1');
grid on;
%case 04(a<-1)
c=4;
a=-2;
n=-60:0;
x=c*a.^-n;
subplot(3,2,2);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a<-1');
grid on;
%case 05(-1<a<0)
c=2;
a=-0.5;
n=-30:0;
x=c*a.^-n;
subplot(3,2,4);
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when -1<a<0');
grid on;
%case 06(a=-1)
c=2;
a=-1;
n=-15:0;
x=c*a.^-n;
subplot(3,2,6)
stem(n,x,'linewidth',2);
xlabel('time(sampled)');
ylabel('magnitude');
title('DT exponential signal when a=-1');
grid on;


 
TASK-10:
DISCRETE TIME CONVOLUTION  
n0=0:20;
x=5*(-0.5).^n0;
n1=-10:5;
h=(2/3).^n;
n2=-20:10;
y1=conv(x,h);
y=y1(1:length(n2));
subplot(3,1,1);
stem(n0,x);
xlabel('time(sampled)');
ylabel('magnitude x(n)');
title('input signal');
grid on;
subplot(3,1,2);
stem(n1,h);
xlabel('time(sampled)');
ylabel('magnitude h(n)');
title('transfer function h(n)');
grid on;
subplot(3,1,3);
stem(n2,y);
xlabel('time(sampled)');
ylabel('magnitude y(n)');
title('output signal');
grid on;

 

TASK-11:
CONTINUOUS TIME CONVOLUTION  
t=0:0.01:10;
x=ones(1,length(t));
h=2*exp(-1*t);
y1=conv(x,h)*0.01; //multiplying with step size
y=y1(1:length(t));
figure(1);
subplot(3,1,1);
plot(t,x);
xlabel('time');
ylabel('x(t)');
title('convolution of continuous time signal');
subplot(3,1,2);
plot(t,h);
xlabel('time');
ylabel('h(t)');
subplot(3,1,3);
plot(t,y);
xlabel('time');
ylabel('y(t)');
title('convolved signal')
grid on;

 

PLOTTING A CONTINUOUS TIME SINUSIOD


To plot a continuous time sinusiodal copy this code and paste it in installed matlab sofware, run the program you will get wave given below in the diagram.
%PART-A
a=10;
f=1000;
ph=pi/2;
T=1/f;
t=0:T/40:10*T; %10 cycles
x=a*sin(2*pi*f*t+ph);
plot(t,x),
xlabel('t'),
ylabel('x'),
title('PLOTTING A CONTINUOUS TIME SINUSIOD'),
grid on

%PART-B
a=10;
f=1000;
ph=pi/2;
T=1/f;
t=0:T/40:10*T; %10 cycles
x=a*cos(2*pi*f*t+ph);
plot(t,x),
xlabel('t'),
ylabel('x'),
title('PLOTTING A CONTINUOUS TIME SINUSIOD'),
grid on


Saturday, 31 May 2014

How to generate DISCRETE TIME CONVOLUTION in matlabs,

DISCRETE TIME CONVOLUTION  
n0=0:20;
x=5*(-0.5).^n0;
n1=-10:5;
h=(2/3).^n;
n2=-20:10;
y1=conv(x,h);
y=y1(1:length(n2));
subplot(3,1,1);
stem(n0,x);
xlabel('time(sampled)');
ylabel('magnitude x(n)');
title('input signal');
grid on;
subplot(3,1,2);
stem(n1,h);
xlabel('time(sampled)');
ylabel('magnitude h(n)');
title('transfer function h(n)');
grid on;
subplot(3,1,3);
stem(n2,y);
xlabel('time(sampled)');
ylabel('magnitude y(n)');
title('output signal');
grid on;

Saturday, 24 May 2014

Universal OBD-II Scan Tool

my this article is about a project perform by these group members at university of  engineering and technology which is used to find out that which part of the vehicle is not working , without wasting time in a short time, these students belong to computer system department and perform this project, its detail is given in my previous article,http://mobilezonex.blogspot.com/2014/05/how-to-find-out-fault-in-cars-in-seconds.html
Supervisor:  

Group Members:

Shawkat Ali  
  Amjad Ali   , Dr. Laiq Hassan  
     Saba Kanwal   
       Maria Shoukat   

CONTENTS
OVERVIEW
IMPLEMENTATION
RESULTS
FUTURE WORK

OVERVIEW
On-Board Diagnostics-II. 
Brief history.
Designing such a scanning tool that is compatible with every manufacturer vehicle.
The OBD-II standard connector specifies the type of diagnostic connector and its pin out.



Overview(Conti…)
OBD-II
Design hardware using  STN1110 IC
Interface STN1110 with pc via UART using Max232
Interface with DLC for compatibility with different vehicles
Apply for vehicle telemetry
Vehicle performance optimization






IMPLEMENTATION
Final schematic and design on PCB. 
The schematic was designed using Proteus software. 
Hardware design on Breadboard.
Testing hardware using different OBDII complaint vehicles. 
RESULTS
Proteus PCB design. (Completed) 
Hardware design.      (Completed)
Hardware testing.      (in progress)
ERP module.       (In progress)



Results (Conti…)


Results (Conti…)


Results (Conti…)
Results (Conti…)
FUTURE WORK
Hardware testing. 
ERP module Development & Testing.
Debug the whole project.



        GANTT CHART
Q’s IF ANY?????

Friday, 23 May 2014

NETWORK BASIC COMMANDS

  
Objectives:

Gather information including connection, host name, Layer 2 MAC address and Layer 3 TCP/IP network address information.

Compare network information to other PCs on the network.
Learn to use the TCP/IP Packet Internet Groper (ping) command from a workstation.
Learn to use the Trace Route (tracert) command from a workstation.

Step 1 Connect into the Internet

Establish and verify connectivity to the Internet. This ensures the computer has an IP address.

Step 2 Gather TCP/IP configuration information

Use the Start menu to open the Command Prompt, an MS-DOS-like window. Press Start > Programs > Accessories > Command Prompt

OR
Start > Programs > Command Prompt. OR
Press Start>Run Then type cmd.

The following figure shows the Command screen. Type ipconfig and press the Enter key. The spelling of ipconfig is critical while case is not. It is short for IP Configuration.  i do this task with my friend laptop sufyan and its cmd snip shot is given below



Fig: 1


Fig: 2
This first screen shows the IP address, subnet mask, and default gateway. The IP address and the default gateway should be in the same network or subnet, otherwise this host would not be able to communicate outside the network. In the figure the subnet mask tells us that the first three octets must be the same to be in the same network.

Note: If this computer is on a LAN, the default gateway might not be seen if it is running behind a Proxy Server. Record the following information for this computer.

Step 3 Record the following TCP/IP information for this computer

IP address: 192.168.1.6

Subnet Mask: 255.255.255.0

Default Gateway: 192.168.1.1

Difference between Fig.1 and Fig.2: The features of wireless LAN adaptor, wireless network connection are absent

Step 4 Compare the TCP/IP configuration of this computer to others on the LAN

If this computer is on a LAN, compare the information of several machines.

Are there any similarities? Yes, the Subnet mask and default gateway are similar.

What is similar about the IP addresses? The Network ID is same.

What is similar about the default gateways? Both of the machine's Default Gateway are same.

The IP addresses should share the same network portion. All machines in the LAN should share the same default gateway.
Record a couple of the IP Addresses:

192.168.1.2 , 192.168.1.6
Step 5: Check additional TCP/IP configuration information

To see detailed information, type ipconfig /all and press Enter. The figure shows the detailed IP configuration screen.


Fig.3: Command Screen for ipconfig /all


The host name, including the computer name and NetBIOS name should be displayed. Also, the DHCP server address, if used, and the date the IP lease starts and ends should be displayed. Look over the information. Entries for the DNS, used in name resolution servers, may also be present. The previous figure reveals that the router is performing both DHCP and DNS services for this network. This would likely be a small office or home office (SOHO) or small branch office implementation.

Notice the Physical Address (MAC) and the NIC model (Description).

(74-DE-2B-72-91-1E) and (Bluetooth Device <Personal Area Network>)Write down the IP addresses of any servers listed:

(192.168.1.2), (192.168.1.6) (192.168.1.102)

Write down the computer Host Name:
Sufiyan

Write down the Host Names of a couple other computers:

(HASHIM ELAHI),  (monA).

Do all of the servers and workstations share the same network portion of the IP address as the student workstation?  Yes

It would not be unusual for some or all of the servers and workstations to be in another network. It means that the computer default gateway is going to forward requests to the other network.

Step 6 Close the screen

Close the screen when finished examining network settings.
Repeat the previous steps as necessary. Make sure that it is possible to return to and interpret this screen.


Based on observations, what can be deduced about the following results taken from two computers connected to one switch?

Computer 1

IP Address: 192.168.1.2
Subnet Mask: 255.255.255.
Default Gateway: 192.168.1.1

Computer 2
IP Address: 192.168.1.6
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1

Computer 3
IP Address: 192.168.1.3
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1

Should they be able to talk to each other?

______________________________________________________________________________

Are they all on the same network? Why or why not?
Yes, to make sure that the IP address should be close enough.2. Using “ping” and “tracert “

Objective

Learn to use the TCP/IP Packet Internet Groper (ping) command.

Learn to use the Trace Route (tracert) command.
Observe name resolution occurrences using WINS and/or DNS servers.

Background

This lab assumes the use of any version of Windows. This is a non-destructive lab and can be done on any machine without concern of changing the system configuration.

Ideally, this lab is performed in a LAN environment that connects to the Internet. It can be done from a single remote connection via a modem or DSL-type connection. The student will need the IP addresses that were recorded in the previous part of the lab.

PING Command SET:

Ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS] -t ==> repetitive.

-n ==> number of echo to be sent
-l ==> sending buffer size [Max: 65500 bytes] -f ==> don’t fragment.
-r count ==> record route for count hops [3rd layer device] -j ==> loose source route
-k ==> strict source route -i TTL ==> time to live

-v TOS ==> Type of Service


Example:

Ping -t -l 60000 192.168.230.1 -f -l 1000

-l 1000
To see the difference between fragmenting and non-fragmenting, use -f

ping -r 3 192.168.230.1

Step 1 Establish and verify connectivity to the Internet

This ensures the computer has an IP address.

Step 2 Access the command prompt

As accessed in previous part of the lab.
Step 3 ping the IP address of another computer

Ping 192.168.1.2

In the window, type ping, a space, and the IP address of a computer recorded in the previous lab. The following figure shows the successful results of ping to this IP address. Ping uses the ICMP echo reply feature to test physical connectivity. Since ping reports on four attempts, it gives an indication of the reliability of the connection. Look over the results and verify that the ping was successful. Is the ping successful?

Step 4 ping the IP address of the default gateway
Ping 192.168.1.1


Try to ping the IP address of the default gateway if one was listed in the last exercise. If the ping is successful, it means there is physical connectivity to the router on the local network and probably the rest of the world.

Step 5 ping the IP address of a DHCP or DNS servers

Try to ping the IP address of any DHCP and/or DNS servers listed in the last exercise. If this works for both server and they are not in the network, what does this indicate?
No idea.


Was the ping successful? NO

Step 6 ping the Loopback IP address of this computer

Type the following command: ping 127.0.0.1

The 127.0.0.0 network is reserved for loopback testing. If the ping is successful, then TCP/IP is properly installed and functioning on this computer.


Was the ping successful? YES

Step 7t ping the hostname of another compuer

Try to ping the hostname of the computer that was recorded in the previous lab.

Step 8 ping the hostname of another computer using

Try to ping repetitively, the hostname of the computer

How can we stop the ping: CTL+C


Step 9 ping the Yahoo web site

Type the following command: ping www.yahoo.com
 The first output line shows the Fully Qualified Domain Name (FQDN) followed by the IP    address. A Domain Name Service (DNS) server somewhere in the network was able to resolve the name to an IP address. DNS servers resolve domain names, not hostnames, to IP addresses.
Without this name resolution, the ping would have failed because TCP/IP only understands valid IP addresses. It would not be possible to use the web browser without this name resolution.
With DNS, connectivity to computers on the Internet can be verified using a familiar web address, or domain name, without having to know the actual IP address. If the nearest DNS server does not know the IP address, the server asks a DNS server higher in the Internet structure.

What is the IP Address of www.yahoo.com: 46.228.47.115

How much time did our ping took to reach www.yahoo.com: 286Ms


Tracert Command SET:

tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

-d ==> do not resolve address to hostname.

-h maximum_hops ==> maximum number of Hosts to Search for Target -j host-list ==> loose source router along host-list
-w timeout ==> wait timeout milliseconds for each reply

Step 10 Trace the route to the Yahoo web site

Type tracert www.yahoo.com and press Enter.


Tracert is TCP/IP abbreviation for trace route. The preceding figure shows the successful result when running tracert from Bavaria in Germany. The first output line shows the FQDN followed by the IP address. Therefore, a DNS server was able to resolve the name to an IP address. Then there are listings of all routers the tracert requests had to pass through to get to the destination. tracert uses the same echo requests and replies as the ping command but in a slightly different way. Observe that tracert actually contacted each router three times. Compare the results to determine the consistency of the route. Notice in the above example that there were relatively long delays after router 11 and 13, possibly due to congestion. The main thing is that there seems to be relatively consistent connectivity. Each router represents a point where one network connects to another network and the packet was forwarded through.

What is the difference between the following commands?

Tracert www.yahoo.com
Tracert –h 20 www.yahoo.com


Tracert shows how much HOPS  the desired location is away, and Tracer -h20 declares the location which is at 20 hops distance away.Step 11 Trace a local host name or IP address
Tracert 192.168.1.1

Count the number of Hops: 30 Hops

Simulation of Line Coding Schemes in Matlab


Objectives
How to write Matlab code that encodes a digital data into digital signal?
Study sample Matlab program for unipolar NRZ, NRZ-L, and Bipolar AMI
Program Code
Unipolar NRZ
 A positive voltage represents a binary 1, and zero volts indicates a binary 0. It is the simplest line code.
% Unipolar NRZ
clc
message = [0 1 1 0 1 0 1];
data = [0 0 1 0 1 0 0 0 1 0 0 0 1 0];
i = 1 : 7;
j = 1.99 : 7.99;
time = [ ];
for k = 1 : 7
time = [time i(k), j(k)];
end
% Digital Signal Generation:
signal = [ ];
for t=1:2:13
    if (data(t) == 0)
        signal (t : t+1) = 0;
    else
        signal (t : t+1) = -1;
    end
end
subplot(2,1,1);
plot (time, signal)      % Plotting PCM Signal
xlabel ('Time (t)')
ylabel ('Amplitude (A)')
title('Digital Signal')

Simulation Results
 
NRZ-L
In this encoding schemes, 0 is represented by +ve volt and 1 is represented by negative volt.
Program Code
% NRZ-L
 
message = [0 1 0 1 1 1 0 0 1 1 1 1 ];
data = message;
i = 1:length(messgae);
j=1.99:length(message+0.99);
time = []
for (k = 1 : length(message))
    time= [time i(k) j(k)]
end
 
% Generating signal 
signal = [];
N = length(data);
for (t=1:2:N)
    if(data(t)==1)
        signal(t:t+1)=1;
    else
        signal(t:t+1)=-1;
    end
end
% display the signal
 
figure(1);
plot(time,signal,'linewidth',2)
title('NRZ-LZ')
xlabel('time')
ylabel('voltage level')
 
axis([1 8 -0.5 1.5 ])

Simulation Results
 


 
Pseudo Ternary Encoding
A multilevel binary encoding that complements the bipolar-AMI encoding: binary 1 is represented by a lack of pulse, and a binary 0 is represented by a positive or a negative pulse. The binary 0 pulses must alternate in polarity.

Program Code
clc
message = [0 1 1 0 1 1 1 0 0 0 1];   
data = zeros(1,2*length(message)-1);           
data (1 : 2 : end) = message;
i = 1 : 11;
j = 1.99 : 11 + 0.99;
time = [ ];
for (k = 1 : length(message));
    time = [time i(k), j(k)];   
end
% Gnerating Signal
signal = [ ];            
n = length(data);
prebit = 1;
for t = 1 : 2 : n                  
    if (data(t) == 0)
        signal(t : t+1) = 0;
    else if (data(t) == 1 & prebit == 1)
            signal (t : t+1) = 1;
            prebit = -1;
        else
            signal (t : t+1) = -1;
            prebit = 1;
        end
    end
end
subplot(2,1,1)
plot (time, signal)            % Plotting …
title ('Digital Signal')
xlabel ('Time')
ylabel ('Amplitude')
 

 

Thursday, 22 May 2014

Simulation of line coding scheme in Matlab


Manchester Coding Scheme:
Program :
data=[ 1 0 1 0 1 0  ];

i=1:length(data);
j=1.49:length(data)+0.49;
I=1.50:length(data)+0.50;
J=1.99:length(data)+0.99;
N=length(data);
time=[];
for k=1:length(data);
time=[time i(k),j(k),I(k),J(k)];
end

signal=[];
a=1;
prebit=1;

for t=1:length(data);
  
if(data(t)==0)
    signal(a:a+1)=1;
    signal(a+2:a+3)=-1;
      
elseif(data(t)==1)
    signal(a:a+1)=-1;
    signal(a+2:a+3)=1;
    
   
end
   
a=a+4;

end

plot(time,signal,'linewidth',4);
xlabel('time')
ylabel('signal')





Simulation Results









Differential Manchester Coding Scheme :
Program :
data=[ 1 0 1 0 1 0  ];

i=1:length(data);
j=1.49:length(data)+0.49;
I=1.50:length(data)+0.50;
J=1.99:length(data)+0.99;
N=length(data);
time=[];
for k=1:length(data);
time=[time i(k),j(k),I(k),J(k)]; %Time vector
end

signal=[];
a=1;
prebit=1;

%Signal Generation
for t=1:length(data);
    if(data(t)==0 && prebit==1)
        signal(a:a+1)=-1;
        signal(a+2:a+3)=1;
        prebit=1;
    elseif(data(t)==0 && prebit==-1)
        signal(a:a+1)=1;
        signal(a+2:a+3)=-1;
        prebit=-1;
    elseif(data(t)==1 && prebit==-1)
        signal(a:a+1)=-1;
        signal(a+2:a+3)=1;
        prebit=1;
    elseif(data(t)==1 && prebit==1) 
        signal(a:a+1)=1;
        signal(a+2:a+3)=-1;
        prebit=-1;

end
           a=a+4;
end
plot(time,signal,'linewidth',4); %Plot signal
title('Differential Manchester');
xlabel('Time');
ylabel('Differential Manchester');

%constellation diagram
   M = 4;
x = [0:M-1];
scatterplot(modulate(modem.pskmod(M),x));

Simulation Results :


  

Implementing  BPSK , QPSK and MFSK in Matlab

Program Code For BPSK 
clc;
clear all;
message=[1 1 0 0 1 0];
f_one=1.5;
fs=1000;% frequency
t=[0:1/fs:1];
A=5;
x=A*cos(2*pi*f_one*t+pi); %binary 0
y=A*cos(2*pi*f_one*t); %binary 1
time=t;
for i=1:length(message)-1;
    time=[time i+t];
end
%ask signal logic
ask_signal=[];
for i=1:length(message);
   if(message(i)==0)
       ask_signal=[ask_signal x];
   else
       ask_signal=[ask_signal y];
   end
end
   
plot(time,ask_signal,'linewidth',2);
xlabel('no of bits per second')
ylabel('signal value')

%constellation diagram BPSK
M = 2;
x = [0:M-1];
scatterplot(modulate(modem.pskmod(M),x));

Simulation :



  


Programme Code For MFSK :
clc; %clears the command window
clear all; %clears the workspace
message=[1 1 0 0 1 0 1 0 0]; %binary input is
                                                 
if (rem(length(message),3)~=0)     %for don’t care bits
    display('Error in Message'); 
end
f_one=1;
fs=1000; %frequency
t=[0:2/fs:1];
A=5;
w=A*cos(2*pi*f_one*t); %binary 000   (1 Hz)
x=A*cos(4*pi*f_one*t); %binary 001   (2 Hz)
y=A*cos(6*pi*f_one*t); %binary 010   (3 Hz)
z=A*cos(8*pi*f_one*t); %binary 011   (4 hz)
W=A*cos(10*pi*f_one*t);%binary 100   (5 Hz)
X=A*cos(12*pi*f_one*t);%binary 101   (6 Hz)
Y=A*cos(14*pi*f_one*t);%binary 110   (7 Hz)
Z=A*cos(16*pi*f_one*t);%binary 111   (8 Hz)
time=t;
for i=1:(length(message)/3)-1;
    time=[time i+t];
end
%ask signal logic
ask_signal=[];
for i=1:3:length(message);
   if(message(i)==0 && message(i+1)==0 && message(i+2)==0)
       ask_signal=[ask_signal y];
   elseif(message(i)==0 && message(i+1)==0 && message(i+2)==1)
       ask_signal=[ask_signal z];
   elseif(message(i)==0 && message(i+1)==1 && message(i+2)==0)
       ask_signal=[ask_signal x];
   elseif(message(i)==0 && message(i+1)==1 && message(i+2)==1)
       ask_signal=[ask_signal w];
   elseif(message(i)==1 && message(i+1)==0 && message(i+2)==0)
       ask_signal=[ask_signal W];
   elseif(message(i)==1 && message(i+1)==0 && message(i+2)==1)
       ask_signal=[ask_signal X];
   elseif(message(i)==1 && message(i+1)==1 && message(i+2)==0)
       ask_signal=[ask_signal Y];
   elseif(message(i)==1 && message(i+1)==1 && message(i+2)==1)
       ask_signal=[ask_signal Z];
   end
end
   %figure
   plot(time,ask_signal,'linewidth',2);
   xlabel('no of bits per second');
   ylabel('signal value');
    
% constellation diagram
inphase = [1 1 1 1 1 1 1 1];
quadr = [0 0 0 0 0 0 0 0];
 const = inphase + j*quadr;
scatterplot(const,1,0,'*');
axis([-3 3 -3 3]); 

Simulation :
  




Programme Code For QPSK :

clc; %clears the command window
clear all; %clears the workspace
message=[1 1 0 0 1 0]; %binary input is
                                                 
if (rem(length(message),2)~=0)     %for don’t care bits
    message(1,length(message)+1)=1; 
end
f_one=1.5;
fs=1000; %frequency
t=[0:2/fs:1];
A=5;
w=A*cos(2*pi*f_one*t+pi/4);%binary 11
x=A*cos(2*pi*f_one*t+3*pi/4); %binary 01
y=A*cos(2*pi*f_one*t-3*pi/4); %binary 00
z=A*cos(2*pi*f_one*t-pi/4); %binary 10
time=t;
for i=1:(length(message)/2)-1;
    time=[time i+t];
end
%ask signal logic
ask_signal=[];
for i=1:2:length(message);
   if(message(i)==0 && message(i+1)==0)
       ask_signal=[ask_signal y];
   elseif(message(i)==1 && message(i+1)==0)
       ask_signal=[ask_signal z];
   elseif(message(i)==0 && message(i+1)==1)
       ask_signal=[ask_signal x];
   elseif(message(i)==1 && message(i+1)==1)
       ask_signal=[ask_signal w];

end
end

%figure
plot(time,ask_signal,'linewidth',2);
xlabel('no of bits per second');
ylabel('signal value');
    
% constellation diagram
inphase = [1 -1 1 -1];
quadr = [1 1 -1 -1];
inphase = [inphase; inphase]; inphase = inphase(:);
quadr = [quadr; quadr]; quadr = quadr(:);
const = inphase + j*quadr;
scatterplot(const,1,0,'*');
     
axis([-3 3 -3 3]);


Simulation :