triggered capture using preamble detection -凯发k8网页登录
this example shows how to use a software-defined-radio (sdr) to capture data from the air using preamble detection. the example also shows how to use the transmit capabilities of the same radio to loop back a test waveform.
introduction
the example demonstrates these steps.
generate a waveform containing a preamble.
configure the preamble detector to detect the preamble sequence.
use the
plotthreshold
function to calibrate a fixed or adaptive threshold and capture data.explore trigger offset.
set up radio
call the radioconfigurations
function. the function returns all available radio setup configurations that you saved using the radio setup wizard. for more information, see .
savedradioconfigurations = radioconfigurations;
to update the dropdown menu with your saved radio setup configuration names, click update. then select the radio to use with this example.
savedradioconfigurationnames = [string({savedradioconfigurations.name})];
radio = savedradioconfigurationnames(1);
generate transmission waveform
create a transmission waveform containing a zadoff-chu preamble sequence. to enable straightforward demonstration of the preamble detection workflow, concatenate zeros before and after the preamble.
generate a preamble sequence of length 137 by using 38th root of the zadoff-chu sequence and normalize. concatenate with zeros.
zcseq = zadoffchuseq(38,137); preamble = zcseq/norm(zcseq,2); prepadlen = 2501; postpadlen = 2500; headsignal = complex(zeros(prepadlen,1),zeros(prepadlen,1)); rearsignal = complex(zeros(postpadlen,1),zeros(postpadlen,1)); inputsignal = [headsignal; zcseq*0.75; rearsignal];
plot transmission waveform.
figure(); subplot(2,1,1); plot(real(inputsignal)); subtitle("real part"); xlabel("samples"); ylabel("amplitude"); title("waveform with preamble"); subplot(2,1,2); plot(imag(inputsignal),color='r'); subtitle("imaginary part"); xlabel("samples"); ylabel("amplitude");
configure preamble detector
create a preamble detector object with the specified radio. because the object requires exclusive access to radio hardware resources, before running this example for the first time, clear any other object associated with the specified radio. to speed up the execution time of the example in subsequent runs, reuse your new workspace object.
if ~exist("pd","var") pd = preambledetector(radio); end
set the rf properties of the preamble detector. set the radiogain
property according to the local wireless channel.
pd.samplerate = 30720000; pd.centerfrequency = 2450000000; pd.radiogain = 30; % increase if signal levels are low.
to update the dropdown menu with the antennas available for capture on your radio, call the hcaptureantennas
helper function. then select the antenna to use with this example.
captureantennaselection = hcaptureantennas(radio);
pd.antennas = captureantennaselection(1);
configure the preamble sequence for preamble detection.
pd.preamble = preamble;
set the capture data type to the data type of the generated transmission waveform.
pd.capturedatatype = "double";
configure transmission variables
set the transmit gain and transmit antenna values. set the transmit gain variable according to the local wireless channel.
txgain = 30; % increase if signal levels are low.
to update the dropdown menu with the antennas available for transmit on your radio, call the htransmitantennas
helper function. then select the antenna to use with this example.
transmitantennaselection = htransmitantennas(radio);
txantenna = transmitantennaselection(1);
detect preamble using fixed threshold and capture data
data capture is triggered when the correlator output is greater than the fixed threshold. by setting the fixed threshold to 0, you can analyze the behavior of the preamble detector and understand how to set the fixed threshold value for successful detection.
set the preamble detector to use fixed threshold. to set the threshold method, stop any ongoing transmission.
stoptransmission(pd);
pd.thresholdmethod = "fixed";
set the fixed threshold initially to 0.
pd.fixedthreshold = 0;
transmit the test waveform.
transmit(pd,inputsignal,"continuous",transmitgain=txgain, ... transmitcenterfrequency=pd.centerfrequency,transmitantennas=txantenna);
use the plotthreshold
function to analyze the behavior of the detector by plotting 10,000 samples. because the fixed threshold value is 0, all samples from the correlator output are possible trigger points. check the correlator output values at the peak trigger points. because the sampling phase determines the quality of the correlator peak, run the plotthreshold
function multiple times to see how the trigger points change.
plotthreshold(pd,10e3);
choose a threshold value that is below any of the trigger point values. plot the threshold information again and adjust the fixed threshold until the trigger points appear only on the correlator output peak. run the plotthreshold
function multiple times to see any sampling phase effects.
pd.fixedthreshold = 0.1;
plotthreshold(pd,10e3);
once the threshold is set, capture data.
[data, ~, ~, status] = capture(pd,10e3,seconds(1)); plotcaptureddata(data,status);
detect preamble using adaptive threshold and capture data
as an alternative to the fixed threshold, data capture can be triggered when the correlator output is greater than the adaptive threshold, which dynamically varies with the input signal power. by setting the adaptive threshold gain and offset to 0, you can analyze the behavior of the preamble detector and understand how to configure the adaptive threshold for successful detection.
set the preamble detector to use adaptive threshold. to set the threshold method, stop any ongoing transmission.
stoptransmission(pd);
pd.thresholdmethod = 'adaptive';
set the adaptive threshold gain and offset initially to 0.
pd.adaptivethresholdgain = 0; pd.adaptivethresholdoffset = 0;
transmit the test waveform.
transmit(pd,inputsignal,"continuous",transmitgain=txgain, ... transmitcenterfrequency=pd.centerfrequency,transmitantennas=txantenna);
use the plotthreshold
function to analyze the behavior of the detector by plotting 10,000 samples. check the correlator output values at the peak trigger points and run the plotthreshold
function multiple times if necessary.
plotthreshold(pd,10e3);
to remove all the trigger points from the bottom of the plot, set the adaptive threshold offset to a value that is above the noise floor. adjust the adaptive threshold gain and plot the threshold information repeatedly until the correlator output is greater than the adaptive threshold.
pd.adaptivethresholdoffset = 0.05; pd.adaptivethresholdgain = 0.25; plotthreshold(pd,10e3);
once the threshold is configured, capture data.
[data, ~, ~, status] = capture(pd,10e3,seconds(1)); plotcaptureddata(data,status);
set trigger offset to include preamble in captured data
to capture the preamble sequence, set the trigger offset to the length of the preamble. to set the trigger offset, stop any ongoing transmission.
stoptransmission(pd);
pd.triggeroffset = -137;
transmit the test waveform and capture data.
transmit(pd, inputsignal,"continuous",transmitgain=txgain,... transmitcenterfrequency=pd.centerfrequency,transmitantennas=txantenna); % detect and capture 10,000 samples, with a 1 second timeout [data, ~, ~, status] = capture(pd,10e3,seconds(1)); plotcaptureddata(data,status);
end transmission
to end the continuous transmission, call the stoptransmission
function on the preamble detector object.
stoptransmission(pd);
local functions
function plotcaptureddata(data,status) if status % if detection is successful, plot data figure(); subplot(2,1,1); plot(real(double(data))); title("real part of captured signal") xlabel("samples"); ylabel("amplitude"); subplot(2,1,2); plot(imag(double(data)),color='r'); title("imaginary part of captured signal") xlabel("samples"); ylabel("amplitude"); else disp("detection failed.") end end