-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfindTxFrequency.m
63 lines (50 loc) · 1.77 KB
/
findTxFrequency.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
function txFrequency = findTxFrequency()
% Setup:
%
% Place the HB100 in front of the Phaser - 0 degree azimuth.
%
% Notes:
%
% The frequency of the phaser is swept between 10 and 10.5 GHz. The peak
% frequency is measured. This is assumed to be the frequency of the HB100.
%
% Copyright 2023 The MathWorks, Inc.
% Setup the frequencies to scan.
f_start = 10.e9;
f_stop = 10.5e9;
f_step = 5e6;
fvec = f_start : f_step : f_stop;
% Setup the antenna, setting the frequency to f_start.
[rx,bf,~,tx,bf_TDD] = setupAntenna(f_start);
% Setup variables for capturing scan amplitude and frequency.
full_ampl = [];
full_freqs = [];
N = rx.SamplesPerFrame;
% Loop through the frequency vector and save receive data at each center
% frequency.
for centerfrequency = fvec
% The LO is set to 4x the Frequency setting.
bf.Frequency = (centerfrequency + rx.CenterFrequency)/4;
rx();
% Capture the data, sum the channels, and convert to the frequency domain
data = rx();
data = sum(data,2);
famplitude = mag2db(1/N * fftshift(abs(fft(data))));
full_ampl = [full_ampl, famplitude];
% Get the frequency span for this data sample
df = rx.SamplingRate/N;
band = (-rx.SamplingRate/2 : df : rx.SamplingRate/2 - df);
freqspan = centerfrequency-band;
full_freqs = [full_freqs, freqspan'];
end
% Get the max amplitude for each measurement
[maxamplitudes,maxidxs] = max(full_ampl);
% Get the max amplitude in the whole dataset
[~,maxframeidx] = max(maxamplitudes);
maxdatapointidx = maxidxs(maxframeidx);
txFrequency = full_freqs(maxdatapointidx,maxframeidx);
ax = axes(figure);
plot(ax,full_freqs/1e9,full_ampl); xlabel('Frequency (GHz)'); ylabel('Amplitude (dB)');
title(ax,['HB100 Frequency = ' num2str(txFrequency/1e9) 'GHz']);
cleanupAntenna(rx,tx,bf,bf_TDD);
end