Pages

Wednesday, April 24, 2013

QPSK modulation


%try cosine wave plot also
%a=.5;  
pi=3.14;
f=1;

x=[0 0 0 1 1 0 1 1 0 0 1 0  1 1 0 1];
nx=size(x,2);

i=1;
while i<nx+1
    t = i:0.001:i+2;
    if x(i)==0 && x(i+1)==0
        z=sin(2*pi*f*t-3*pi/4);
        dibit=0;
    elseif x(i)==0 && x(i+1)==1
        z=sin(2*pi*f*t-pi/4);
        dibit=1;
    elseif x(i)==1 && x(i+1)==0
        z=sin(2*pi*f*t+pi/4);
        dibit=2;
    else
        z=sin(2*pi*f*t+3*pi/4);
        dibit=3;
    end
    %subplot(2,1,1);
    plot(t,dibit,'r');
    %grid on;
    hold on;
    %subplot(2,1,2);
    plot(t,z);
    hold on;
    grid on;
    axis([1 20 -3 3]);
    i=i+2;
end

Saturday, April 20, 2013

FM modulation


Ac=1;
fc=1;

Am=1;
fm=0.1;
kf=1.5;
B=kf*Am/fm;

t=[0:0.1:20];
ct=Ac*cos(2*pi*fc*t);
mt=Am*cos(2*pi*fm*t);
FMt=Ac*cos(2*pi*fc*t+B*sin(2*pi*fm*t));

subplot(2,2,1);
plot(mt);
ylabel('message signal');
grid on;

subplot(2,2,2);
plot(ct);
ylabel('carrier');
grid on;

subplot(2,2,3);
plot(FMt);
ylabel('FM signal');
grid on;

AM modulation


clc;
Ac=2;
fc=.9;

Am=.5;
fm=.05;
Fs=100;

ka=1;

t=[0:0.1:50];
ct=Ac*cos(2*pi*fc*t);
mt=Am*cos(2*pi*fm*t);
DSBAMt=ct.*(1+ka*mt);

subplot(2,2,1);
plot(mt);
ylabel('message signal');
grid on;

subplot(2,2,2);
plot(ct);
ylabel('carrier');
grid on;

subplot(2,2,3);
plot(DSBAMt);
ylabel('DSBAM signal');
grid on;

Saturday, January 26, 2013

matlab code for digital modulation(ask, fsk and psk)


%matlab code for digital modulation(ask, fsk and psk)
pi=3.14;
f=5;
f2=10;
phi=pi;

x=[1 0 1 1 0];
nx=size(x,2);

i=1;
while i<nx+1
     t = i:0.001:i+1;
    if x(i)==1
       ask=sin(2*pi*f*t);
       fsk=sin(2*pi*f*t);
       psk=sin(2*pi*f*t);
    else
        ask=0;
        fsk=sin(2*pi*f2*t);
        psk=sin(2*pi*f*t+phi);
    end
    subplot(3,1,1);
    plot(t,ask);
    hold on;
    grid on;
    axis([1 10 -2 2]);
 
    subplot(3,1,2);
    plot(t,fsk);
    hold on;
    grid on;
    axis([1 10 -2 2]);
 
    subplot(3,1,3);
    plot(t,psk);
    hold on;
    grid on;
    axis([1 10 -2 2]);
 
    i=i+1;
end

Friday, December 21, 2012

matlab code for line coding : unipolar, polar, bipolar and manchester code

%Matlab code to generate line code wave form  for given bit stream

clc;
close all;
clear all;
x=[1 0 1 1 0 1];
nx=size(x,2);
sign=1;
i=1;
while i<nx+1
    t = i:0.001:i+1-0.001;
    if x(i)==1
        unipolar_code=square(t*2*pi,100);
        polar_code=square(t*2*pi,100);
        bipolar_code=sign*square(t*2*pi,100);
        sign=sign*-1;
        manchester_code=-square(t*2*pi,50);
    else
        unipolar_code=0;
        polar_code=-square(t*2*pi,100);
        bipolar_code=0;
        manchester_code=square(t*2*pi,50);
    end
    subplot(4,1,1);
    plot(t,unipolar_code);
    ylabel('unipolar code');
    hold on;
    grid on;
    axis([1 10 -2 2]);
 
    subplot(4,1,2);
    plot(t,polar_code);
    ylabel('polar code');
    hold on;
    grid on;
    axis([1 10 -2 2]);
 
    subplot(4,1,3);
    plot(t,bipolar_code);
    ylabel('bipolar code');
    hold on;
    grid on;
    axis([1 10 -2 2]);
     
    subplot(4,1,4);
    plot(t,manchester_code);
    ylabel('manchester code');
    hold on;
    grid on;
    axis([1 10 -2 2]);
 
    i=i+1;
end

Matlab code for convolution of two signals without using conv function

%Matlab code for convolution of two signals without using conv function

close all
clear all
x=input('Enter x:   ')                % input x in the form [1,2,3,4,5]
h=input('Enter h:   ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];                     % padding of n zeros
H=[h,zeros(1,m)];                    % padding of m zeros
for i=1:n+m-1
    Y(i)=0;
    for j=1:i
        Y(i)=Y(i)+X(j)*H(i-j+1);
    end
end
Y
stem(Y);
ylabel('Y[n]');
xlabel('----->n');
title('Convolution of Two Signals without conv function');