MATLAB is a software environment and programming language with over 1,000,000 users and is used to generate arbitrary and standard waveforms, configure and control instruments, build automated test applications, and analyze and visualize data from other instruments. MATLAB only supports instrument communication when you use MATLAB with its Instrument Control Toolbox™.
This example uses MATLAB to generate an arbitrary waveform (IQ data), configure the instrument, download the waveform to the Agilent source, and instruct the instrument when to source the waveform.
To execute this example, type ‘Generate_Waveform_Agilent’ in the MATLAB command window. [Note: Change the IP address in the generate_agilent_waveform.m file to the IP address of the signal source.]
This MATLAB example has been tested on an N5182A MXG but should work on other Agilent signal sources including these MXG, ESG, and PSG models: E4428C,E4438C,N5181A,N5182A,N5183A,E8241A,E8244A,E8251A,E8254A,E8247C,E8257C, E8267C,E8257D,E8267D,E8663B,N8211A,N8212A.
To learn more about using MATLAB and Instrument Control Toolbox™ for configuring and controlling instruments, visit:
To request a trial of MATLAB and/or Instrument Control Toolbox, visit http://www.mathworks.com/agilent/instrument/tryit.html
For additional information on using MATLAB with Agilent instruments, including MATLAB examples, demos, drivers, and videos, visit:
when i am running your code this error happen
Error using icinterface/fopen (line 83)
Unsuccessful open: Connection timed out: connect
Error in Generate_Waveform_Agilent (line 36)
what i doing fore solving this error
It is worth noting that the module relies upon the Instrument Control Toolbox.
Nikola, I think it is a little awkward to call twos complement "signed" since it's just a binary representation. However, I believe what they mean is that the Agilent components represent signed data as twos complement. I do not think they're implying that you make twos complement and then awkwardly add a sign bit to the data (not sure how this would be done anyway). I do agree with you that there is an error in the code you indicated.
I believe the intent of the code is to write out unsigned 16-bit integer values, that, when interpreted by the Agilent component as twos complement, will result in the correct values signed values.
Before I discuss issues with the codes implementation of this methodology, I would first question why I wouldn't just scale the data and convert to 'int16' and then write out the signed data using binblockwrite. I expect the binary data would be written out as twos complement and I'd be done. After all the binary representation of 'int16' is the same as data converted to twos complement and cast to 'uint16'.
The conversion from signed to unsigned twos complement, I believe, is making all the data negative, if my assumptions on interpretation on the Agilent component is correct.
The last two lines of this snippet are problematic:
scale = 2^15-1;
scale = scale/tmp;
wave = round(wave * scale);
modval = 2^16;
wave = uint16(mod(modval + wave, modval));
First, the data is scaled to the range [-2^15+1, 2^15-1]. Then the last line moves the range to [(mod(2^16-2^15+1, 2^16), mod(2^16+2^15-1, 2^16)] = [2^15-1, 2^16-1]. If you interpret this range as 16-bit twos complement, I believe all the numbers end up as negative numbers.
Now, the addition of 2^16 is the typical operation for converting a positive twos complement value to it's negative complement (and vice versa) so I can understand how the author ended up doing this. However, I think it should only be done to data that is negative.
Replacing the last line with the following two lines should give the desired result:
wave(wave<0) = modval + wave(wave<0);
wave = uint16(wave)
The modulus operation is no longer necessary.
Great script. It works for me. One question: how do I compute the I/Q base band signal sample rate? Say I need to send a 1Mhz tone and filter it before sending it to the RF?
does agilent waveform download asisstant do the same work?
Great work on connect MATLAB and Agilent instruments.
First of all thanks for the script, secondly I tried the code on Agilent N5182A but unfortunately the N5182A display an error i.e. "ERROR_ -275, File name error"
Waiting for a kind response...
MATLAB_WFM is it a file?
Thank you for this script. It is very useful except a bug that should be corrected.
I have formatted/scaled waveform by using this script. I was successful to download it to Agilent Signal generator PSG E8267D.
Unfortunately, the PSG output signal (with ARB waveform modulation) was not as suppose to be. I expected to see burst spread spectrum signal but I've got flat signal with a few dB variations.
After a few hours investigation of the problem I found that the cause is the use of Two's complement formatting in the Matlab code.
wave = uint16(mod(modval + wave, modval));
I've got the correct PSG's output signal without 2's complement formatting.
If you go to the Agilent PSG programming guide (E8251-90255) you can see the following sentence "...Data must be in signed, 2’s complement (binary) format..." (very interesting combination, isn't it?)
There is no use of 2's complement formatting in the attached examples script in C/C++.
I have tried this program in an Agilent Signal Generator E8267D.
However, the instrument displays an error message -275 wrong file name after the line 59:
binblockwrite(deviceObject,wave,'uint16',[':MEM:DATA "WFM1:' ArbFileName '",']);
Change in copyright.
Update to include VISA and basic interface functionality in example.
Create scripts with code, output, and formatted text in a single executable document.