-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx2.m
72 lines (49 loc) · 1.71 KB
/
tx2.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
function [tx, bits, gain] = tx2()
% Example Transmitter. Outputs modulated data tx, and original data stream
% data for checking error rate at receiver.
% Your team will be assigned a number, rename your function txNUM.m
% Also rename the global variable tofeedbackNUM
% Global variable for feedback
% you may use the following uint8 for whatever feedback purposes you want
global feedback2;
uint8(feedback2);
% DO NOT TOUCH BELOW
fsep = 8e4;
nsamp = 16;
Fs = 120e4;
M = 16; % THIS IS THE M-ARY # for the FSK MOD. You have 16 channels available
% THE ABOVE CODE IS PURE EVIL
% initialize, will be set by rx after 1st transmission
if isempty(feedback2)
feedback2 = randi(15);
end
%% You should edit the code starting here
% Tone to transmit the data on
tonecoeff = double(feedback2);
msgM = 16; % Select 4 QAM for my message signal
k = log2(msgM);
% You may use as many BITS as you wish, but must transmit exactly 1024
% SYMBOLS
bits = randi([0 1],1024*k,1); % Generate random bits, pass these out of function, unchanged
%bits = ones(1024*k,1);
syms = bi2de(reshape(bits,k,length(bits)/k).','left-msb')';
% Random 4-QAM Signal
msg = qammod(syms,msgM);
msglength = length(msg);
if(msglength ~= 1024)
error('You smurfed up')
end
%% You should stop editing code starting here
%% Serioulsy, Stop.
% Generate a carrier
% don't mess with this code either, just pick a tonecoeff above from 0-15.
carrier = fskmod(tonecoeff*ones(1,msglength),M,fsep,nsamp,Fs);
%size(carrier); % Should always equal 16484
% upsample the msg to be the same length as the carrier
msgUp = rectpulse(msg,nsamp);
% multiply upsample message by carrier to get transmitted signal
tx = msgUp.*carrier;
% scale the output
gain = std(tx);
tx = tx./gain;
end