
# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
#***********************************************************************
# LOAD LIBRARIES
#***********************************************************************
library(fastICA)
library(plotly)
library(mAr)
library(shiny)

#***********************************************************************
# DATA REQUIRED
#***********************************************************************
names = c("sinusoidal","triangular","rectangular","random","wave1","wave2")

#***********************************************************************
# USER INTERFACE FUNCTION
#***********************************************************************
shinyUI(fluidPage(

  # Application title
  titlePanel("Independent Component Analysis"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      p("This example shows how Indipendent Component Anlysis works. We can select 6 types of sources and then 
         we generate a recorded signal based on both sources selected using a linear combination of sources called W (matrix of weights, 2x2 matrix).
        Secondly we add a white noise according to certain noise standard deviation that we can shoose in the sliderbar
        FastICA is the algorithm to differentiate both sources. The input of this is the recorded signal + noise"),
      p("Choose first source"),
      selectInput('source1', 'Choose source 1 (s1)', names,selected = names[1]),
      p("Choose second source"),
      selectInput('source2', 'Choose source 2 (s2)', names,selected = names[2]),
      p("Noise Standard deviation"),
      sliderInput("sd", "Noise standard deviation :", min = 0, max = 0.5, value = 0.05),
      p("In signal processing, independent component analysis (ICA)
         is a computational method for separating a multivariate signal
         into additive subcomponents. This is done by assuming that the
         subcomponents are non-Gaussian signals and that they are statistically 
         independent from each other. ICA is a special case of blind source separation.
         A common example application is the cocktail party problem of listening in on one
         person's speech in a noisy room")
    ),
    # Show a plot of the generated distribution
    mainPanel(
      plotlyOutput("OriginalSources"),
      plotlyOutput("RecordedSignals"),
      plotlyOutput("ICASources")
    )
  )
))
