Commit 681f564e authored by Lindenberg, Arthur-Vincent's avatar Lindenberg, Arthur-Vincent
Browse files

Added more waveform classes to Red Pitaya Signal Generator

Build Binary mehtod to call arbitrary class
Extended the example file
parent 82e2def9
......@@ -14,17 +14,17 @@ channel = "CH1"; % Name of used red pitaya channel
%% Waveform Sinus
% sigeSin = SigGenSine(); % get an object of the SigGenSine child class
% SiGeSin_proberty_message = sigeSin.get_mqtt_message_sin; % build mqtt message
%sigeSin.magnitude =0.6; % change magnitude
%sigeSin.frequency = 4000; % change frequency
%rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSin_proberty_message) % Use Mqtt function to generate signal
% SiGeSin_proberty_message = sigeSin.get_mqtt_message; % build mqtt message
% sigeSin.magnitude =0.6; % change magnitude
% sigeSin.frequency = 4000; % change frequency
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSin_proberty_message) % Use Mqtt function to generate signal
% %% Waveform Square
%
%% Waveform Square
% sigeSquare = SigGenSquare(); % Build object of child class SigGenSquare
% sigeSquare.magnitude =0.6; % change magnitude
% sigeSquare.frequency = 3000; % change frequency
% SiGeSquare_proberty_message = sigeSquare.get_mqtt_message_square; % build mqtt message
% SiGeSquare_proberty_message = sigeSquare.get_mqtt_message; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSquare_proberty_message) % Use Mqtt function to generate signal
......@@ -33,14 +33,58 @@ channel = "CH1"; % Name of used red pitaya channel
% sigeSawtooth = SigGenSawtooth(); % Build object of child class SigGenSawtooth
% sigeSawtooth.magnitude =0.7; % change magnitude
% sigeSawtooth.frequency = 2000; % change frequency
% SiGeSawtooth_proberty_message = sigeSawtooth.get_mqtt_message_sawtooth; % build mqtt message
% SiGeSawtooth_proberty_message = sigeSawtooth.get_mqtt_message; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSawtooth_proberty_message) % Use Mqtt function to generate signal
%% Waveform PWM
sigePWM = SigGenPWM(); % Build object of child class SigGenSquare
sigePWM.magnitude =0.6; % change magnitude
sigePWM.frequency = 3000; % change frequency#
sigePWM.duty_cycle = 0.2; % change duty cicle
SiGeSquare_proberty_message = sigePWM.get_mqtt_message_pwm; % build mqtt message
rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSquare_proberty_message) % Use Mqtt function to generate signal
% sigePWM = SigGenPWM(); % Build object of child class SigGenPWM
% sigePWM.magnitude =0.6; % change magnitude
% sigePWM.frequency = 3000; % change frequency#
% sigePWM.duty_cycle = 0.2; % change duty cicle
% SiGeSquare_proberty_message = sigePWM.get_mqtt_message; % build mqtt message
%
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSquare_proberty_message) % Use Mqtt function to generate signal
%
% channel = "CH2"; % Name of used red pitaya channel
% sigePWM.frequency = 2000; % change frequency
% sigePWM.duty_cycle = 0.6;
% SiGeSquare_proberty_message = sigePWM.get_mqtt_message; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSquare_proberty_message) % Use Mqtt function to generate signal
%% Waveform Triangle
% sigeTriangle = SigGenTriangle(); % Build object of child class SigGenTriangle
% sigeTriangle.magnitude =0.6; % change magnitude
% sigeTriangle.frequency = 3000; % change frequency
% SiGeTriangle_proberty_message = sigeTriangle.get_mqtt_message; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeTriangle_proberty_message) % Use Mqtt function to generate signal
%% Waveform Revsawtooth
% sigeRevsawtooth = SigGenRevsawtooth(); % Build object of child class SigGenRevsawtooth
% sigeRevsawtooth.magnitude =0.6; % change magnitude
% sigeRevsawtooth.frequency = 3000; % change frequency
% SiGeRevsawtooth_proberty_message = sigeRevsawtooth.get_mqtt_message; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeRevsawtooth_proberty_message) % Use Mqtt function to generate signal
%% Waveform Direct Current (DC)
% sigeDC = SigGenDC(); % Build object of child class SigGenDC
% sigeDC.magnitude =0.6; % change magnitude
% SiGeDC_proberty_message = sigeDC.get_mqtt_message; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeDC_proberty_message) % Use Mqtt function to generate signal
%% Waveform Arbitrary
% N=16383;
% t=0:(2*pi)/N:2*pi;
% x=sin(t)+1/3*sin(3*t);
%
% sigeArbitrary = SigGenArbitrary(x); % Build object of child class SigGenArbitrary
% [SiGeArbitrary_proberty_message,SiGeArbitrary_proberty_message_b] = sigeArbitrary.get_mqtt_message(); % build mqtt message
% rp_sig_gen_b(myMqtt, broker_ip, rp_name, channel, SiGeArbitrary_proberty_message_b) % Use Mqtt function to generate signal
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeArbitrary_proberty_message) % Use Mqtt function to generate signal
classdef SigGenArbitrary < SigGenProperties
properties
waveform
end
methods
%% Constructor
function obj = SigGenArbitrary(data)
%SigGenArbitrary Construct an instance of this class
obj@SigGenProperties();
if nargin > 0
obj.waveform = data;
end
end
%% Getter methods
function [mqtt_message_sig, mqtt_message_sig_b] = get_mqtt_message(obj)
mqtt_message_sig_b ={"/WAVE/ARB", obj.waveform};
mqtt_message_sig = get_mqtt_message@SigGenProperties(obj);
end
%% Setter methods
function obj = set.waveform(obj,value)
obj.waveform = typecast(single(value), 'uint8');
% fprintf( 'set.waveform method called. waveform = %s\n', obj.waveform );
fprintf( 'set.waveform method called');
end
end
end
classdef SigGenDC < SigGenProperties
properties
end
methods
%% Constructor
function obj = SigGenDC()
obj@SigGenProperties();
%SigGenRevsawtooth Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append ={"/WAVE/DC", "1"};
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
......@@ -14,12 +14,12 @@ classdef SigGenPWM < SigGenProperties
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_pwm(obj)
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append =...
{"/WAVE/PWM", "1";...
"/FREQUENCY", num2str(obj.frequency);...
"/DUTYCYCLE",num2str(obj.duty_cycle)};
mqtt_message = obj.get_mqtt_message;
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
......
classdef SigGenRevsawtooth < SigGenProperties
properties
frequency = 1000;
end
methods
%% Constructor
function obj = SigGenRevsawtooth()
obj@SigGenProperties();
%SigGenRevsawtooth Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append =...
{"/WAVE/REVSAWTOOTH", "1";...
"/FREQUENCY", num2str(obj.frequency)};
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
......@@ -13,11 +13,11 @@ classdef SigGenSawtooth < SigGenProperties
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_sawtooth(obj)
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append =...
{"/WAVE/SAWTOOTH", "1";...
"/FREQUENCY", num2str(obj.frequency)};
mqtt_message = obj.get_mqtt_message;
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
......
......@@ -13,9 +13,9 @@ classdef SigGenSine < SigGenProperties
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_sin(obj)
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append = {"/WAVE/SINE", "1"; "/FREQUENCY", num2str(obj.frequency)};
mqtt_message = obj.get_mqtt_message;
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
......
......@@ -13,11 +13,11 @@ classdef SigGenSquare < SigGenProperties
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_square(obj)
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append =...
{"/WAVE/SQUARE", "1";...
"/FREQUENCY", num2str(obj.frequency)};
mqtt_message = obj.get_mqtt_message;
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
......
classdef SigGenTriangle < SigGenProperties
properties
frequency = 1000;
end
methods
%% Constructor
function obj = SigGenTriangle()
obj@SigGenProperties();
%SigGenTriangle Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message(obj)
mqtt_message_append =...
{"/WAVE/TRIANGLE", "1";...
"/FREQUENCY", num2str(obj.frequency)};
mqtt_message = get_mqtt_message@SigGenProperties(obj);
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
function rp_sig_gen_b(mqtt_handler, broker_ip, rp_name, ch, message)
% Build signal from message proberty class
len_message = size(message);
len_message_dim1= len_message(1);
for i= 1:len_message_dim1
mqtt_handler.pub_mqtt_binary(broker_ip, rp_name + "/CONFIGURE/AO/" + ch + message(i,1), message{i,2});
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment