-
Notifications
You must be signed in to change notification settings - Fork 2
/
bb2transmitter.m
109 lines (86 loc) · 2.58 KB
/
bb2transmitter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
% Bipolar, Baseband PAM transmitter
%
% ESE 471, Spring 2021
% Author: Neal Patwari
% License: see LICENSE.md
%
% Possible modes:
% 1: 'test' mode which allows you to show what would be tranmitted
% for a fake data bit list
% 2: 'instructor', what I use to generate the received signal
% 3: 'assignment', what you use to build a receiver to work with the
% given saved received signal.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Signal Generation
% INPUT: none
% OUTPUT: binary data
temp = 'ESE 471';
data = text2bits(temp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modulation
% INPUT: data
% OUPUT: modulated values, x
inputVec = [0 1];
outputVec = [-1 1];
x = lut(data, inputVec, outputVec);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Upsample
% INPUT: modulated values, x
% OUTPUT: modulated values at sampling rate, x_s
x_s = oversample(x,16);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pulse-shape filter
% INPUT: modulated values at sampling rate, x_s
% OUTPUT: baseband transmit signal s
pulse = sqrt(1/16).*ones(1,16);
s = conv(x_s, pulse);
% Plot for project handout
figure(1)
h = plot(s, '-o');
set(gca,'FontSize',20);
set(gca,'ylim',[-0.5 0.5]);
set(h,'LineWidth',2);
xlabel('Sample')
ylabel('Value')
grid
% Load s if doing the receiver assignment from a saved mat file
% load bb2.mat
% Bipolar, baseband PAM receiver
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matched filter
% INPUT: baseband transmitted signal s
% OUTPUT: matched-filtered signal y
y = filter(pulse, 1, s);
% Plot for project handout
figure(2)
h = plot(y, '-o');
set(gca,'FontSize',20)
set(h,'LineWidth',2);
xlabel('Sample')
ylabel('Value')
grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Time Synch
% Input: Matched Filter output
% OUTPUT: Synched MF output with samples at US_Rate, 2*US_Rate, ...
y_s = y(16:end);
% Plot eye-diagram
figure(3)
h = plot_eye_diagram(y_s, 16, 0);
set(gca,'ylim',[-1.1, 1.1]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Downsample
% INPUT: Synched matched filter output
% OUTPUT: Symbol Samples (at n*T_s)
US_Rate = 16;
r_hat = y_s(US_Rate: US_Rate: end);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bit decisions
% INPUT: Symbol Samples
% OUTPUT: Bits
data_out = double(r_hat > 0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Translate to ascii text
% INPUT: Bits
% OUTPUT: Character vector, message_out
message_out = binvector2str(data_out)