0% found this document useful (0 votes)
68 views2 pages

All All: For If For End Elseif For End End End For For End End

This document contains MATLAB code to simulate frequency-shift keying (FSK) modulation and demodulation. It defines an input binary sequence, two carrier frequencies, generates the FSK signal by switching between the frequencies, plots the message, carrier and FSK signals. It then demodulates the FSK signal by comparing it to the carrier frequencies to recover the original binary sequence, and plots the demodulated signal. The code also calculates the minimum bandwidth required for the FSK modulation.

Uploaded by

Pawan Rauniyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views2 pages

All All: For If For End Elseif For End End End For For End End

This document contains MATLAB code to simulate frequency-shift keying (FSK) modulation and demodulation. It defines an input binary sequence, two carrier frequencies, generates the FSK signal by switching between the frequencies, plots the message, carrier and FSK signals. It then demodulates the FSK signal by comparing it to the carrier frequencies to recover the original binary sequence, and plots the demodulated signal. The code also calculates the minimum bandwidth required for the FSK modulation.

Uploaded by

Pawan Rauniyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

FSK

clc;
clear all;
close all;
s=[1 0 1 0]; %%%%%input sequence%%%%
%%%%%tb=10;%%%
%%%%%%r=1;%%%%%%
nb=10;%%%%baud rate%%%
f1=10; %%%%first frequency%%%
f2=50; %%%%second frequency%%%
a=length (s);%%%%length of input sequence%%%%
for i=1:a %%%%creation of for loop i=1:4%%%%
if s(1,i)==1 %%%%comparing the value stored into the variable%%%%
freq=f1%%%%if condition true freq=f1%%%%%
for t= (i-1)*100+1:i*100 %%%%%timing range%%%%%
x(t)= sin(2*pi*freq*t/1000); %%%%general expression for FSK%%%
end %%%end of for loop%%%
elseif s(1,i)==0 %%%if condtion goes to false den consider else part%%
freq=f2%%%%select the second frequency%%%
for t=(i-1)*100+1:i*100 %%%timing range for binary o%%%
x(t)= sin(2*pi*freq*t/1000); %%%%general expression for FSK%%%
end %%%end of if statment%%%
end %%%end of for loop%%%
end %%%%end of for loop%%%%%
for i=1:a%%%%creation of for loop for carrier signal%%%
for t=(i-1)*100+1:i*100%%%%timing range%%%
c(t)=sin(2*pi*f1*t/1000);%%%expression for carrier signal%%
end%%%%end of for loop%%
end%%%end of for loop%%%
subplot(4,1,1);%%%%%create axes in tiled positions.subplot(row,column,position)%%%%%
stairs(s);%%%%draws a stairstep graph of the elements of s%%%%%
title('Message Signal');%%%%title to current axes%%%
xlabel('time in sec');%%%%xlabel%%
ylabel('Amplitude');%%%ylabel%%%
grid on %%%The grid function turns the current axes' grid lines on and off%%
subplot(4,1,2);
plot(c);%%%%plotting the carrier signal%%%%
title('Carrier Signal');
xlabel('time in sec');
ylabel('Amplitude');
grid on
subplot(4,1,3);
plot(x); %%%%%%plotting the FSK signal%%%
xlabel('time in secs');

ylabel('amplitude in volts')
title ('FSK')
grid on
%%%%%%Demodulation%%%%
len=length(x);%%%%length of FSK Signal%%
for t=len:1;%%%timing range%%%
if x(t)==sin(2*pi*freq*t/1000)%%%%general expression%%%
s(t)=1;%%%%if condition true%%%
else
s(t)=0;
end
end
subplot(4,1,4)
stairs(s);
title('demodulated FSK signal ')
xlabel('time in sec')
ylabel('amplitude')
grid on
%%%%%tb=10;%%%
%%%%%%r=1;%%%%%%
nb=1;%%%%baud rate%%%
bw=2*nb;%%%%%%%%nb=Baud rate%%%%
%%%%%baud rate=bit rate%%%%
%%%%%r=bit rate%%%%
%%%%%bw=(f2-f1)+r;
%%%%%r=1/tb;%%% %%%%tb=Pulse width%%%
disp(bw)

You might also like