Saturday, January 25, 2014

Matlab Program for Amplitude Shift Keying (ASK) Generation

with 0 Comment
Amplitude Shift Keying - Matlab Program:

clc
clear all;
close all;
N=10;
x=randint(1,N);
k=1;
for t=0.01:0.01:10
    c(k)=sin(2*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)=0;
        end
    end
    if x(j)==1
        for i=(j-1)*100+1:1:j*100
            y(i)=1;
            tr(i)=c(i);
        end
    end
end
for i=1:1:1000
    re(i)=tr(i)*c(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(5,1,1);
plot(y);
title('message Signal');
subplot(5,1,2);
plot(c);
title('Carrier Signal');
subplot(5,1,3);
plot(tr);
title('Transmitted Signal');
subplot(5,1,4);
plot(re);
title('Received Signal');
subplot(5,1,5);
plot(det);
title('Detected Signal');

Amplitude Shift Keying Generation:

clc
clear all;
close all;
N=10;%No.of Data
x=randint(1,N);
%Carrier Generation
k=1;
for t=0:0.01:10
    c(k)=2*sin(2*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)=y(i)*c(i);
        end
    else
        for i=(((j-1)*100)+1):1:(j*100)
            y(i)=0;
            R(i)=y(i)*c(i);
        end
    end
end
for i=1:1:1000
    re(i)=R(i)*c(i);
end
for j=1:N
    d=0;
    for i=(((j-1)*100)+1):1:(j*100)
        d=d+re(i)
    end
    if d>=0.5
        r(j)=1;
    else
        r(j)=0;
    end
end
x%Transmitted Data Sequence
r%Detected Data Sequence
figure(1);
subplot(3,1,1);
plot(y);
title('Binary Input');
xlabel('Time in ms');
ylabel('Amplitude');
subplot(3,1,2);
plot(c);
title('Carrier Signal');
xlabel('Time in ms');
ylabel('Amplitude');
subplot(3,1,3);
plot(R);
title('Amplitude Shift Keying');
xlabel('Time in ms');
ylabel('Amplitude');

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive