clc;clear;close all;
N = 10;
Tb = 3;
fc1 = 6;
fc2 = 5;
fs = 150;
t = 0:1/fs:Tb-1/fs;
m = randi([0 1],1,N);
c1 = sqrt(2/Tb)*sin(2*pi*fc1*t);
c2 = sqrt(2/Tb)*sin(2*pi*fc2*t);
message = [];
fsk = [];
time = [];
for i = 1:N
if m(i)==1
msg = ones(1,length(t));
signal = c1;
else
msg = zeros(1,length(t));
signal = c2;
end
message = [message msg];
fsk = [fsk signal];
time = [time (i-1)*Tb+t];
end
figure;
subplot(4,1,1);
stem(0:N-1,m,'filled');
title('Binary Data');
xlabel('Bit Number');
ylabel('Bit');
axis([0 N-1 -0.5 1.5]);
grid on;
subplot(4,1,2);
plot(time,message,'LineWidth',1.5);
title('Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
axis([0 N -0.2 1.2]);
grid on;
subplot(4,1,3);
plot(time,fsk,'LineWidth',1.5);
title('BFSK Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
demod = zeros(1,N);
for i=1:N
r = fsk((i-1)*length(t)+1:i*length(t));
x1 = sum(r.*c1);
x2 = sum(r.*c2);
if x1>x2
demod(i)=1;
else
demod(i)=0;
end
end
subplot(4,1,4);
stem(0:N-1,demod,'filled');
title('Demodulated Data');
xlabel('Bit Number');
ylabel('Bit');
axis([0 N-1 -0.5 1.5]);
grid on;
disp('Original Bits:');
disp(m);
disp('Recovered Bits:');
disp(demod);
if isequal(m,demod)
disp('Demodulation Successful');
else
disp('Demodulation Failed');
end
To embed this project on your website, copy the following code and paste it into your website's HTML: