AFG3151C transfer Pseudo Random Binary Sequence(PRBS) waveform(Square wave) using Matlab

Post Reply
Chihiro
Posts: 2
Joined: January 20th, 2017, 12:40 am
Country: Taiwan

AFG3151C transfer Pseudo Random Binary Sequence(PRBS) waveform(Square wave) using Matlab

Post by Chihiro » January 20th, 2017, 2:13 am

Hello,

I want to transfer a Pseudo Random Binary Sequence(PRBS) waveform(square wave) into arbitray memory of the tektronix signal generator using Matlab commands.

I know that the command is:

Code: Select all

DATA:DATA EMEMory,#42000<DAB><DAB>...<DAB>
But I don't know how to write <DAB>,

So I have reference to the open-source network to rewrite their own programs,

My code(Matlab):

Code: Select all

visaAddress = 'USB::0x0699::0x0355::C010145::INSTR';
myFgen = visa('tek', visaAddress);
myFgen.OutputBufferSize = 51200; 
myFgen.ByteOrder = 'littleEndian';
fopen(myFgen);
f1 = 1e3;
f2 = 4e3;
freqMax = max(f1, f2);
sampleRate = 80*freqMax; 
timeVec = 0:1/sampleRate:10/f1;
timeVec = timeVec(1:end-1);

x=1:10;
x1=[x;x(2:end),x(end)+1];
x2=x1(:);
y=[1 0 1 0 1 0 1 0 1 0]; %PRBS
y1=[y;y];
y2=y1(:);
waveform = x2,y2
timeVec = timeVec(1:end-1);

% Convert the double values integer values between 0 and 16382 (as required
% by the instrument)
waveform =  round((waveform + 1.0)*8191);
waveformLength = length(waveform);
% Encode variable 'waveform' into binary waveform data for AFG.  This is the
% same as AWG5000B but marker bits are ignored. Refer to AWG5000B series
% programmer manual for bit definitions.
%binblock = zeros(2 * waveformLength, 1);
%binblock(2:2:end) = bitand(waveform, 255);
%binblock(1:2:end) = bitshift(waveform, -8);
%binblock = binblock';
% Build binary block header
bytes = num2str(length(binblock));
header = ['#' num2str(length(bytes)) bytes];
%fprintf(myFgen, ['DATA:DEF EMEM, ' 10 ';']); % Resets the contents of edit memory and define the length of signal
fwrite(myFgen, [':TRACE EMEM, ' header binblock  ';'], 'uint8');% Transfer the custom waveform from MATLAB to edit memory of instrument
fprintf(myFgen, 'SOUR1:FUNC EMEM'); % Associate the waveform in edit memory to channel 1
% Set the output frequency to 1 Hz. This is important since the custom
% waveform's frequency is further upconverted to the value set below.
fprintf(myFgen, 'SOUR1:FREQ:FIXed 1Hz');
fprintf(myFgen, ':OUTP1 ON'); % Turn on Channel 1 output
fclose(myFgen);
clear myFgen;
But this still did not solve my problem,

Does anyone have any idea?
Thanks.
Last edited by Carl M on January 24th, 2017, 4:01 pm, edited 1 time in total.
Reason: code tags

David N
Tektronix Applications
Tektronix Applications
Posts: 416
Joined: July 31st, 2008, 8:26 am

Re: AFG3151C transfer Pseudo Random Binary Sequence(PRBS) waveform(Square wave) using Matlab

Post by David N » January 20th, 2017, 10:41 am

You can find the data format listed in the AWG5000 Series programmers manual on page 2.23. See excerpt below from the AWG5000 manual. Just disregard the marker data as that is not used in the AFG3000 series.
Attachments
AWG5000 Programmers Manual Excerpt.PNG
AWG5000 Programmers Manual Excerpt.PNG (70.99 KiB) Viewed 4689 times

Chihiro
Posts: 2
Joined: January 20th, 2017, 12:40 am
Country: Taiwan

Re: AFG3151C transfer Pseudo Random Binary Sequence(PRBS) waveform(Square wave) using Matlab

Post by Chihiro » January 22nd, 2017, 3:44 am

David N wrote:You can find the data format listed in the AWG5000 Series programmers manual on page 2.23. See excerpt below from the AWG5000 manual. Just disregard the marker data as that is not used in the AFG3000 series.

Hello David N:

I had a reference to the AWG 5000 programmers datasheet yesterday,

Also tried all day,

But my AWG3000 square wave signal is still wrong (I have also consulted the AWG3000 programmer data sheet),

I have a 4096 bit digital information (ex:010100101 ..... 01),

I want this 4096-bit digital information into a square wave,

And allow the AWG3000 to generate these square waves,

The following is a 250bit Matlab code:

clc;
clear;
x=1:250;
x1=[x;x(2:end),x(end)+1];
x2=x1(:);
%The following is a 250bit digital information
y=[0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1];
y1=[y;y];
y2=y1(:);
plot(x2,y2);
axis([1,250,0,2]);

But I don't know how the AWG3000 generates these square waves,

Can you provide some suggestions or source code reference?

I'm sorry to have wasted your valuable time,

Thank you for reading my problem description.

Carl M
Tektronix Applications
Tektronix Applications
Posts: 775
Joined: July 30th, 2008, 4:45 pm

Re: AFG3151C transfer Pseudo Random Binary Sequence(PRBS) waveform(Square wave) using Matlab

Post by Carl M » January 24th, 2017, 5:53 pm

The data following the binary block header is unsigned 16-bit integer values, most significant byte first (big-endian). Bits 15 and 16 are ignored as the AFG has 14-bits of dynamic range. The key concept is the digital values are unit-less. Value 0 is the minimum output and value 16382 is the maximum output. Amplitude (and offset, and timing) are applied at run-time based on the AFG settings.

For a bit stream application, if you are only using one sample per bit, you could simply multiply your bit vector by 16382.

MATLAB vectors default to double precision floating point. You'll need to convert it to uint16.

MATLAB also defaults to little-endian. You can use swapbytes to change between big and little endianness but I'm not sure how to tell MATLAB a specific variable is big-endian. When you interpret big-endian data as little-endian, you get incorrect values.

Furthermore, fwrite with an instrument object will cast to uint8 by default. You cannot just switch to uint16 because you still need uint8 for the ASCII command bytes. You can use typecast to convert a uint16 vector of length N to a uint8 vector of length N*2. With the uint8 representation of your vector, you can then append it to the command and write it to the instrument.

As a side-note, I prefer NI VISA. With IO Trace, you can see the binary byte values and order being written to the instrument. This is helpful for debugging binary type formatting.
afg2k_trace_data.png
afg2k_trace_data.png (10.55 KiB) Viewed 4391 times
Tektronix Application Engineer

Post Reply

Return to “AFG1000/2000/3000 series”

Who is online

Users browsing this forum: No registered users and 1 guest