Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help inmatlab code of fsk demodulation

Status
Not open for further replies.

Shruti01

Member level 3
Joined
Apr 14, 2010
Messages
67
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Mumbai, India
Activity points
1,941
hello,
I have written a matlab code for fsk modulation...the explanation of my code is first I have generated a random sequence. Then i have compared that with threshold. If the number is greater than or equal to threshold then we assign that number to 1 else we assign the number to 0. Thus we get a binary sequence. If the bit is equal to 1, the frequency fc1 is switched on and when the bit is equal to 0, the frequency fc2 is switched on. Now the fsk signal generated is demodulated by using two bandpass filters that are tuned to frequencies of both carrier's fc1 and fc2.... Can u help me out wid the demodulation part... my code is as follows:
clc;
close all;
clear all;
no_of_bits=1000;
no_of_samples=200;
threshold = 0.5;
snr=[-3:1:20];
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
fc1=cos(2*pi*3000*t1); % Carrier frequency 1
fc2=cos(2*pi*2000*t1); % Carrier frequency 2
A = rand(1,no_of_bits); % Generate a random sequence
for i=1:no_of_bits
if (A(i)>=threshold)
A(i)=1;
else
A(i)=0;
end
d = A(1:no_of_bits); % Binary sequence
for j = 1:length(d)
if d(j)==1
fskmod=fc1;
else
fskmod=fc2;
end
end
 

u mite be plotting fskmod.rite?the problem s dat u r assigning to fskmod the last vale of fc1 or fc2..i.e, u r not saving freqs corresponding to each bit
 

clc;
close all;
clear all;
no_of_bits=5;
no_of_samples=200;
threshold = 0.5;
snr=[-3:1:20];
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
fc1=cos(2*pi*3000*t1); % Carrier frequency 1
fc2=cos(2*pi*2000*t1); % Carrier frequency 2
A=rand(1,no_of_bits); % Generate a random sequence
for i=1:no_of_bits
if (A(i)>=threshold)
A(i)=1;
else
A(i)=0;
end;
end;
d = A(1:no_of_bits); % Binary sequence
for j = 1:length(d)
if d(j)==1
fsk_mod(j,:)=fc1;
else
fsk_mod(j,:)=fc2;
end;
end
for j = 1:length(d)
plot((j-1)*no_of_samples+1:1:j*no_of_samples,fsk_mod(j,:));
hold on;
end;


this code will give u the fsk modulated signal
 

hello,
I am getting wrong plot for ber vs snr curve for fsk. My matlab code is as follows:

clc;
close all;
clear all;
no_of_bits=1000;
M=100;
no_of_samples=5000;
threshold = 0.5;
snr=[-3:1:20];
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t1=linspace(0, 1, no_of_samples);
f1=cos(2*pi*1000*t1);
f2=cos(2*pi*2000*t1);
n=50; % order of the filter
fsamp=5000; % sampling frequency
fc1=1000;
fc2=2000;
delta=500;
w1=fc1-delta;
w2=fc1+delta;
w3=fc2-delta;
w4=fc2+delta;
w11=w1/fsamp; % Frequency normalization
w22=w2/fsamp;
w33=w3/fsamp;
w44=w4/fsamp;
b1=fir1(n,[w11 w22]); % filter centered at fc1 where w22 is greater than w11
b2=fir1(n,[w33 w44]); % filter centered at fc2 where w33 is greater than w44
for i=1:10
ber(i)=0;
end
for k=1:length(snr)
sn(k)=snr(k)+6;
err(k)=0;
for m=1:M
A = rand(1,no_of_bits); % Generate a random sequence
for i=1:no_of_bits
if (A(i)>=threshold)
A(i)=1;
else
A(i)=0;
end
end
d = A(1:no_of_bits); % Binary sequence
for i=1:no_of_bits
for j = 1:length(d)
if d(j)==1
fskmod=fc1;
else
fskmod=fc2;
end
end
%Receiver side
received=fskmod; % FSK modulated signal
if (b1>b2)
fskdmod=1;
else
fskdmod=0;
end
fskout(i)=fskdmod;
if (d(i)~=fskout(i))
err(k)=err(k)+1;
end
end
d;
fskout;
err(k);
end
ber(k)=err(k)/(no_of_bits*M)
sn(k)
end
% plot
close all
figure
semilogy(sn,ber);
axis([3 26 10^-10 10^0]);
grid on;
xlabel('snr');
ylabel('Bit Error Rate');
title('Bit error probability curve for FSK modulation');
The plot I am getting after running the above program is as follows:
ber vs snr plot for fsk.JPG
Kindly help me in getting the correct plot.. The correct plot should be as snr increases, ber decreases....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top