NInFEA: Non-Invasive Multimodal Foetal ECG-Doppler Dataset for Antenatal Cardiology Research 1.0.0

File: <base>/code/Interfaccia_dataset.m (16,502 bytes)
function Interfaccia_dataset

% Initialization
close all

% Add the UI components
hUI = addcomponents;

% Make figure visible after adding
hUI.fig.Visible = 'on';

% Global variables (shared between functions)
global tempo_doppler
global tempo_sig
global data
global fs
global sample
global index
global flag
global ylim_zoom
global fs_doppler
% Default Settings
index = 1;
flag = 1;
fs=2048;
fs_doppler=284;

unica = imread('Logo_UniCa.jpg');
red = unica(:,:, 1);
green = unica(:,:, 2);
blue = unica(:,:, 3);
rth = 240;
gth = 240;
bth = 240;
redMask = (red > rth);
greenMask = (green > gth);
blueMask = (blue > bth);
mask = logical(redMask & greenMask & blueMask);
red(mask) = 240;
green(mask) = 240;
blue(mask) = 240;
unica(:,:,1) = red;
unica(:,:,2) = green;
unica(:,:,3) = blue;
imshow(unica, 'Parent', hUI.logo_unica);


    function hUI = addcomponents()
        % Add components, save handles in a struct
        
        % Main figure
        hUI.fig = figure('Visible','off', 'numbertitle','off',...
            'Units','normalized', 'menubar','figure', 'name','Fetal ECG interface',...
            'Resize','on', 'Position',[.015 .055 .97 .848]);%, 'Color',[1 215/255 227/255]);
        
        % Image
        hUI.ax1 = axes('Units','pixels','Units','normalized',...
            'XTick',[], 'YTick',[], 'Position',[.05 .55 .7 .44]);
        
        % Logo Unica
        hUI.logo_unica = axes('Units','pixels','Units','normalized',...
            'XTick',[], 'YTick',[], 'Position',[.756 .74 .25 .25]);
        
        % Signal
        hUI.ax2 = axes('Units','pixels','Units','normalized',...
            'Position',[.05 .1 .7 .44]);
        
        % Slider
        hUI.slider = uicontrol(hUI.fig,'Style','slider','Min',1,'Max',2,'Value',1,...
            'Units','normalized','Position',[.19 .02 .56 .03],'Enable','off','Visible','on',...
            'BackgroundColor',[0.941 0.941 0.941],'callback',@slider_callback);
        
        % Frame text
        uicontrol(hUI.fig,'Style','text',...
            'String','Frame',...
            'Units','normalized','Position',[.05 .04 .05 .02]);
        
        % Current frame
        hUI.frame_disp = uicontrol(hUI.fig,'Style','edit','Units','normalized',...
            'String','1','Value',1,'Position',[.05 .012 .05 .02],...
            'callback',@frame_disp_callback,...
            'Interruptible','on','Visible', 'on','Enable','off');
        
        % Time text
        uicontrol(hUI.fig,'Style','text',...
            'String','Time [s]',...
            'Units','normalized','Position',[.11 .04 .05 .02]);
        
        % Current time
        hUI.time_disp = uicontrol(hUI.fig,'Style','text','Units','normalized',...
            'String','0','Value',0,'Position',[.11 .012 .05 .02],...
            'Interruptible','on','Visible', 'on','Enable','on');
        
        % LOAD button
        hUI.load_but = uicontrol(hUI.fig,'Style','pushbutton',...
            'String','LOAD','Units','normalized','Position',[.84 .63 .08 .05],...
            'BackgroundColor',[0.941 0.941 0.941], 'callback',@load_callback,'Interruptible','on','Enable', 'on');
        
        % Channel group
        hUI.channelgrp = uibuttongroup('parent',hUI.fig,'Title','Channels','visible','on',...
            'Position',[.79 .3 .19 .30],'BackgroundColor',[0.941 0.941 0.941]);
        
        % Channel checkboxes:
        hUI.ch1 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 1','Value',1,'Enable','off',...
            'Position',[0.01 0.9 0.2 0.08]);
        
        hUI.ch2 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 2','Value',0,'Enable','off',...
            'Position',[0.01 0.8 0.2 0.09]);
        
        hUI.ch3 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 3','Value',0,'Enable','off',...
            'Position',[0.01 0.7 0.2 0.09]);
        
        hUI.ch4 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 4','Value',0,'Enable','off',...
            'Position',[0.01 0.6 0.2 0.09]);
        
        hUI.ch5 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 5','Enable','off',...
            'Position',[0.01 0.5 0.2 0.09]);
        
        hUI.ch6 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 6','Value',0,'Enable','off',...
            'Position',[0.01 0.4 0.2 0.09]);
        
        hUI.ch7 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 7','Enable','off',...
            'Position',[0.01 0.3 0.2 0.09]);
        
        hUI.ch8 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 8','Value',0,'Enable','off',...
            'Position',[0.01 0.2 0.2 0.09]);
        
        hUI.ch9 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 9','Value',0,'Enable','off',...
            'Position',[0.01 0.1 0.2 0.09]);
        
        hUI.ch10 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 10','Value',0,'Enable','off',...
            'Position',[0.01 0.001 0.2 0.09]);
        
        hUI.ch11 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 11','Value',0,'Enable','off',...
            'Position',[0.27 0.9 0.2 0.09]);
        
        hUI.ch12 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 12','Value',0,'Enable','off',...
            'Position',[0.27 0.8 0.2 0.09]);
        
        hUI.ch13 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 13','Value',0,'Enable','off',...
            'Position',[0.27 0.7 0.2 0.09]);
        
        hUI.ch14 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 14','Value',0,'Enable','off',...
            'Position',[0.27 0.6 0.2 0.09]);
        
        hUI.ch15 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 15','Value',0,'Enable','off',...
            'Position',[0.27 0.5 0.2 0.09]);
        
        hUI.ch16 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 16','Value',0,'Enable','off',...
            'Position',[0.27 0.4 0.2 0.09]);
        
        hUI.ch17 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 17','Value',0,'Enable','off',...
            'Position',[0.27 0.3 0.2 0.09]);
        
        hUI.ch18 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 18','Value',0,'Enable','off',...
            'Position',[0.27 0.2 0.2 0.09]);
        
        hUI.ch19 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 19','Value',0,'Enable','off',...
            'Position',[0.27 0.1 0.2 0.09]);
        
        hUI.ch20 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 20','Value',0,'Enable','off',...
            'Position',[0.27 0.001 0.2 0.09]);
        
        hUI.ch21 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 21','Value',0,'Enable','off',...
            'Position',[0.53 0.9 0.2 0.09]);
        
        hUI.ch22 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 22','Value',0,'Enable','off',...
            'Position',[0.53 0.8 0.2 0.09]);
        
        hUI.ch23 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 23','Value',0,'Enable','off',...
            'Position',[0.53 0.7 0.2 0.09]);
        
        hUI.ch24 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 24','Value',0,'Enable','off',...
            'Position',[0.53 0.6 0.2 0.09]);
        
        hUI.ch25 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 25','Value',0,'Enable','off',...
            'Position',[0.53 0.5 0.2 0.09]);
        
        hUI.ch26 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 26','Value',0,'Enable','off',...
            'Position',[0.53 0.4 0.2 0.09]);
        
        hUI.ch27 = uicontrol(hUI.channelgrp,'Style', 'check','Units','normalized',...
            'String','Ch 27','Value',0,'Enable','off',...
            'Position',[0.53 0.3 0.2 0.09]);
        
        
        hUI.offset = uicontrol(hUI.fig,'Style', 'check','Units','normalized',...
            'String','Remove the offset','Value',0,'Enable','off',...
            'Position',[.84 .15 .12 .10]);
        
        hUI.zoom_plus = uicontrol(hUI.fig,'Style', 'check','Units','normalized',...
            'String','Zoom +','Value',0,'Enable','off',...
            'Position',[.84 .08 .12 .10]);
        
        
        % Plot button
        hUI.plot_but = uicontrol(hUI.fig, 'Style','pushbutton',...
            'String','PLOT', 'Units','normalized','Position',[.84 .22 .08 .05],...
            'BackgroundColor',[0.941 0.941 0.941], 'callback',@plot_callback,...
            'Interruptible','on','Enable', 'off','Visible','on');
        
    end

    function load_callback(~,~)
        
        
        [Name_doppler, Path_doppler] = uigetfile({'*.bmp','Doppler (*.bmp)'},...
            'Select Filtered Doppler');
        [Name_sig, Path_sig] = uigetfile({'*.mat','Signal (*.mat)'},...
            'Select Signal');
        hUI.load_but.BackgroundColor = [.9 .4 .4];
        hUI.load_but.Enable = 'off';
        signal = load([Path_sig, Name_sig]);
        data = signal.PORTI;
        doppler = imread([Path_doppler, Name_doppler]);
        imshow(doppler, 'Parent', hUI.ax1);
        
        xlim(hUI.ax1, [-2*fs_doppler - 1,2*fs_doppler - 1]);
        ch = 1;
        L = length(data(ch,:));
        tempo_sig = (0:L-1)/fs;
        len = length(doppler);
        tempo_doppler = (0:len-1)/fs_doppler;
        sample = 1;
        plot(hUI.ax2,tempo_sig,data(ch,:));
        data_plotted=data(ch,:);
        
        ylabel('Amplitude [µV]')
        hold(hUI.ax2, 'on' )
        line([tempo_sig(sample), tempo_sig(sample)], ylim(hUI.ax2),'Color','r')
        xlim(hUI.ax2, [tempo_sig(sample)-2,tempo_sig(sample)+2]);
        hold(hUI.ax2, 'off' )
        set(hUI.frame_disp, 'Enable','on')
        set(hUI.slider, 'Enable','on')
        set(hUI.slider,'Min',1)
        set(hUI.slider,'Max', len)
        set(hUI.slider,'Value',1)
        set(hUI.slider,'SliderStep',[1/(len-1), 10/(len-1)])
        set(hUI.load_but,'BackgroundColor',[0.941 0.941 0.941]);
        set(hUI.load_but,'Enable', 'on')
        set(hUI.ch1, 'Enable','on')
        set(hUI.ch2, 'Enable','on')
        set(hUI.ch3, 'Enable','on')
        set(hUI.ch4, 'Enable','on')
        set(hUI.ch5, 'Enable','on')
        set(hUI.ch6, 'Enable','on')
        set(hUI.ch7, 'Enable','on')
        set(hUI.ch8, 'Enable','on')
        set(hUI.ch9, 'Enable','on')
        set(hUI.ch10, 'Enable','on')
        set(hUI.ch11, 'Enable','on')
        set(hUI.ch12, 'Enable','on')
        set(hUI.ch13, 'Enable','on')
        set(hUI.ch14, 'Enable','on')
        set(hUI.ch15, 'Enable','on')
        set(hUI.ch16, 'Enable','on')
        set(hUI.ch17, 'Enable','on')
        set(hUI.ch18, 'Enable','on')
        set(hUI.ch19, 'Enable','on')
        set(hUI.ch20, 'Enable','on')
        set(hUI.ch21, 'Enable','on')
        set(hUI.ch22, 'Enable','on')
        set(hUI.ch23, 'Enable','on')
        set(hUI.ch24, 'Enable','on')
        set(hUI.ch25, 'Enable','on')
        set(hUI.ch26, 'Enable','on')
        set(hUI.ch27, 'Enable','on')
        set(hUI.offset, 'Enable','on')
        set(hUI.zoom_plus, 'Enable','on')
        set(hUI.plot_but,'Enable', 'on')
        ylim_zoom=ylim;
        ylim([ylim_zoom(1) ylim_zoom(2)])
    end


    function slider_callback(~,~)
        
        ncol = round(get(hUI.slider,'Value'));
        set(hUI.frame_disp,'Value',ncol);
        set(hUI.frame_disp,'String',ncol);
        set(hUI.time_disp,'Value',tempo_doppler(ncol));
        set(hUI.time_disp,'String',tempo_doppler(ncol));
        xlim(hUI.ax1, [-2*fs_doppler + ncol-1, 2*fs_doppler + ncol-1]);
        if isempty(index)==0
            [~, sample] =  min(abs(tempo_sig - tempo_doppler(ncol)));
            if get(hUI.offset,'value')
                remove_offset                
            else
                plot(hUI.ax2,tempo_sig,data(index,:));                
            end
            hold
            ylabel('Amplitude [µV]')
            hold(hUI.ax2, 'on' )
            line([tempo_sig(sample), tempo_sig(sample)], ylim(hUI.ax2),'Color','r')            
            xlim(hUI.ax2, [tempo_sig(sample)-2,tempo_sig(sample)+2]);
            hold(hUI.ax2, 'off' )
            if get(hUI.zoom_plus,'value')
                zoom_plus
            end
            ylim([ylim_zoom(1) ylim_zoom(2)])
        end
        
    end


    function frame_disp_callback(~,~)
        
        ncol = round(str2double(get(hUI.frame_disp,'String')));
        set(hUI.frame_disp,'Value',ncol);
        set(hUI.frame_disp,'String',ncol);
        set(hUI.slider,'Value',ncol);
        set(hUI.time_disp,'Value',tempo_doppler(ncol));
        set(hUI.time_disp,'String',tempo_doppler(ncol));
        xlim(hUI.ax1, [-2*fs_doppler + ncol-1, 2*fs_doppler + ncol-1]);
        if isempty(index)==0
            [~, sample] =  min(abs(tempo_sig - tempo_doppler(ncol)));
            if get(hUI.offset,'value')
                remove_offset                
            else
                plot(hUI.ax2,tempo_sig,data(index,:));                
            end
            hold
            ylabel('Amplitude [µV]')
            hold(hUI.ax2, 'on' )
            line([tempo_sig(sample), tempo_sig(sample)], ylim(hUI.ax2),'Color','r')
            xlim(hUI.ax2, [tempo_sig(sample)-2,tempo_sig(sample)+2]);            
            hold(hUI.ax2, 'off' )
            ylim([ylim_zoom(1) ylim_zoom(2)])
            if get(hUI.zoom_plus,'value')
                zoom_plus
            end
        end
        
    end



    function plot_callback(~,~)
        flag=1;
        value = zeros(1,27);
        for i = 1:27
            value(i) = get(hUI.(sprintf('ch%d',i)),'value');
        end
        index = find(value);
        
        if isempty(index)==1
            cla(hUI.ax2)
        elseif isempty(index)==0
            if get(hUI.offset,'value')
                remove_offset                
            else
                plot(hUI.ax2,tempo_sig,data(index,:));               
            end
            hold(hUI.ax2, 'on' )
            line([tempo_sig(sample), tempo_sig(sample)], ylim(hUI.ax2),'Color','r')
            xlim(hUI.ax2, [tempo_sig(sample)-2,tempo_sig(sample)+2]);
            ylabel('Amplitude [µV]')
            hold(hUI.ax2, 'off' )
            ylim_zoom=ylim;
            ylim([ylim_zoom(1) ylim_zoom(2)])
            if get(hUI.zoom_plus,'value')
                zoom_plus
            end
        end
        
    end


    function remove_offset(~,~)
        if (tempo_sig(sample)-2)*fs<1
            plot(hUI.ax2,tempo_sig,data(index,:)-mean(data(index,[1:(tempo_sig(sample)+2)*fs])')');            
        elseif (tempo_sig(sample)+2)*fs>length(data)
            plot(hUI.ax2,tempo_sig,data(index,:)-mean(data(index,[(tempo_sig(sample)-2)*fs:end])')');            
        else
            plot(hUI.ax2,tempo_sig,data(index,:)-mean(data(index,round([tempo_sig(sample)-2:tempo_sig(sample)+2]*fs))')');            
        end
    end

    function zoom_plus(~,~)        
        y=get(findobj(gca,'Type','line'),'Ydata');
        d=[cell2mat(y(2));cell2mat(y(3));cell2mat(y(4))];
        xx=xlim;
        time=(xx(1)*fs:xx(2)*fs);
        d=d(:,time(time>0));
        ylim([min(min( d))-0.1 max(max(d))])
        ylim_zoom = ylim;
    end

end