/**
	Program: 		Data Processing
	@author: 		André Perez
	Contact: 		andre_mperez@hotmail.com
	Last Modified: 		18 October 2015
*/

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class DataProcessing {
	
	// Static Fields
	
	private int dataCounter=0;
	private int samplingRate;
	private int audioLength=300;
	
	public double[] originalData;
	public double[] modifiedData;
	
	// Constructors
	
	DataProcessing(){
				
	}
	
	// Setter and Getter Methods
	
	public int GetDataCounter(){
		
		return this.dataCounter;
	}
	
	public int GetSamplingRate(){
		
		return this.samplingRate;
	}
	
	public void GetDataParameters(){
		
		Scanner fileInput = null;
		try{
			
			fileInput = new Scanner(new FileInputStream("originalData.txt"));
		}
		catch(FileNotFoundException e){
			
			System.out.println("SR: File not found !");
			System.exit(0);
		}		
		
		while(fileInput.hasNextLine()){
			
			fileInput.nextLine();
			this.dataCounter++;
		}
		
		fileInput.close();
		this.samplingRate = this.dataCounter / this.audioLength;
	}
	
	public void GetDataFromFile(){
		
		Scanner fileInput = null;
		this.originalData = new double[this.dataCounter];
		this.modifiedData = new double[this.dataCounter];
		try{
			
			fileInput = new Scanner(new FileInputStream("originalData.txt"));
		}
		catch(FileNotFoundException e){
			
			System.out.println("GETDATA: File not found !");
			System.exit(0);
		}
		
		for(int i=0 ; i<dataCounter ; i++){
			
			this.originalData[i] = fileInput.nextInt();
			if(fileInput.hasNextLine()){
				
				fileInput.nextLine();
			}
		}
		
		fileInput.close();
	}
	
	// Methods

	public double[] NormalizeData(double[] modifiedArray, double[] originalArray){
		
		double max = Double.MIN_VALUE;
		for(int i=0 ; i<this.dataCounter ; i++){
			
			if(Math.abs(originalArray[i])>max){
				
				max = Math.abs(originalArray[i]);
			}
		}
		
		for(int i=0 ; i<this.dataCounter ; i++){
			
			modifiedArray[i] = modifiedArray[i] / max;
		}
		
		return modifiedArray;
	}
	
	public void PutDataFile(double[] dataArray, String fileName){
		
		PrintWriter fileOutput = null;
		try{
			
			fileOutput = new PrintWriter(new FileOutputStream(fileName));
		}
		catch(FileNotFoundException e){
			
			System.out.println("PUTDATA: File not found !");
			System.exit(0);
		}
		
		for(int i=0 ; i<this.dataCounter ; i++){
			
			fileOutput.println(dataArray[i]);
		}
		
		fileOutput.close();
	}
}

@@ -8,17 +8,16 @@
 ogram: %09
-%09
 Data Pro
@@ -33,18 +33,16 @@
 @author:
- %09
 %09Andr%C3%A9 P
@@ -61,33 +61,34 @@
 t: %09
-%09andre_mperez@hotmail.com
+2221166p@student.gla.ac.uk
 %0A%09La
@@ -101,17 +101,16 @@
 ified: %09
-%09
 18 Octob

Update DataProcessing.java