Sunteți pe pagina 1din 9

Frequency Shift Keying using MATLAB

clc
clear all
close all
m=input('enter the binary sequency')
l=length(m)
t=[0.01:0.01:l]
for i=1:1:l
a((i-1)*100+1:i*100)=m(i)
end
% the fsk can be written as sum of two asks having different frequencies
% generating the ASK Signal for the inputed sequence with high frequency
f1=a.*(sin(2*pi*5*t))
f2=not(a).*sin(2*pi*t)
fsk=f1+f2
figure(1)
plot(f1)
title('ASk signal')
figure(2)
plot(f2)
title('ask signal')
figure(3)
plot(fsk)
title('frequency shift keying signal')

figure(4)
hold on
plot(f1,'black')
plot(f2,'red')
helg=legend('high frequency signal','low frequency signal')
hold off

Matlab Program for ASK


clear all;
clc;
close all;
F1=input('Enter the frequency of carrier=');
F2=input('Enter the frequency of pulse=');
A=3;%Amplitude
t=0:0.001:1;
x=A.*sin(2*pi*F1*t);%Carrier Sine wave
u=A/2.*square(2*pi*F2*t)+(A/2);%Square wave message
v=x.*u;
subplot(3,1,1);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Carrier');

grid on;
subplot(3,1,2);
plot(t,u);
xlabel('Time');
ylabel('Amplitude');
title('Square Pulses');
grid on;subplot(3,1,3);
plot(t,v);
xlabel('Time');
ylabel('Amplitude');
title('ASK Signal');
grid on;

Matlab Program for PSK / Matlab Code for PSK


clear all;
clc;
close all;
set(0,'defaultlinelinewidth',2);
A=5;
t=0:.001:1;
f1=input('Carrier Sine wave frequency =');

f2=input('Message frequency =');


x=A.*sin(2*pi*f1*t);%Carrier Sine
subplot(3,1,1);
plot(t,x);
xlabel('time');
ylabel('Amplitude');
title('Carrier');
grid on;
u=square(2*pi*f2*t);%Message signal
subplot(3,1,2);
plot(t,u);
xlabel('time');
ylabel('Amplitude');
title('Message Signal');
grid on;

v=x.*u;%Sine wave multiplied with square wave


subplot(3,1,3);
plot(t,v);
axis([0 1 -6 6]);

xlabel('t');
ylabel('y');
title('PSK');
grid on;

Frequency Modulation:

clear all
ts=0.0001;
t = 0:ts:1;
% time variable
fc =1000;
% carrier frequency
F=5;
%-%
% Create message signal m(t)%
%-%
m = sawtooth(2*pi*F*t);
kf =2000*pi;
% frequency deviation constant
%-%
%Modulating the carrier with the message signal%
%-%
carrier = cos(2*pi*fc*t);
modulated = cos(2*pi*fc*t + kf*ts*cumsum(m));
%-%
%Plotting the m(t)%
%-%
subplot(3,1,1)
plot(t,m,b:,'linewidth,2)
title(Message Signal,'Fontsize,12);
xlabel(time(seconds)\rightarrow);
ylabel(amplitude(volts)\rightarrow);
grid on;
%-%
%Plotting the carrier%
%-%
subplot(3,1,2)

plot(t,carrier,b,'linewidth,2.5);
title(carrier Signal,'Fontsize,12);
xlabel(time(seconds)\rightarrow);
ylabel(amplitude(volts)\rightarrow);
grid on;
%-%
%Plotting the modulated%
%-%
subplot(3,1,3)
plot(t,modulated,m:);
title(Frequency Modulated Signal,'Fontsize,12);
xlabel(time(seconds)\rightarrow);
ylabel(amplitude(volts)\rightarrow);
grid on;
axis([0 1 -1.5 1.5]);
_______________________________________________

Phase Modulation:

clc;
clear all;
close all;
%=======================================================%
%Phase Modulation%
%=======================================================%
t = 0:0.0001:1;
% time variable
fc=input(Enter carrier frequency between 50 to 100= )%For better results
Fm=5;
%=======================================================%
%Create message signal m(t)%
%=======================================================%
m = sawtooth(2*pi*Fm*t);
kp = pi/2;
% phase deviation constant
%=======================================================%
%Modulating the carrier with the message signal%
%=======================================================%
carrier =cos(2*pi*fc*t);
modulated = cos(2*pi*fc*t + kp*m);

%=======================================================%
%Plotting the signals%
%=======================================================%
subplot(3,1,1)
plot(t,m,:r,'linewidth,2)
xlabel(time(seconds)>);
ylabel(amplitude(volts)>);
title(Message Signal,'Fontsize,14);
grid on;
subplot(3,1,2)
plot(t,carrier,k,'linewidth,2);
xlabel(time(seconds)>);
ylabel(amplitude(volts)>);
title(carrier Signal,'Fontsize,14);
grid on;
subplot(3,1,3)
plot(t,modulated,.-b);
xlabel(time(seconds)>);
ylabel(amplitude(volts)>);
title(Phase Modulated Signal,'Fontsize,14);
grid on;
axis([0 1 -1.5 1.5]);

MATLAB Code:clc
close all;
clear all;
t=0:0.0001:1;
fm=input('enter the msg frequency');
am=input('enter the msg amplitude');
fc=input('enter carrier signal frequency');
ac=input('enter amplitude of carrier signal');
m=am*cos(2*pi*fm*t);
c=cos(2*pi*fc*t);
x=m.*c;
mod=x+(ac.*c);

%plot
subplot(4,1,1),plot(t,m);
xlabel('time');
ylabel('amplitude');
legend('Message signal m(t)');
title('message');

subplot(4,1,2),plot(t,c);
xlabel('time');
ylabel('amplitude');
legend('Carrier signal c(t)');
title('carrier');
subplot(4,1,3),plot(t,mod);
xlabel('time');
ylabel('amplitude');
legend('Amplitude modulated signal s(t)');
title('mod');

%fm signal
b=(fc-fm)/fm;
modfm=ac.*cos(2*pi*fc.*t + b*sin(2*pi*fm.*t));
subplot(4,1,4)
plot(t,modfm);
xlabel('time---(sec)');
ylabel('amp');
legend('Frequency modulated signal s(t)');
title('FM signal')

Input and Output:


enter the msg frequency10
enter the msg amplitude5
enter carrier signal frequency100
enter amplitude of carrier signal5

Figure:

S-ar putea să vă placă și