1% fsk_basic.m
2% David Rowe 30 sep 2016
3%
4% Basic non-coherent FSK modem simulation to illustrate principles
5% and compare to ideal
6
7rand('seed',1);
8randn('seed',1);
9
10Fs = 9600;     % sample rate
11f1 = 1200;
12f2 = 2400;
13Rs = 1200;     % symbol rate
14Ts = Fs/Rs;    % length of each symbol in samples
15Nbits = 10000;
16EbNodB = 9;
17
18tx_bits = round(rand(1,Nbits));
19
20% continuous phase FSK modulator
21
22w1 = 2*pi*f1/Fs;
23w2 = 2*pi*f2/Fs;
24tx_phase = 0;
25tx = zeros(1,Ts*Nbits);
26
27for i=1:Nbits
28  for k=1:Ts
29    if tx_bits(i)
30      tx_phase += w2;
31    else
32      tx_phase += w1;
33    end
34    tx((i-1)*Ts+k) = exp(j*tx_phase);
35  end
36end
37
38% AWGN channel noise
39
40EbNo = 10^(EbNodB/10);
41variance = Fs/(Rs*EbNo);
42noise = sqrt(variance/2)*(randn(1,Nbits*Ts) + j*randn(1,Nbits*Ts));
43rx = tx + noise;
44
45% integrate and dump demodulator
46
47rx_bits = zeros(1,Nbits);
48for i=1:Nbits
49  arx_symb = rx((i-1)*Ts + (1:Ts));
50  filt1 = sum(exp(-j*w1*(1:Ts)) .* arx_symb);
51  filt2 = sum(exp(-j*w2*(1:Ts)) .* arx_symb);
52  rx_bits(i) = filt2 > filt1;
53end
54
55Nerrors = sum(xor(tx_bits, rx_bits));
56ber = Nerrors/Nbits;
57printf("EbNodB: %4.1f  Nerrors: %d BER: %1.3f\n", EbNodB, Nerrors, ber);
58
59
60
61