help in matlab code of fsk

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 to write a matlab code for fsk transmitter. I have generated a binary data sequence. Converted those bits into frequencies of 10000 hz and 8000 Hz. if input bit=1 ten the signal will b a cosine wave having frequency 10000 Hz and if the input bit=0 ten the signal will b a cosine wave having frequency 8000 Hz. after this wat needs 2 b done 2 generate a fsk modulated signal.. following is my code.
clc;
clear all;
close all;
no_of_bits=10;
no_of_samples=20;
threshold=0.5;
Tb=1; % Bit duration
fc=3/Tb; % Carrier frequency
f1=10000;
f0=8000;
t = linspace(0, 1, no_of_samples);
t1=linspace(0, 1, no_of_samples);
t2=t1/fc;
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
freq1 = cos(2*pi*f1*t2)
else
freq0 = cos(2*pi*f0*t2)
end
end
 

Yes your logic looks correct, but I suppose there is a mistake..

You cannot just compare the ith element of "A" and draw the corresponding graph.
if d(j)==1
freq1 = cos(2*pi*f1*t2)
else
freq0 = cos(2*pi*f0*t2)
end

Do it like this:
1) Compare every single bits of "A" with the threshold.
2) Find if it is "Logic 1" or "Logic 0"
3)Define a matrix which will store the corresponding output
Something Like this.
If A(i)<= threshold
A(i)=1;
wave[] = [wave cos(2*pi*f1*t2)]
else
A(i)=0;
wave[] = [wave cos(2*pi*f0*t2)]
end
4) Then just plot the matrix"Wave".

Try it...
 

Hello,
I have written a matlab code for fsk modulation and demodulation scheme in matlab.... kindly check my code n tell me where did i go wrong. I have generated a binary data sequence. Converted those bits into frequencies of 10000 hz and 8000 Hz i.e if input bit=1 ten the signal will b a cosine wave having frequency 10000 Hz and if the input bit=0 ten the signal will b a cosine wave having frequency 8000 Hz. Ten i have generated fsk modulated signal by adding above two signals. ten i have added noise. ten i multiply dis signal wid 2 corelators i.e. cosine wave having freq 10000 and cosine wave having freq 8000. Ten i integrate these two signals. I subract the two signal outputs after integrating. if d subtraction result is 0 ten i choose 0 and if d subtraction result is 1 ten i choose 1 n thus i get fsk demodulated signal. My code is as follows:

clc;
close all;
clear all;
no_of_bits=10;
threshold=0.5;
snr=-3;
Tb = 1; % Bit duration
fc = 3/Tb; % Carrier frequency
t=0.001;
Noise_Variance=0.5;
f0=8000;
f1=10000;
freq1=cos(2*pi*f0*t);
freq2=cos(2*pi*f1*t);
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
fa=freq1;
else
fb=freq2;
end
end
fskmod=fa+fb; % Modulated waveform
%Noise addition
noise = sqrt(Noise_Variance)*randn(1,length(fskmod));
received = fskmod + noise;
% Multipying the received signal with carrier waveform
v1 = received.*freq1;
y1=v1;
z1=trapz(y1);
if z1<0
z1=0;
else
z1=1;
end
fsk1(i)=z1
v2=received.*freq2;
y2=v2;
z2=trapz(y2);
if z2<0
z2=0;
else
z2=1;
end
fsk2(i)=z2
y=(fsk2(i)-fsk1(i))
if (y<0)
y=0;
else
y=1;
end
fsk(i)=y;
fskout(i)=fsk(i);
end
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…