Saturday, January 25, 2014

Matlab Program for Frequency Shift Keying (FSK) Generation

with 0 Comment
Frequency Shift Keying - Matlab Program:

clc
clear all
close all
N=10;
x=randint(1,N);
k=1;
for t=0.01:0.01:10
    c1(k)=sin(2*pi*t);
    c2(k)=sin(4*pi*t);
    k=k+1;
end
for j=1:1:N;
    if x(j)==0
        for i=(j-1)*100+1:1:j*100
            y(i)=0;
            tr(i)=c2(i);
        end
    end
    if x(j)==1
        for i=(j-1)*100+1:1:j*100
            y(i)=1;
            tr(i)=c1(i);
        end
    end
end
for i=1:1:1000
    re(i)=tr(i)*c1(i)*c2(i);
end

for j=1:1:N
    d=0;
    for i=(j-1)*100+1:1:j*100
        d=d+re(i);
    end
 
  if d>0.5
      det(j)=1;
  else
      det(j)=0;
  end
end
for j=1:1:N
    if det(j)==0
        for i=(j-1)*100+1:1:j*100
            det(i)=0;
        end
    end
    if x(j)==1
        for i=(j-1)*100+1:1:j*100
            det(i)=1;
        end
    end
end
subplot(6,1,1);
plot(y);
title('message signal');
subplot(6,1,2);
plot(c1);
title('Carrier Signal-1');
subplot(6,1,3);
plot(c2);
title('Carrier Signal-2');
subplot(6,1,4);
plot(tr);
title('Transmitted Signal');
subplot(6,1,5);
plot(re);
title('Received Signal');
subplot(6,1,6);
plot(det);
title('Detected Signal');

Frequency Shift Keying Generation:

clc
N=10;%No.of Data
x=randint(1,N);
%Carrier Generation
k=1;
for t=0:0.01:10
    c1(k)=2*sin(2*pi*t);
    k=k+1;
end
k=1;
for t=0:0.01:10
    c2(k)=2*sin(4*pi*t);
    k=k+1;
end
for j=1:1:N;
    if x(j)==1
        for i=(((j-1)*100)+1):1:(j*100)
            y(i)=1;
            R(i)=c1(i);
        end
    else
        for i=(((j-1)*100)+1):1:(j*100)
            y(i)=0;
            R(i)=c2(i);
        end
    end
end
for i=1:1:1000
    re1(i)=R(i)*c1(i);
end
for i=1:1:1000
    re2(i)=R(i)*c2(i);
end
for j=1:N
    d1=0;
    d2=0;
    for i=(((j-1)*100)+1):1:(j*100)
        d1=d1+re1(i);
        d2=d2+re2(i);
    end
    if d1>d2
        r(j)=1;
    else
        r(j)=0;
    end
end
x%transmitted data sequence
r%detected data sequence
figure(1);
subplot(2,1,1);
plot(y);
title('Binary Input');
xlabel('Time in ms');
ylabel('Amplitude');
subplot(2,1,2);
plot(c1);
title('Carrier Signal 1');
xlabel('Time in ms');
ylabel('Amplitude');
figure(2);
subplot(2,1,1);
plot(c2);
title('Carrier Signal 2');
xlabel('Time in ms');
ylabel('Amplitude');
subplot(2,1,2);
plot(R);
title('Frequency Shift Keying');
xlabel('Time in ms');
ylabel('Amplitude');

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive