# Examples for MATLAB

# Arbitrary Waveform Generator

# arbitrary_waveform_generator_basic.m

%% Arbitrary Waveform Generator Example 
%
%  This example demonstrates how you can configure the Arbitrary Waveform 
%  Generator instrument to generate two signals. 
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%
% 
%% Prepare the waveforms
% Prepare the square waveform to be generated
t = linspace(0,1,100);
square_wave = sign(sin(2*pi*t));

% Prepare a more interesting waveform to be generated (note that the points
% must be normalized to range [-1,1])
not_square_wave = zeros(1,length(t));
for h=1:2:15
    not_square_wave = not_square_wave + (4/pi*h)*cos(2*pi*h*t);
end
not_square_wave = not_square_wave / max(not_square_wave);

%% Connect to your Moku
% Connect to your Moku by its IP address.
   
i = MokuArbitraryWaveformGenerator('192.168.###.###');

try
 
    % Configure the output waveform in each channel
    % Channel 1: sampling rate of 125 MSa/s, square wave, 1MHz, 2Vpp.
    i.generate_waveform(1, "625Ms", square_wave, 1e6, 2);
    % Channel 2: automatic sampling rate, use the "not_square_wave" LUT, 10
    % kHz, 1Vpp.
    i.generate_waveform(2, "Auto", not_square_wave, 10e3, 1,...
        'interpolation', true);
    
    %% Set channel 1 to pulse mode 
    % 2 dead cycles at 0Vpp
    i.pulse_modulate(1,'dead_cycles',2,'dead_voltage',0);

    %% Set Channel 2 to burst mode
    % Burst mode triggering from Input 1 at 0.1 V
    % 3 cycles of the waveform will be generated every time it is triggered
    i.burst_modulate(2, "Input1", "NCycle",'burst_cycles',3,'trigger_level',0.1);

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME);
end

i.relinquish_ownership();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

# Data Logger

# datalogger_basic.m

%% Basic Datalogger Example
%
%  This example demonstrates how you can configure the Datalogger instrument.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku and deploy the oscilloscope instrument
i = MokuDatalogger('192.168.###.###');

