loopback transmit and capture -凯发k8网页登录
this example shows how to configure a software-defined radio (sdr) as a baseband transceiver to transmit and capture a custom wireless waveform over the air.
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);
specify wireless waveform
use the attached testtone.mat
file to specify the transmit waveform. the wavestruct
structure contains a complex sine tone that is generated by using the wireless waveform generator app.
load("testtone.mat")
configure baseband transceiver
create a baseband transceiver 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. in subsequent runs, to speed up the execution time of the example, reuse your new workspace object.
if ~exist("bbtrx","var") bbtrx = basebandtransceiver(radio); end
configure the baseband transceiver object using the parameters of the wireless waveform.
set the
samplerate
property to the sample rate of the generated waveform.set the
centerfrequency
property to a value in the frequency spectrum indicating the position of the waveform transmission.
bbtrx.samplerate = wavestruct.fs; bbtrx.transmitcenterfrequency = 2.4e9; bbtrx.capturecenterfrequency = bbtrx.transmitcenterfrequency;
set the transmitradiogain
and captureradiogain
properties according to the local wireless channel.
bbtrx.transmitradiogain = 10; bbtrx.captureradiogain = 10;
to update the dropdown menus with the antennas available for your radio, call the htransmitantennas
and
hcaptureantennas
helper functions. then select the antennas to use with this example.
transmitantennaselection = htransmitantennas(radio); captureantennaselection = hcaptureantennas(radio); bbtrx.transmitantennas = transmitantennaselection(1); bbtrx.captureantennas = captureantennaselection(1);
transmit wireless waveform
call the transmit
function on the baseband transceiver object. specify a continuous transmission.
transmit(bbtrx,wavestruct.waveform,"continuous");
capture iq data
to capture the transmitted waveform, call the capture
function on the baseband receiver object. specify the length of the capture.
pause(1)
capturelength = milliseconds(10);
data = capture(bbtrx,capturelength);
end transmission
to end the continuous transmission, call the stoptransmission
function on the baseband transceiver object.
stoptransmission(bbtrx);
plot spectrum of captured waveform
create a spectrumanalyzer
object. to speed up the execution time of this example upon subsequent runs, reuse the spectrum analyzer object. set the sample rate of the spectrum analyzer object to the sample rate of the baseband transceiver object. plot the spectrum and spectrogram of the captured data.
if ~exist("spectrumscope","var") spectrumscope = spectrumanalyzer; end spectrumscope.samplerate = bbtrx.samplerate; spectrumscope.channelnames = bbtrx.captureantennas; spectrumscope.frequencyoffset = bbtrx.capturecenterfrequency; spectrumscope.spectrumunits = "dbfs"; spectrumscope.fullscalesource = "property"; spectrumscope.fullscale = double(intmax('int16')); spectrumscope(data); spectrumscope.show; release(spectrumscope);
to transmit and capture the waveform again and to update the spectrum analyzer by rerunning the current section, click capture and plot frequency spectrum.