Code covered by the BSD License  

Highlights from
Measure radio frequency power using MATLAB and an RF power meter

image thumbnail

Measure radio frequency power using MATLAB and an RF power meter


Vinod Cherian


MATLAB example to make RF Power measurements using an Agilent RF Power Meter

function [channelCPower, channelDPower] = readPowerMeter()
% This function connects to an Agilent N1914A RF power meter and measures 
% the average power on channel C and channel D and returns the values to the caller
% Parameters for the measurement are defined in the function and will need
% to be modified according to your instrument setup and measurement needs.
% Syntax: [channelCPower,channelDPower] = readPowermeter();

% VC: 04-21-10
% Copyright 1999-2010 The MathWorks, Inc.

%% Define the system parameters. 
addressPowerMeter = '';  % IP address to the signal analyzer
channelCOffset = 49.1;                 % Channel C Offset in dB
channelDOffset = 54.2;                 % Channel D Offset in dB
centerFrequency = 2.14e9;              % Center frequency in Hz

%% Set up some instrument connectivity options and connect to the insturment
powerMeterObject=tcpip(addressPowerMeter, 5025);
% set up a large input buffer so we have enough place to hold data
% Set the instrument timeout
% Connect to signalAnalyzerObject

%% Setting up the instrument for measurement
% Reset the instrument to known state
fprintf(powerMeterObject, '*RST');
% pause for a second while the instrument resets
% get intrument identification to make sure we are speaking with the N1914A
instrumentInfo = query(powerMeterObject, '*IDN?');
% Set the endianness of returned data
fprintf(powerMeterObject,':FORMat:BORDer NORMal');
% Set the format of the returned data
fprintf(powerMeterObject,':FORMat:DATA ASCII');
% Set up the instrument for measurement and make channel C and channel D readings
fprintf(powerMeterObject,'SENSE:AVERage:COUNt 3');
% Power measurement units are DBM
fprintf(powerMeterObject,'UNIT3:POW DBM');
fprintf(powerMeterObject,'UNIT4:POW DBM');
% Turn averaging off
fprintf(powerMeterObject,'SENSe3:AVERage:STATe OFF');
fprintf(powerMeterObject,'SENSe4:AVERage:STATe OFF');
% Auto ranging on
fprintf(powerMeterObject,'SENSe3:POWer:AC:RANGe:AUTO ON');
fprintf(powerMeterObject,'SENSe4:POWer:AC:RANGe:AUTO ON');
% set the frequency
fprintf(powerMeterObject,['SENSe3:FREQuency ' num2str(centerFrequency)]);
fprintf(powerMeterObject,['SENSe4:FREQuency ' num2str(centerFrequency)]);
% set the offsets
fprintf(powerMeterObject,['SENSe3:CORRection:GAIN2 ' num2str(channelCOffset)]);
fprintf(powerMeterObject,['SENSe4:CORRection:GAIN2 ' num2str(channelDOffset)]);
% Turn off continuous measurement and set to immediate measurement
fprintf(powerMeterObject,'INITiate:CONTinuous OFF');
fprintf(powerMeterObject,'TRIGger:SOURce IMMediate');
% Set up the display for channel C and channel D data
fprintf(powerMeterObject,'DISP:WIND1:FORM SNUMeric')
fprintf(powerMeterObject,'DISP:WIND2:FORM SNUMeric')
% read back the power on Channel C and Channel D
numReadings = 20;
power3 = zeros(1,numReadings);
power4 = zeros(1,numReadings);
for iLoop = 1:numReadings
    power3(1,iLoop) = str2double(query(powerMeterObject,'READ3:POW:AC?'));
    power4(1,iLoop) = str2double(query(powerMeterObject,'READ4:POW:AC?'));
channelCPower = mean(power3);
channelDPower = mean(power4);
% Set system to local mode

%% Clean up
% Close and delete instrument connections
fclose(powerMeterObject); delete(powerMeterObject); clear powerMeterObject;

Contact us