http://www.people.fas.harvard.edu/~phuybers/Mfiles/index.html
Matlab Scripts
Multi-taper spectral analysis
pmtmPH.m (requires the signal toolbox for Matlab)
Note the Matlab pmtm.m routine computes inaccurate error estimates due to problems in the chi2conf subroutine and
the assumed number of degrees of freedom. This script uses a fast approximation to compute the 95% confidence limits
for a chi-squared distribtution and computes the equivalent degrees of freedom [see Percival and Walden, 1993, p256 and p370].
Multi-taper coherence analysis
cmtm.m (requires the signal toolbox for Matlab and the below routines)
cohconf.m (calculates confidence levels)
cohbias.m (corrects for the bias ineherent to coherence estimates)
cohbias.mat (used with cohbias.m)
These files allow for the estimation of coherence and phase using the mult-taper method with adaptive weigthing.
Note: Coherece is returned, not coherence-squared, as with the Matlab cohere.m function. Also, the confidence
interval for both coherence and phase is estimated along with an option to plot the results.
Some simple demonstrations of spectral analysis procedures and some other related material: demonstration scripts.
Some supporting files from the below toolbox may be neccessary.
An assortment of matlab functions are also available: toolbox.
Tuesday, November 29, 2011
Wednesday, November 16, 2011
Tuesday, November 15, 2011
Multivariate Analysis Toolbox for Matlab®
Multivariate Analysis Toolbox for Matlab®:
http://carmelab.huji.ac.il/software/MVA/mva.html
http://carmelab.huji.ac.il/software/MVA/mva.html
Multivariate Analysis Toolbox for Matlab®
written by: Liran Carmel
Last modified: 13:14, Mon 13-Sep-2010
We have tried to break down a typical process of multivariate data analysis, in trying to identify key components. We then built a fully object-oriented toolbox, with an object fitting each of those key components.
Data objects. We have identified three entities, which are the building blocks of any multivariate data process. The samplesetobject carries information about the different samples, also called observations, conditions, or experiments. grouping object carries information about labeling of the samples, i.e., their association with specific clusters. The measurements themselves are in a datamatrix. The datamatrix object is the general framework of a datamatrix, from which more specialized data matrices are derived by object-oriented inheritence. These more specialized data matrices encompass most of the data organization forms one may encounter. The vsmatrix object describes a rectangular two-way matrix of variables-by-samples. For example, a result of a gene array experiment in the form of genes-by-conditions will be represented in our toolbox by a vsmatrix object. The ssmatrix object describes relationships between samples. For example, a distance matrix will be represented in our toolbox as a ssmatrix. Thevvmatrix object describes relationships between variables. For example, a correlation matrix will be represented in our toolbox as a vvmatrix.
Graph theory. The graph object describes a general mathematical graph. This toolbox includes more specific graphs (such asdigraphs and trees) that are derived from this general object.
Pairwise data objects. These objects describe specific forms of pairwise data, and are all derived from either ssmatrix orvvmatrix (see above). The covmatrix object describes a covariance or a correlation matrix. The distmatrix object describes a distance matrix. The dissimatrix and simatrix objects describe pairwise dissimilarity or similarity information, respectively.
Dimensionality reduction algorithms. Each object in this group stands for a particular dimensionality reduction technique. Currently available are pcatrans that makes principal component analysis (PCA), wpcatrans that makes weighted principal component analysis (wPCA), and fishtrans that identifies discriminant direction according to the Fisher linear discriminant analysis.
Statistics. This portion of the toolbox includes general statistical functions, mainly various hypothesis testing procedures, as well as the object ctable that describes a contingency table.
Navigate to: General Description List of Objects List of Functions Download
Data objects. We have identified three entities, which are the building blocks of any multivariate data process. The samplesetobject carries information about the different samples, also called observations, conditions, or experiments. grouping object carries information about labeling of the samples, i.e., their association with specific clusters. The measurements themselves are in a datamatrix. The datamatrix object is the general framework of a datamatrix, from which more specialized data matrices are derived by object-oriented inheritence. These more specialized data matrices encompass most of the data organization forms one may encounter. The vsmatrix object describes a rectangular two-way matrix of variables-by-samples. For example, a result of a gene array experiment in the form of genes-by-conditions will be represented in our toolbox by a vsmatrix object. The ssmatrix object describes relationships between samples. For example, a distance matrix will be represented in our toolbox as a ssmatrix. Thevvmatrix object describes relationships between variables. For example, a correlation matrix will be represented in our toolbox as a vvmatrix.
Graph theory. The graph object describes a general mathematical graph. This toolbox includes more specific graphs (such asdigraphs and trees) that are derived from this general object.
Pairwise data objects. These objects describe specific forms of pairwise data, and are all derived from either ssmatrix orvvmatrix (see above). The covmatrix object describes a covariance or a correlation matrix. The distmatrix object describes a distance matrix. The dissimatrix and simatrix objects describe pairwise dissimilarity or similarity information, respectively.
Dimensionality reduction algorithms. Each object in this group stands for a particular dimensionality reduction technique. Currently available are pcatrans that makes principal component analysis (PCA), wpcatrans that makes weighted principal component analysis (wPCA), and fishtrans that identifies discriminant direction according to the Fisher linear discriminant analysis.
Statistics. This portion of the toolbox includes general statistical functions, mainly various hypothesis testing procedures, as well as the object ctable that describes a contingency table.
Navigate to: General Description List of Objects List of Functions Download
Core objects:
- grouping
- labeling of the data according to a classification scheme
- sampleset
- information about samples (observations, conditions, experiments)
- variable
- information about variables (features, coordinates)
Core data objects:
- datamatrix
- a two-way matrix object
- dataset
- repository of information regarding a certain dataset
- graph
- general undirected graph
Pairwise data objects:
- covmatrix
- covariance matrix (inherits vvmatrix)
- dissimatrix
- dissimilarity matrix (inherits ssmatrix)
- distmatrix
- distance matrix (inherits ssmatrix)
- simatrix
- similarity matrix (inherits ssmatrix)
Dimensionality reduction algorithms:
- lintrans
- general dimensionality reduction by linear transformation
Statistics:
- ctable
- contingency table
Combinatorics:
- multinom
- computes the multinomial coefficient.
Data manipulations:
- lineup
- ranks a vector in increasing order.
- majority
- finds the most frequent entry.
- subs_incomp_data
- substitue given data in an incompleted data array
- subsample
- picks up at random a subsample of a vector.
- substitute
- substitutes values in a list with a different set of values.
Graph Theory:
- chowliu
- applies the Chow-Liu algorithm.
- code2dag
- finds the DAG associated with a DAG-code.
- code2rank
- finds the rank of a DAG-code.
- dispdagcode
- displays a DAG code to the screen.
- enumdagcodes
- enumerates all DAG codes for a fixed number of nodes.
- enummarkovclasses
- enumerates all DAG codes for a fixed number of nodes.
- nodags
- computes the number of DAGs with fixed number of nodes.
- rank2code
- finds the DAG-code whose rank is {r}.
- thd2wgt
- computes, given THD, a default weight matrix.
- wgt2thd
- computes, given weights, a default THD matrix.
Grouping:
- group
- turns a list into assignment vector and naming cell array.
Hypothesis testing:
- testbinom
- computes the p-value of testing a binomial parameter.
- testchi2hist
- uses the chi2 test to compare a histograms to a standard.
- testchi2hists
- uses the chi2 test to compare two histograms.
- testchi2independence
- computes the p-value of independence hypothesis.
- testfisherexact
- computes the p-value of Fisher's exact test (© A. Trujillo-Ortiz et al.).
- testfisheromnibus
- computes p-value for the Fisher Omnibus test.
- testkshist
- uses KS test to compare a histograms to a standard.
- testkshists
- uses KS test to compare two histograms.
- testmultinom
- computes the p-value of testing multinomial parameters.
Information Theory:
- centropy
- computes the conditional entropy between two variables.
- emutualentropy
- estimates pairwise mutual entropy
- entropy
- computes the entropy of a distribution.
- kdiv
- computes the K-divergence between distributions p and q.
- kl
- computes the relative entropy.
- ldiv
- computes the L-divergence between distributions p and q.
Linear transformations:
- fa_engin
- performs factor analysis on the data.
- factorscores
- estimate the scores after factor analysis.
- fish_engin
- performs Fisher transformation of a grouped dataset.
- pca_engin
- performs PCA analysis on the data.
Pairwise Relationships:
- distmat
- calculates distance matrix.
Regression analysis:
- regress1d
- linearly regress one variable on another.
Statistics:
- allstats
- computes all common statistics (© D.C. Hanselman).
- fdr
- calculates
- kendall
- computes the Kendall rank correlation matrix.
- pearson
- computes the Pearson (linear) correlation matrix.
- spearman
- computes the Spearman rank correlation matrix.
Visualization:
- scatter2d_engin
- the engine used for 2D scatter plots.
- scatter3d_engin
- the engine used for 3D scatter plots.
Sunday, November 13, 2011
Speech Enhancement Using Kalman Filter
http://dea.brunel.ac.uk/cmsp/Home_Esfandiar/KalmanTime.htm
It is assumed that speech signal is stationary during each frame, that is, the AR model of speech remains the same across the segment. To fit the one-dimensional speech signal to the state space model of Kalman filter we introduce the state vector as:
Clean Noisy Restored
An implementation of this method in Matlab may be downloaded here. You will also need to download this toolbox which contains files used in the m file. Note that in this implementation you need to provide the clean signal to the function as well as the noisy signal.
Home
Speech Enhancement Using Kalman Filter (Time Domain Approach)
The use of Kalman Filter for speech enhancement in the form that is presented here was first introduced by Paliwal (1987) [3]. This method however is best suitable for reduction of white noise to comply with Kalman assumption. In deriving Kalman equations it it normally assumed that the process noise (the additive noise that is observed in the observation vector) is uncorrelated and has a normal distribution. This assumption leads to whiteness character of this noise. There are, however, different methods developed to fit the Kalman approach to colored noises [4].It is assumed that speech signal is stationary during each frame, that is, the AR model of speech remains the same across the segment. To fit the one-dimensional speech signal to the state space model of Kalman filter we introduce the state vector as:
x(k)=[x(k-p+1) x(k-p+2) x(k-p+3) ... x(k)]T (1)
where x(k) is the speech signal at time k. Speech signal is contaminated by additive white noise n(k):
y(k)=x(k)+n(k) (2)
The speech signal could be modelled with an AR process of order p.
x(k)=Σaix(k-i) + u(k) i=1...p (3)
where ai's are AR (LP) coefficients and u(k) is the prediction error which is assumed to have a normal distribution ~N(0,Q). substituting equation 1 into equation 3 we get:x(k)=Ax(k-1)+Gu(k) (4)
where,
G=[0 0 ... 0 1]T
G has a length of p (LP order). and the observation equation would be:
y(k)=Hx(k)+n(k) (5)
H=GT
n(k) as stated earlier has a Gaussian distribution ~N(0,R). The rest of the formulation for this filter is the same as general case.
There are several methods for extraction of LP model parameters from noisy data [5]. In this demonstration however, These parameters are assumed to be given so that we can assess the potential of Kalman Filter for speech enhancement without worrying about the extraction of these parameters and the effect of this error on the system. Other methods try to calculate the LP model parameters first and then use them for de-noising the speech signal or iteratively estimate and correct these values and enhance the speech (EM algorithm). a pre-cleaning block may also be used to extract an estimate of these values (like simple spectral subtraction methods). The initial value for x is the noisy data providing the a posteriori estimate error covariance matrix with diagonal value of R. The LP coefficients are calculated for segments that might or might not be overlapping. In the latter case special care should be taken to guarantee the continuity of the filter parameters (e.g. make sure you store filter parameters midway the segment where you are going to start your next segment filtering, so that you can use these values when going to next segment). It was mentioned in [3]that the use of x(k-p+1) calculated at time k would result in better performance relative to the value that was filtered for the first time (e.g. x(k-p+1) calculated at time k-p+1) since more information is incorporated for in calculating this value. This implementation results in a delayed Kalman filter.
Figure 1. a sample output of the Kalman filter, input SNR=0dB. A complete sentence (left) and a vowel section for detailed resolution (right)
you can also listen to this sample file bu clicking on the links below:Clean Noisy Restored
An implementation of this method in Matlab may be downloaded here. You will also need to download this toolbox which contains files used in the m file. Note that in this implementation you need to provide the clean signal to the function as well as the noisy signal.
Home
Saturday, November 12, 2011
Thursday, November 10, 2011
g++ TUTORIAL
http://www.vietspring.org/cpp_linux/gpp.html
g++ TUTORIAL
g++ is known as a compiler, a program that will take your C++ source code and compile it into a binary file that can be executed to actually run your program. This page will give you the basics on how to take a source code file and compile it into an executable, as well as show you some of the options you have when you compile a source code file.
HOW TO COMPILE A SOURCE CODE FILE
To compile your source code, you must first reside in the directory that your source code files are in. For example, if you wanted to compile the file ~/projects/proj2/proj2.cc, you must first change directories to ~/projects/proj2 using the cd command. (If you need more information on basic Linux commands, go to the Linux Commands tutorial.)
Once you are in the correct directory, compile the source code in the file proj2.cc by typing the following command at the xterm prompt:
g++ proj2.cc
This is the most basic way to compile your source code. After you type this command, 1 of 2 things will happen. Either your source code will be without error and the exectuable will be written, returning you back to the command prompt:
OR your code will have a few errors in it and a display of the errors will be shown:
in which case no executable file will be written and you will be returned to your command prompt.
For now, let's assume that your source code had no errors in it. Using the command above, an executable file will be created in the current directory called a.out. To actually run the program, simply type at the command prompt ./a.out:
(Note that if you have "." added to your PATH environment you do not need the ./ in front of a.out.)
g++ FLAG OPTIONS
g++ allows for options to be flagged when you compile your source code. This discussion will show how to use 3 of them: -g, -Wall, and -o .
-g
To use the -g flag, simply type it in after g++ and before your source code file:
g++ -g source_file.cc
What the -g option will do is allow the executable file to be "debugged" using the GDB debugger. For a quick tutorial on the GDB debugger, click on the GDB link to the left.
-Wall
To use the -Wall flag, type it in just as you did with -g flag:
g++ -Wall source_file.cc
What the -Wall flag will do is show ALL the warning messages you may get that describe possible errors in your source code. If warnings are the only messages you receive when you compile your source code, and executable will still be created. Only if there are ERROR messages will an executable not be created. However, many professors in the Department will deduct points if your source code produces warnings when compiled.
-o
The -o flag is one of the more useful ones. This flag will allow you to rename the executable file from something other than a.out. To use the -o option, place it after the source code file, followed by the name you wish to give the executable. For example, to compile a source code file named proj2.cc into an executable file called proj2.exe, type the following command:
g++ proj2.cc -o proj2.exe
Doing so will create the executable proj2.exe that you would type at the command prompt to run your program.
It is possible to use more than one flag at once when you compile. For example, let's say you entered the following g++ command:
g++ -g -Wall proj2.cc -o proj2
This command will compile the source code file proj2.cc such that the executable will be able to be used with the GDB debugger (-g), will show all warning messages when compiled (-Wall), and will create the executable into a file called proj2 (-o proj2).
COMPILING MUTLIPLE-FILE PROGRAMS
g++ also allows you to compile a program that is contained in multiple files and create a single executable. To do so, simply list all the source code files one after the other, like so:
g++ source_file_1 source_file_2 source_file_3...
For example, let's say that you have a program contained in 3 files: proj2.cc contains the main() function and is the backbone of your program, functions.h contains the prototypes for functions that your program uses, and functions.cc contains the implementations for those functions. To compile these 3 files into one executable, type at the prompt:
g++ functions.cc proj2.cc
The above command will then compile the two source files and create one executable a.out.
NOTE - YOU DO NOT PUT ANY .h FILES IN THE g++ COMMAND! DOING SO WILL GIVE ERRORS!
Also, just like you would with single-file programs, you can add options flags when you compile:
g++ -g -Wall functions.cc proj2.cc -o proj2
This command will compile the two source files functions.cc and proj2.cc so that the executable can be used with the GDB debugger (-g), all compilation warnings will be displayed (-Wall), and the executable file will be called proj2 (-o proj2).
Of course, g++ has more functionality than what is described in this tutorial. To see a full listing of g++ commands, type at the command prompt:
man g++
to load up the "man" (manual) page for g++.
g++ is known as a compiler, a program that will take your C++ source code and compile it into a binary file that can be executed to actually run your program. This page will give you the basics on how to take a source code file and compile it into an executable, as well as show you some of the options you have when you compile a source code file.
HOW TO COMPILE A SOURCE CODE FILE
To compile your source code, you must first reside in the directory that your source code files are in. For example, if you wanted to compile the file ~/projects/proj2/proj2.cc, you must first change directories to ~/projects/proj2 using the cd command. (If you need more information on basic Linux commands, go to the Linux Commands tutorial.)
Once you are in the correct directory, compile the source code in the file proj2.cc by typing the following command at the xterm prompt:
This is the most basic way to compile your source code. After you type this command, 1 of 2 things will happen. Either your source code will be without error and the exectuable will be written, returning you back to the command prompt:
OR your code will have a few errors in it and a display of the errors will be shown:
in which case no executable file will be written and you will be returned to your command prompt.
For now, let's assume that your source code had no errors in it. Using the command above, an executable file will be created in the current directory called a.out. To actually run the program, simply type at the command prompt ./a.out:
(Note that if you have "." added to your PATH environment you do not need the ./ in front of a.out.)
g++ FLAG OPTIONS
g++ allows for options to be flagged when you compile your source code. This discussion will show how to use 3 of them: -g, -Wall, and -o .
-g
To use the -g flag, simply type it in after g++ and before your source code file:
What the -g option will do is allow the executable file to be "debugged" using the GDB debugger. For a quick tutorial on the GDB debugger, click on the GDB link to the left.
-Wall
To use the -Wall flag, type it in just as you did with -g flag:
What the -Wall flag will do is show ALL the warning messages you may get that describe possible errors in your source code. If warnings are the only messages you receive when you compile your source code, and executable will still be created. Only if there are ERROR messages will an executable not be created. However, many professors in the Department will deduct points if your source code produces warnings when compiled.
-o
The -o flag is one of the more useful ones. This flag will allow you to rename the executable file from something other than a.out. To use the -o option, place it after the source code file, followed by the name you wish to give the executable. For example, to compile a source code file named proj2.cc into an executable file called proj2.exe, type the following command:
Doing so will create the executable proj2.exe that you would type at the command prompt to run your program.
It is possible to use more than one flag at once when you compile. For example, let's say you entered the following g++ command:
This command will compile the source code file proj2.cc such that the executable will be able to be used with the GDB debugger (-g), will show all warning messages when compiled (-Wall), and will create the executable into a file called proj2 (-o proj2).
COMPILING MUTLIPLE-FILE PROGRAMS
g++ also allows you to compile a program that is contained in multiple files and create a single executable. To do so, simply list all the source code files one after the other, like so:
For example, let's say that you have a program contained in 3 files: proj2.cc contains the main() function and is the backbone of your program, functions.h contains the prototypes for functions that your program uses, and functions.cc contains the implementations for those functions. To compile these 3 files into one executable, type at the prompt:
The above command will then compile the two source files and create one executable a.out.
NOTE - YOU DO NOT PUT ANY .h FILES IN THE g++ COMMAND! DOING SO WILL GIVE ERRORS!
Also, just like you would with single-file programs, you can add options flags when you compile:
This command will compile the two source files functions.cc and proj2.cc so that the executable can be used with the GDB debugger (-g), all compilation warnings will be displayed (-Wall), and the executable file will be called proj2 (-o proj2).
Of course, g++ has more functionality than what is described in this tutorial. To see a full listing of g++ commands, type at the command prompt:
to load up the "man" (manual) page for g++.
Saturday, November 5, 2011
Speedup tricks
Speedup tricks: "tic
B = zeros(30000,1); % Preallocate B with the zeros command.
for i = 1:30000
B(i) = i;
end
with = toc
ratio = without / with"
'via Blog this'
B = zeros(30000,1); % Preallocate B with the zeros command.
for i = 1:30000
B(i) = i;
end
with = toc
ratio = without / with"
'via Blog this'
Thursday, November 3, 2011
Subscribe to:
Posts (Atom)