All All: For For End End
All All: For For End End
clc;
clear all;
close all;
x=[1 0 1 1 0 1];
l=length(x);
fc=20;
fm=80;
for i=1:l
amp=x(1,i);
for t=(i-1)*100+1:i*100
inp(t)=amp;
end
end
subplot(3,1,1);
plot(inp);
title('input signal');
axis([1 t -2 2]);
grid on;
ylabel('amplitude--->');
xlabel('time--->');
%fsk modulation
for i=1:l
amp=x(1,i);
for t=(i-1)*100+1:i*100
if amp==1
freq=fm;
inp(t)=cos(2*pi*freq*t/1000);
else if amp==0
freq=fc;
inp(t)=cos(2*pi*freq*t/1000);
end
end
end
end
subplot(3,1,2);
plot(inp);
title('fsk signal');
axis([1 t -2 2]);
grid on;
ylabel('amplitude--->');
xlabel('time--->');
%fsk demodulation
for i=1:l
if freq==(fm*x(1,i))
for t=(i-1)*100+1:i*100
d(t)=1;
end
else
for t=(i-1)*100+1:i*100
d(t)=0;
end
end
end
subplot(3,1,3);
plot(d);
title('recovered signal');
axis([1 t -2 2]);
grid on;
ylabel('amplitude--->');
xlabel('time--->');