try

    % Enable precision mode
    i.set_acquisition_mode('mode','Precision');
    
    % Set the sample rate to 1 kSa/s
    i.set_samplerate(1e3);
    
    % Generate a sine wave on Channel 1
    % 1Vpp, 10kHz, 0V offset
    i.generate_waveform(1, 'Sine', 'amplitude',1, 'frequency',10e3);
    % Generate a square wave on Channel 2
    % 1Vpp, 10kHz, 0V offset, 50% duty cycle
    i.generate_waveform(2, 'Square', 'amplitude',1, 'frequency', 1e3, 'duty', 50);
    
    % Start the data logging session of 10 second and store the file on the RAM
    logging_request = i.start_logging('duration',10);
    log_file = logging_request.file_name;
    
    % Set up to display the logging process
    progress = i.logging_progress();
    
    while progress.complete < 1
        fprintf('%d seconds remaining \n',progress.time_remaining)
        pause(1);
        progress = i.logging_progress();
    end
    
    % Download the log file from the Moku to "Users" folder
    % Moku:Go should be downloaded from "persist" and Moku:Pro from "ssd"
    i.download_file('persist',log_file,['C:\Users\' log_file]);

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

% End the current connection session with your Moku
i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

# Data Streaming

# datalogger_streaming.m

%% Datalogger streaming Example
%
%  This example demonstrates how you can configure the Datalogger instrument,
%  and view triggered time-voltage data stream in real-time.
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address.
i = MokuDatalogger('192.168.###.###');

try

    % Generate a sine wave on Output 1
    % 0.5Vpp, 10kHz, 0V offset
    i.generate_waveform(1, 'Sine', 'amplitude', 0.5, 'frequency', 10e3);

    % Generate a square wave on Output 2
    % 1Vpp, 20kHz, 0V offset, 50% duty cycle
    i.generate_waveform(2, 'Square', 'amplitude', 1, 'frequency', 20e3, 'duty', 50);
    
    i.start_streaming('duration', 30);

  
    %% Set up plots
    % Get initial data to set up plots
    data = i.get_stream_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (sec)')
    ylabel(gca,'Amplitude (V)')
    
    %% Receive and plot new data frames
    while 1
        data = i.get_stream_data();
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end

catch ME
    i.stop_streaming();
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

# lock_in_amplifier_streaming.m

%% Plotting Lock-in Amplifier Example
%
%  This example demonstrates how you can configure the Lock-in Amplifier
%  instrument to demodulate an input signal from Input 1 with the reference
%  signal from the Local Oscillator to extract the X component and generate
%  a sine wave on the auxiliary output
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address and deploy the Lock-in Amplifier 
% instrument.
i = MokuLockInAmp('192.168.###.###');

try
    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 1 MOhm impedance, and 400 mVpp range
    i.set_frontend(1, 'DC', '1MOhm','0dB');
    % Channel 2 DC coupled, 1 MOhm impedance, and 4 Vpp range
    i.set_frontend(2, 'DC', '1MOhm','0dB');
    
    % Configure the demodulation signal to Local oscillator with 1 MHz and
    % 0 degrees phase shift
    i.set_demodulation('Internal','frequency',1e6,'phase',0);
    
    % Set low pass filter to 1 kHz corner frequency with 6 dB/octave slope
    i.set_filter(1e3,'slope','Slope6dB');
    
    % Configure output signals
    % X component to Output 1 
    % Aux oscillator signal to Output 2 at 1 MHz 500 mVpp
    i.set_outputs('X','Aux');
    i.set_aux_output(1e6,0.5);
    
    %% Set up signal monitoring
    % Configure monitor points to Input 1 and main output
    i.set_monitor(1,'Input1');
    i.set_monitor(2,'MainOutput');
    
    % Configure the trigger conditions
    % Trigger on Probe A, rising edge, 0V
    i.set_trigger('type','Edge', 'source','ProbeA', 'level',0);
    
    % View +- 1 ms i.e. trigger in the centre
    i.set_timebase(-1e-3,1e-3);
    
    i.start_streaming('duration', 10);
    %% Set up plots
    % Get initial data to set up plots
    data = i.get_stream_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (sec)')
    ylabel(gca,'Amplitude (V)')
    
    %% Receive and plot new data frames
    while 1
        data = i.get_stream_data();
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

# Digital Filter Box

# digital_filter_box_plotting.m

%% Plotting Digital Filter Box Example
%
% This example demonstrates how you can configure the Digital
% Filter Box instrument to filter and display two signals. Filter
% 1 takes its input from Input1 and applies a lowpass Butterworth
% filter. Filter 2 takes its input from Input1 + Input2 and applies
% a highpass Elliptic filter. The output of both filters are then
% displayed on the plot.
%
%  (c) 2024 Liquid Instruments Pty. Ltd.
%

%% Connect to the Moku
% Connect to your Moku by its IP address.
i = MokuDigitalFilterBox('192.168.###.###');

try
    % Set Channel 1 and 2 to DC coupled, 1 MOhm impedance, and
    % default input range (400 mVpp range on Moku:Pro, 1 Vpp
    % range on Moku:Lab, 10 Vpp range on Moku:Go)
    i.set_frontend(1, 'DC', '1MOhm', '0dB');
    i.set_frontend(2, 'DC', '1MOhm', '0dB');

    % Channel1 signal: Input 1
    % Channel2 signal: Input 1 + Input 2
    i.set_control_matrix(1, 1, 0);
    i.set_control_matrix(2, 1, 1);

    % Configure Digital Filter on Channel 1 and Channel 2
    % Channel1 is a 8th-order Butterworth lowpass filter
    % Channel2 is a 8th-order Elliptic highpass filter
    % 3.906 MHz is for Moku:Go
    % Please change sampling rate for other Moku devices.
    i.set_filter(1, "3.906MHz", 'shape',"Lowpass", 'type',"Butterworth",...
        'low_corner',1e3, 'order',8);
    i.set_filter(1, "3.906MHz", 'shape',"Highpass", 'type',"Elliptic",...
        'high_corner',100e3, 'order',8);

    % Monitor ProbeA: Filter Channel1 output
    % Monitor ProbeB: Filter Channel2 output
    i.set_monitor(1, "Output1");
    i.set_monitor(2, "Output2");

    % Enable Digital Filter Box output ports
    i.enable_output(1, 'signal',true, 'output',true);
    i.enable_output(2, 'signal',true, 'output',true);

    % View +- 0.5 ms i.e. trigger in the centre
    i.set_timebase(-0.5e-3, 0.5e-3);
    
    %% Retrieve data
    % Get one frame of data
    data = i.get_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (s)')
    ylabel(gca,'Amplitude (V)')
    legend('Lowpass Filter Output', 'Highpass Filter Output')
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
    
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

# Frequency Response Analyzer

# frequency_response_analyzer_basic.m

%% Basic Frequency Response Analyzer Example 
%
% This example demonstrates how you can generate output sweeps using the
% Frequency Response Analyzer instrument and retrieve a single sweep frame.
%
% (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Define sweep parameters here for readability
f_start = 20e6;  % Hz
f_stop= 100;  % Hz
points = 512;
averaging_time = 1e-6;  % sec
settling_time = 1e-6;  % sec
averaging_cycles = 1;
settling_cycles = 1;

%% Connect to Moku
% Connect to your Moku using its IP address.
i = MokuFrequencyResponseAnalyzer('192.168.###.###');

try

    %% Configure the instrument
    % Set output sweep amplitudes and offsets
    i.set_output(1, 1,'offset',0); % Channel 1, 1Vpp, 0V offset
    i.set_output(2, 1,'offset',0); % Channel 2, 1Vpp, 0V offset

    % Configure measurement mode to In/Out
    i.measurement_mode('mode','InOut');

    % Set sweep configuration
    i.set_sweep('start_frequency',f_start,'stop_frequency',f_stop, 'num_points',points, ...
        'averaging_time',averaging_time, 'averaging_cycles',averaging_cycles, ...
        'settling_time', settling_time, 'settling_cycles',settling_cycles);

    %% Get data from Moku
    % Get a single sweep frame from the Moku 
    data = i.get_data();

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME);
end

% End the current connection session with your Moku
i.relinquish_ownership();
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

# frequency_response_analyzer_plotting.m

%% Plotting Frequency Response Analyzer Example 
%
% This example demonstrates how you can generate output sweeps using the
% Frequency Response Analyzer instrument, and view transfer function data 
% in real-time.
%
% (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Define sweep parameters here for readability
f_start = 20e6;  % Hz
f_stop= 100;  % Hz
points = 512;
averaging_time = 1e-6;  % sec
settling_time = 1e-6;  % sec
averaging_cycles = 1;
settling_cycles = 1;

%% Connect to the Moku
% Connect to your Moku by its IP address.
i = MokuFrequencyResponseAnalyzer('192.168.###.###');
    
try

    %% Configure the instrument
    % Set output sweep amplitudes and offsets
    i.set_output(1, 1,'offset',0); % Channel 1, 1Vpp, 0V offset
    i.set_output(2, 1,'offset',0); % Channel 2, 1Vpp, 0V offset

    % Configure the measurement mode to In/Out
    i.measurement_mode('mode','InOut');

    % Set output sweep configuration
    i.set_sweep('start_frequency',f_start,'stop_frequency',f_stop, 'num_points',points, ...
        'averaging_time',averaging_time, 'averaging_cycles',averaging_cycles, ...
        'settling_time', settling_time, 'settling_cycles',settling_cycles);

    %% Set up plots
    % Get initial data to set up plots
    data = i.get_data();

    % Set up the plots
    figure;

    magnitude_graph = subplot(2,1,1);
    ms = semilogx(magnitude_graph, data.ch1.frequency,data.ch1.magnitude, data.ch2.frequency, data.ch2.magnitude);
    xlabel(magnitude_graph,'Frequency (Hz)');
    ylabel(magnitude_graph,'Magnitude (dB)');
    set(gca, 'XScale', 'log')

    phase_graph = subplot(2,1,2);
    ps = semilogx(phase_graph, data.ch1.frequency,data.ch1.phase, data.ch2.frequency, data.ch2.phase);
    xlabel(phase_graph,'Frequency (Hz)');
    ylabel(phase_graph,'Phase (cyc)');
    set(gca, 'XScale', 'log')

    %% Receive and plot new data frames
    while 1
        data = i.get_data();
        set(ms(1),'XData',data.ch1.frequency,'YData',data.ch1.magnitude);
        set(ms(2),'XData',data.ch2.frequency,'YData',data.ch2.magnitude);
        set(ps(1),'XData',data.ch1.frequency,'YData',data.ch1.phase);
        set(ps(2),'XData',data.ch2.frequency,'YData',data.ch2.phase);
        axis(magnitude_graph,'tight');
        axis(phase_graph,'tight');
        pause(0.1);
    end

catch ME
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

# Laser Lock Box

# laser_lock_box_basic.m

%% Basic Laser Lock Box Example
%
%  This example demonstrates how you can configure the Laser Lock Box 
%  Instrument.
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address and deploy the Laser Lock Box
% instrument.
i = MokuLaserLockBox('192.168.###.###');

try
    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 1 MOhm impedance, and 400 mVpp range
    i.set_frontend(1, 'DC', '1MOhm','0dB');
    % Channel 2 DC coupled, 1 MOhm impedance, and 4 Vpp range
    i.set_frontend(2, 'DC', '1MOhm','-20dB');
    
    % Configure the scan oscillator to a 10 Hz 500 mVpp positive ramp
    % signal from Output 1
    i.set_scan_oscillator('enable',true,'shape','PositiveRamp', ...
        'frequency',10,'amplitude',0.5,'output','Output1');
    
    % Configure demodulation signal to Local Oscillator at 1 MHz and no
    % phase shift
    i.set_demodulation('Internal','frequency',1e6,'phase',0);
    
    % Set low pass filter to 100 kHz corner frequency with 6 dB/octave slope
    i.set_filter('shape','Lowpass','low_corner',100e3,'order',4);
    
    % Set the fast PID controller to -10 dB proportional gain and
    % integrator crossover frequency at 3 kHz
    i.set_pid_by_frequency(1,-10,'int_crossover',3e3);
    % Set the slow PID controller to -10 dB proportional gain and
    % integrator crossover frequency at 50 Hz
    i.set_pid_by_frequency(2,-10,'int_crossover',50);
    
    % Enable the output channels
    i.set_output(1,true,true);
    i.set_output(2,true,true);
    
catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

# laser_lock_box_plotting.m

%% Plotting Laser Lock Box Example
%
%  This example demonstrates how you can configure the Laser Lock Box 
%  Instrument and monitor the signals at Input 1 and Input 2.
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address and deploy the Laser Lock Box
% instrument.
i = MokuLaserLockBox('192.168.###.###');

try
    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 1 MOhm impedance, and 400 mVpp range
    i.set_frontend(1, 'DC', '1MOhm','0dB');
    % Channel 2 DC coupled, 1 MOhm impedance, and 4 Vpp range
    i.set_frontend(2, 'DC', '1MOhm','-20dB');
    
    % Configure the scan oscillator to a 10 Hz 500 mVpp positive ramp
    % signal from Output 1
    i.set_scan_oscillator('enable',true,'shape','PositiveRamp', ...
        'frequency',10,'amplitude',0.5,'output','Output1');
    
    % Configure demodulation signal to Local Oscillator at 1 MHz and no
    % phase shift
    i.set_demodulation('Internal','frequency',1e6,'phase',0);
    
    % Configure a 4th order low pass filter with 100 kHz corner frequency
    i.set_filter('shape','Lowpass','low_corner',100e3,'order',4);
    
    % Set the fast PID controller to -10 dB proportional gain and
    % integrator crossover frequency at 3 kHz
    i.set_pid_by_frequency(1,-10,'int_crossover',3e3);
    % Set the slow PID controller to -10 dB proportional gain and
    % integrator crossover frequency at 50 Hz
    i.set_pid_by_frequency(2,-10,'int_crossover',50);
    
    % Enable the output channels
    i.set_output(1,true,true);
    i.set_output(2,true,true);
    
    %% Set up signal monitoring
    % Configure monitor points to Input 1 and Input 2
    i.set_monitor(1,'Input1');
    i.set_monitor(2,'Input2');
    
    % Configure the trigger conditions
    % Trigger on Probe A, rising edge, 0V
    i.set_trigger('type','Edge', 'source','ProbeA', 'level',0);
    
    % View +- 1 ms i.e. trigger in the centre
    i.set_timebase(-1e-3,1e-3);
    
    %% Set up plots
    % Get initial data to set up plots
    data = i.get_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (sec)')
    ylabel(gca,'Amplitude (V)')
    
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

# Lock-in Amplifier

# lock_in_amplifier_basic.m

%% Basic Lock-in Amplifier Example
%
%  This example demonstrates how you can configure the Lock-in Amplifier
%  instrument to demodulate an input signal from Input 1 with the reference
%  signal from the Local Oscillator to extract the X component and generate
%  a sine wave on the auxiliary output
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address and deploy the Lock-in Amplifier 
% instrument.
i = MokuLockInAmp('192.168.###.###');

try
    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 1 MOhm impedance, and 400 mVpp range
    i.set_frontend(1, 'DC', '1MOhm','0dB');
    % Channel 2 DC coupled, 1 MOhm impedance, and 4 Vpp range
    i.set_frontend(2, 'DC', '1MOhm','-20dB');
    
    % Configure the demodulation signal to Local oscillator with 1 MHz and
    % 0 degrees phase shift
    i.set_demodulation('Internal','frequency',1e6,'phase',0);
    
    % Set low pass filter to 1 kHz corner frequency with 6 dB/octave slope
    i.set_filter(1e3,'slope','Slope6dB');
    
    % Configure output signals
    % X component to Output 1 
    % Aux oscillator signal to Output 2 at 1 MHz 500 mVpp
    i.set_outputs('X','Aux');
    i.set_aux_output(1e6,0.5);
    

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

# lock_in_amplifier_plotting.m

%% Plotting Lock-in Amplifier Example
%
%  This example demonstrates how you can configure the Lock-in Amplifier
%  instrument to demodulate an input signal from Input 1 with the reference
%  signal from the Local Oscillator to extract the X component and generate
%  a sine wave on the auxiliary output
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address and deploy the Lock-in Amplifier 
% instrument.
i = MokuLockInAmp('192.168.###.###');

try
    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 1 MOhm impedance, and 400 mVpp range
    i.set_frontend(1, 'DC', '1MOhm','0dB');
    % Channel 2 DC coupled, 1 MOhm impedance, and 4 Vpp range
    i.set_frontend(2, 'DC', '1MOhm','-20dB');
    
    % Configure the demodulation signal to Local oscillator with 1 MHz and
    % 0 degrees phase shift
    i.set_demodulation('Internal','frequency',1e6,'phase',0);
    
    % Set low pass filter to 1 kHz corner frequency with 6 dB/octave slope
    i.set_filter(1e3,'slope','Slope6dB');
    
    % Configure output signals
    % X component to Output 1 
    % Aux oscillator signal to Output 2 at 1 MHz 500 mVpp
    i.set_outputs('X','Aux');
    i.set_aux_output(1e6,0.5);
    
    %% Set up signal monitoring
    % Configure monitor points to Input 1 and main output
    i.set_monitor(1,'Input1');
    i.set_monitor(2,'MainOutput');
    
    % Configure the trigger conditions
    % Trigger on Probe A, rising edge, 0V
    i.set_trigger('type','Edge', 'source','ProbeA', 'level',0);
    
    % View +- 1 ms i.e. trigger in the centre
    i.set_timebase(-1e-3,1e-3);
    
    %% Set up plots
    % Get initial data to set up plots
    data = i.get_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (sec)')
    ylabel(gca,'Amplitude (V)')
    
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

# Logic Analyzer

# logicanalyzer_basic.m

%% Basic LogicAnalyzer Example
%
%  This example demonstrates how you can configure the LogicAnalyzer instrument.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku and deploy the Logic Analyzer instrument
i = MokuLogicAnalyzer('192.168.###.###');

try
    patterns = [struct('pin', 1, 'pattern', repmat([1],1,1024)), ...
        struct('pin', 2, 'pattern', repmat([0],1,1024)), ...
        struct('pin', 3, 'pattern', repmat([1 0],1,512)), ...
        struct('pin', 4, 'pattern', repmat([0 1],1,512))];
    
    
    i.set_pattern_generator(1, patterns, 'divider', 8);
    
    i.set_pin_mode(1, "PG1");
    i.set_pin_mode(2, "PG1");
    i.set_pin_mode(3, "PG1");
    i.set_pin_mode(4, "PG1");
    
    data = i.get_data('wait_reacquire', true, 'include_pins', [1, 2, 3, 4]);
    
    tiledlayout(4,1)
    
    ax1 = nexttile;
    p1 = stairs(data.time, data.pin1, 'Color','r');
    
    ax2 = nexttile;
    p2 = stairs(data.time, data.pin2, 'Color','r');
    
    ax3 = nexttile;
    p3 = stairs(data.time, data.pin3, 'Color','r');
    
    ax4 = nexttile;
    p4 = stairs(data.time, data.pin4, 'Color','r');
    

    
    linkaxes([ax1 ax2 ax3 ax4],'xy');
    
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
        set(p1,'XData',data.time,'YData',data.pin1);
        set(p2,'XData',data.time,'YData',data.pin2);
        set(p3,'XData',data.time,'YData',data.pin3);
        set(p4,'XData',data.time,'YData',data.pin4);
        
        axis tight
        pause(0.1)
    end
    
catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end


% End the current connection session with your Moku
i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

# Multi-instrument Mode

# mim_wg_osc.m

Multi-instrument Mode on Moku:Go (two-slot), deploying the Waveform Generator and Oscilloscope at once. This example is easily ported to Moku:Pro by changing the "platform_id" to one supported by that hardware.

%% Multi-instrument WaveformGenerator-Oscilloscope Example
%
%  This example demonstrates how you can configure the multi instrument mode
% with Waveform Generator in slot1 and Oscilloscope in slot2
%  and view triggered time-voltage data frames in real-time.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Configure multi-instrument with platform_id 2
m = MokuMultiInstrument('192.168.###.###', 2);

try

    %% Configure the instruments
    % WaveformGenerator in slot1
    % Oscilloscope in slot2
    wg = m.set_instrument(1, @MokuWaveformGenerator);
    osc = m.set_instrument(2, @MokuOscilloscope);

    % configure routing
    connections = [struct('source', 'Input1', 'destination', 'Slot1InA');
                struct('source', 'Slot1OutA', 'destination', 'Slot2InA');
                struct('source', 'Slot1OutA', 'destination', 'Slot2InB');
                struct('source', 'Slot2OutA', 'destination', 'Output1')];

    m.set_connections(connections);

    % configure frontend
    m.set_frontend(1, "1MOhm", "DC", "0dB");

    %% Configure waveform generator
    % generate waveform
    wg.generate_waveform(1, "Sine");

    % set the timebase
    osc.set_timebase(-5e-3, 5e-3);

    %% Set up plots
    % Get initial data to set up plots
    data = osc.get_data();

    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca, 'Time (sec)')
    ylabel(gca, 'Amplitude (V)')

    %% Receive and plot new data frames
    while 1
        data = osc.get_data();
        set(lh(1), 'XData', data.time, 'YData', data.ch1);
        set(lh(2), 'XData', data.time, 'YData', data.ch2);

        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    m.relinquish_ownership();
    rethrow(ME)
end

m.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

# mim_wg_sa.m

Multi-instrument Mode on Moku:Go (two slot), deploying the Waveform Generator and Spectrum Analyzer at once. This example is easily ported to Moku:Pro by changing the "platform_id" to one supported by that hardware.

%% Multi-instrument WaveformGenerator-SpectrumAnalyzer Example
%
%  This example demonstrates how you can configure the multi instrument mode
% with Waveform Generator in slot1 and SpectrumAnalyzer in slot2
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Configure multi-instrument with platform_id 2
m = MokuMultiInstrument('192.168.###.###', 2);

try

    %% Configure the instruments
    % WaveformGenerator in slot1
    % SpectrumAnalyzer in slot2
    wg = m.set_instrument(1, @MokuWaveformGenerator);
    sa = m.set_instrument(2, @MokuSpectrumAnalyzer);

    % configure routing
    connections = [struct('source', 'Input1', 'destination', 'Slot1InA');
                struct('source', 'Slot1OutA', 'destination', 'Slot2InA')];

    m.set_connections(connections);

    % configure frontend
    m.set_frontend(1, "1MOhm", "DC", "0dB");

    %% Configure waveform generator
    % generate waveform
    wg.generate_waveform(1, 'Sine', 'frequency', 10e5);

    % set the span
    sa.set_span(0, 10e5);

    % set rbw mode
    sa.set_rbw('Auto');

    %% Retrieve data
    % Get one frame of spectrum data
    data = sa.get_data();

    % Set up the plots
    figure
    lh = plot(data.frequency, data.ch1);
    xlabel(gca, 'Frequency (Hz)')
    ylabel(gca, 'Amplitude (dBm)')

    %% Receive and plot new data frames
    while 1
        data = sa.get_data();

        set(lh(1), 'XData', data.frequency, 'YData', data.ch1);

        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    m.relinquish_ownership();
    rethrow(ME)
end

m.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

# Oscilloscope

# oscilloscope_basic.m

%% Plotting Oscilloscope Example
%
%  This example demonstrates how you can configure the Oscilloscope instrument
% to retrieve a single frame of dual-channel voltage data.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address.
i = MokuOscilloscope('192.168.###.###');

try
    
    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 10Vpp range
    i.set_frontend(1, '1MOhm', 'DC', '10Vpp');
    % Channel 2 DC coupled, 50Vpp range
    i.set_frontend(2, '1MOhm', 'DC', '10Vpp');
    
    % Configure the trigger conditions
    % Trigger on input Channel 1, rising edge, 0V
    i.set_trigger('type',"Edge", 'source',"Input1", 'level',0);
    
    % View +- 1 ms i.e. trigger in the centre
    i.set_timebase(-1e-3,1e-3);
    
    % Generate a sine wave on Output 1
    % 0.5Vpp, 10kHz, 0V offset
    i.generate_waveform(1, 'Sine', 'amplitude',0.5, 'frequency', 10e3);
    
    % Generate a square wave on Output 2
    % 1Vpp, 20kHz, 0V offset, 50% duty cycle
    i.generate_waveform(2, 'Square', 'amplitude',1, 'frequency',20e3, 'duty', 50);
    
    % Set the data source of Channel 1 to be Input 1
    i.set_source(1,'Input1');
    % Set the data source of Channel 2 to Input 2
    i.set_source(2,'Input2');
    
    %% Retrieve data
    % Get one frame of dual-channel voltage data
    data = i.get_data();

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

# oscilloscope_plotting.m

%% Plotting Oscilloscope Example
%
%  This example demonstrates how you can configure the Oscilloscope instrument,
%  and view triggered time-voltage data frames in real-time.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address.
i = MokuOscilloscope('192.168.###.###');

try

    %% Configure the instrument
    
    % Configure the frontend
    % Channel 1 DC coupled, 10Vpp range
    i.set_frontend(1, '1MOhm', 'DC', '10Vpp');
    % Channel 2 DC coupled, 50Vpp range
    i.set_frontend(2, '1MOhm', 'DC', '10Vpp');
    
    % Configure the trigger conditions
    % Trigger on input Channel 1, rising edge, 0V
    i.set_trigger('type',"Edge", 'source',"Input1", 'level',0);
    
    % View +- 1 ms i.e. trigger in the centre
    i.set_timebase(-1e-3,1e-3);
    
    % Generate a sine wave on Output 1
    % 0.5Vpp, 10kHz, 0V offset
    i.generate_waveform(1, 'Sine', 'amplitude',0.5, 'frequency', 10e3);
    
    % Generate a square wave on Output 2
    % 1Vpp, 20kHz, 0V offset, 50% duty cycle
    i.generate_waveform(2, 'Square', 'amplitude',1, 'frequency',20e3, 'duty', 50);
    
    % Set the data source of Channel 1 to be Input 1
    i.set_source(1,'Input1');
    % Set the data source of Channel 2 to Input 2
    i.set_source(2,'Input2');
    
    %% Set up plots
    % Get initial data to set up plots
    data = i.get_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (sec)')
    ylabel(gca,'Amplitude (V)')
    
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end


catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

# Phasemeter

# phasemeter_basic.m

%% Basic Phasemeter Example
%
%  This example demonstrates how you can configure the Phasemeter
%  instrument to measure 4 independent signals.
%
%  (c) 2022 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku and deploy the Phasemeter instrument
i = MokuPhasemeter('192.168.###.###');

try
    % Set frontend of all input channels to 50 Ohm, DC coupled, 4 Vpp
    % range
    i.set_frontend(1,'50Ohm','DC','4Vpp');
    i.set_frontend(2,'50Ohm','DC','4Vpp');
    i.set_frontend(3,'50Ohm','DC','4Vpp');
    i.set_frontend(4,'50Ohm','DC','4Vpp');
    
    % Configure Output channel 1 to generate sine waves at 1 Vpp, 2 MHz
    i.generate_output(1, 'Sine', 'amplitude',1, 'frequency',2e6);
    % Configure Output channel 2 to be phase locked to Input 2 signal at an
    % amplitude of 0.5 Vpp
    i.generate_output(2, 'Sine', 'amplitude',0.5, 'phase_locked',true);
    % Configure Output channel 3 and 4 to generate measured phase at a
    % scaling of 1 V/cycle and 10 V/cycle respectively
    i.generate_output(3, 'Phase','scaling',1);
    i.generate_output(4, 'Phase','scaling',10);
    
    % Set the acquisition speed to 596Hz for all channels
    i.set_acquisition_speed('596Hz');
    
    % Set all input channels to 2 MHz, bandwidth 100 Hz
    i.set_pm_loop(1,'auto_acquire',false,'frequency',2e6,'bandwidth','100Hz');
    i.set_pm_loop(2,'auto_acquire',false,'frequency',2e6,'bandwidth','100Hz');
    i.set_pm_loop(3,'auto_acquire',false,'frequency',2e6,'bandwidth','100Hz');
    i.set_pm_loop(4,'auto_acquire',false,'frequency',2e6,'bandwidth','100Hz');
    
    % Get all the data available from the Moku
    data = i.get_data();
    
catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# PID Controller

# pidcontroller_basic.m

%% Basic PID Controller Example
%
%  This example demonstrates how you can configure the PID Controller instrument.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

% Connect to your Moku and deploy the PID controller instrument
i = MokuPIDController('192.168.###.###');

try
    
    %% Configure the PID controller
    % Configure the control matrix
    i.set_control_matrix(1,1,0);
    i.set_control_matrix(2,0,1);
    % Enable all input and output channels
    i.enable_input(1,true);
    i.enable_input(2,true);
    i.enable_output(1,true,true);
    i.enable_output(2,true,true);
    
    % Configure controller 1 by gain
    i.set_by_gain(1,'prop_gain',10, 'diff_gain',-5,'diff_corner',5e3 );
    % Configure controller 2 by frequency
    i.set_by_frequency(2, 'prop_gain', -5, 'int_crossover',100, 'int_saturation',10);
    
  
catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

# pidcontroller_plotting.m

%% Plotting PID Controller Example
%
%  This example demonstrates how you can configure the PID Controller instrument,
%  and view triggered time-voltage data frames in real-time.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

% Connect to your Moku and deploy the PID controller instrument
i = MokuPIDController('192.168.###.###');

try
    
    %% Configure the PID controller
    % Configure the control matrix
    i.set_control_matrix(1,1,0);
    i.set_control_matrix(2,0,1);
    % Enable all input and output channels
    i.enable_input(1,true);
    i.enable_input(2,true);
    i.enable_output(1,true,true);
    i.enable_output(2,true,true);
    
    % Configure controller 1 by gain
    i.set_by_gain(1,'prop_gain',10, 'diff_gain',-5,'diff_corner',5e3 );
    % Configure controller 2 by frequency
    i.set_by_frequency(2, 'prop_gain', -5, 'int_crossover',100, 'int_saturation',10);
    
    
    % Place 2 monitor points, one at input 1, one at output 1
    i.set_monitor(1,'Input1');
    i.set_monitor(2,'Output1');
    % Configure the timebase to -2 ms and 2 ms
    i.set_timebase(-0.002,0.002);
    
    % Configure the trigger
    i.set_trigger('type',"Edge", 'source',"ProbeA", 'level',0);
    
    %% Set up plots
    % Get initial data to set up plots
    data = i.get_data();
    
    % Set up the plots
    figure
    lh = plot(data.time, data.ch1, data.time, data.ch2);
    xlabel(gca,'Time (sec)')
    ylabel(gca,'Amplitude (V)')
    grid on
    grid(gca,'minor')
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
        set(lh(1),'XData',data.time,'YData',data.ch1);
        set(lh(2),'XData',data.time,'YData',data.ch2);
        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

# Programmable Power Supplies

# powersupply_basic.m

%% PPSU Example
%
%  This example will demonstrate how to configure the power supply
%  units of the Moku:Go.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

% Connect to your Moku by its IP address.
% An instrument must be deployed to establish the connection with the
% Moku, in this example we will use the Oscilloscope.
i = MokuOscilloscope('192.168.###.###');
try

    % Configure Power Supply Unit 1 to 2 V and 0.1 A
    i.set_power_supply(1,'enable',true,'voltage',2,'current',0.1);
    
    % Read the current status of Power Supply Unit 1 
    disp(i.get_power_supply(1));

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# Spectrum Analyzer

# spectrumanalyzer_basic.m

%% Basic Spectrum Analyzer Example  
%
%  This example demonstrates how you can configure the Spectrum Analyzer
%  instrument to retrieve a single spectrum data frame over a set frequency 
%  span.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to the Moku
% Connect to your Moku by its IP address.
i = MokuSpectrumAnalyzer('192.168.###.###');

try
    
    %% Configure the instrument
    
    % Generate a sine wave on Channel 1
    % 1Vpp, 1MHz, 0V offset
    i.sa_output(1, 1, 1e6);
    % Generate a sine wave on Channel 2
    % 2Vpp, 50kHz, 0V offset
    i.sa_output(2, 2, 50e3);
    
    % Configure the measurement span to from 10Hz to 10MHz
    i.set_span(10,10e6);
    % Use Blackman Harris window
    i.set_window('BlackmanHarris');
    % Set resolution bandwidth to automatic
    i.set_rbw('Auto');
    
    %% Retrieve data
    % Get one frame of spectrum data
    data = i.get_data();

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

# spectrumanalyzer_plotting.m

%% Basic Spectrum Analyzer Example  
%
%  This example demonstrates how you can configure the Spectrum Analyzer
%  instrument to retrieve a single spectrum data frame over a set frequency 
%  span.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to the Moku
% Connect to your Moku by its IP address.
i = MokuSpectrumAnalyzer('192.168.###.###');

try
    
    %% Configure the instrument
    
    % Generate a sine wave on Channel 1
    % 1Vpp, 1MHz, 0V offset
    i.sa_output(1, 1, 1e6);
    % Generate a sine wave on Channel 2
    % 2Vpp, 50kHz, 0V offset
    i.sa_output(2, 2, 50e3);
    
    % Configure the measurement span to from 10Hz to 10MHz
    i.set_span(10,10e6);
    % Use Blackman Harris window
    i.set_window('BlackmanHarris');
    % Set resolution bandwidth to automatic
    i.set_rbw('Auto');
    
    %% Retrieve data
    % Get one frame of spectrum data
    data = i.get_data();
    
    % Set up the plots
    figure
    lh = plot(data.frequency, data.ch1, data.frequency, data.ch2);
    xlabel(gca,'Frequency (Hz)')
    ylabel(gca,'Amplitude (dBm)')
    
    %% Receive and plot new data frames
    while 1
        data = i.get_data();
    
        set(lh(1),'XData',data.frequency,'YData',data.ch1);
        set(lh(2),'XData',data.frequency,'YData',data.ch2);
    
        axis tight
        pause(0.1)
    end

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

# Waveform Generator

# waveformgenerator_basic.m

%% Basic Waveform Generator Example 
%
%  This example demonstrates how you can configure the Waveform Generator
%  instrument.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address.
i = MokuWaveformGenerator('192.168.###.###');

try

    %% Configure the instrument
    % Generate a sine wave on Channel 1
    % 0.5Vpp, 1MHz, 0V offset
    i.generate_waveform(1, 'Sine','amplitude', 0.5, 'frequency',1e6,'offset',0);
    % Generate a square wave on Channel 2
    % 1Vpp, 10kHz, 0V offset, 50% duty cycle
    i.generate_waveform(2, 'Square', 'amplitude',1,'frequency',10e3, 'duty',50);

    % Phase sync between the two channels
    i.sync_phase();

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

# waveformgenerator_modulation.m

%% Basic Waveform Generator Example 
%
%  This example demonstrates how you can configure the Waveform Generator
%  instrument.
%
%  (c) 2021 Liquid Instruments Pty. Ltd.
%

%% Connect to your Moku
% Connect to your Moku by its IP address.
i = MokuWaveformGenerator('192.168.###.###');

try
    
    %% Configure the instrument
    % Generate a sine wave on Channel 1
    % 0.5Vpp, 1MHz, 0V offset
    i.generate_waveform(1, 'Sine','amplitude', 0.5, 'frequency',1e6,'offset',0);
    % Generate a square wave on Channel 2
    % 1Vpp, 10kHz, 0V offset, 50% duty cycle
    i.generate_waveform(2, 'Square', 'amplitude',1,'frequency',10e3,'duty', 50);

    % Phase sync between the two channels
    i.sync_phase();

    %% Configure modulation
    % Amplitude modulate the Channel 1 Sinewave with another internally-
    % generated sinewave. 50% modulation depth at 1Hz.
    i.set_modulation(1,'Amplitude','Internal','depth',50, 'frequency',1);

    % Burst modulation on Channel 2 using Output 1 as the trigger
    i.set_burst_mode(2,'Output1','NCycle','trigger_level',0.1, 'burst_cycles',2);

catch ME
    % End the current connection session with your Moku
    i.relinquish_ownership();
    rethrow(ME)
end

i.relinquish_ownership();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39