# Hi currently im doing a mod and demod of FSK signals and i have to add AWGN into it but cant figure it out can someone help and identify the error, currently im using the code below:

3 views (last 30 days)
Shaun Tay on 16 Oct 2020
Answered: Chaitanya Mallela on 19 Oct 2020
x=[1 0 0 1 1 0 1]; binary information
bsp=0.000001; bit period
disp(‘Binary information at Transmitter:’);
disp(x);
%Noise
SNR = 0:4:40;
Noise_Power = 1./(10.^(SNR./10));
K_rice = 5;
num_bits = 5000000;
%Representation of transmitting binary information as digital signal
bit=[];
For n=1:1 length(x)
If x(n)==1;
se=ones(1,100);
Else x( n)==0;
se=zeros(1,100);
End
bit=[bit se];
End
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(3,1,1);
plot(t1, bit, ‘lineWidth’, 2.5); grid on
axis([0 bp*length(x)-.5 1.5]);
ylabel(‘Amplitude(volt)’);
xlabel(‘Time(sec)’)
title(‘Transmitting information as digital signal’);
%Binary-FSK modulation
A=5; amplitude of carrier signal
br=1/bp; bit rate
f1=br*8; carrier frequency for info as 1
f2=br*2; carrier frequency for info as 0
t2=bp/99:bp99:bp;
ss=length(t2);
m=[];
For (i=1:1:length(x)
if(x(i)==1);
y=A*cos(2*pi*f1*t2);
Else
u=A*cos(2*pi*f2*t2);
end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
z=awgn(t3,m); ,- this is the part i am not so sure about
plot(z,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary FSK modulation corresponding binary information');
%XXXXXXXXXXXXXXXXXXXX Binary FSK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t); % carrier signal for information 1
y2=cos(2*pi*f2*t); % carrier signal for information 0
mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm) % integration
z2=trapz(t4,mmm) % integration
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2) % logic lavel= (0+A)/2 or (A+0)/2 or 2.5 ( in this case)
a=1;
else(zz2>A/2)
a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver :');
disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after demodulation XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bit=[];
for n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit se];
end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary FSK demodulation');
%
Sorry if the error is stupid as im still a beginner to matlab,
furthermore could someoen explain the following:
t3=bp/99:bp/99:bp*length(x); what does this line do?

#### 1 Comment

Shaun Tay on 16 Oct 2020
or is there a more efficient way to compute my code for modulation and demodulation of FSK systems. thank you in advanced!

Chaitanya Mallela on 19 Oct 2020
awgn function considers input vector signal, Signal to Noise Ratio (SNR) and Signal power as a general valid attributes.
Refer the documentation https://www.mathworks.com/help/comm/ref/awgn.html for more insights on using awgn function.
t3=bp/99:bp/99:bp*length(x);
This line generates a vector with start value bp/99 and end value bp*length(x) incrementing at bp/99.