mp3read and mp3write: listen to your favourite music inside Matlab
Mp3 is probably the most common format to download and listen music. In the recent years many websites has offered free mp3 songs and the compact music format has spread out all over the world. Here we report these great tools from Dan Ellis that will allow you to edit your mp3 files inside Matlab.
MP3 reading and writing
These function, mp3read and mp3write, aim to exactly duplicate the operation of wavread and wavwrite for accessing soundfiles, except the soundfiles are in Mpeg-Audio layer 3 (MP3) compressed format. All the hard work is done by external binaries written by others: mp3info to query the format of existing mp3 files, mpg123 to decode mp3 files, and lame to encode audio files. Binaries for these files are widely available (and may be included in this distribution).
These functions were originally developed for access to very large mp3 files (i.e. many hours long), and so avoid creating the entire uncompressed audio stream if possible. mp3read allows you to specify the range of frames you want to read (as a second argument), and mp3read will construct an mpg123 command that skips blocks to decode only the part of the file that is required. This can be much quicker (and require less memory/temporary disk) than decoding the whole file.
mpg123 also provides for “on the fly” downsampling at conversion to mono, which are supported as extra options in mp3read.
For more information, including advice on handling MP4 files, see http://labrosa.ee.columbia.edu/matlab/mp3read.html
Example usage
Here, we read a wav file in, then write it out as an MP3, then read the resulting MP3 back in, and compare it to the original file.
% Read an audio waveform [d,sr] = wavread('piano.wav'); % Save to mp3 (default settings) mp3write(d,sr,'piano.mp3'); % Read it back again [d2,sr] = mp3read('piano.mp3'); % mp3 encoding involves some extra padding at each end; we attempt % to cut it off at the start, but can't do that at the end, because % mp3read doesn't know how long the original was. But we do, so.. % Chop it down to be the same length as the original d2 = d2(1:length(d),:); % What is the SNR (distortion)? ddiff = d - d2; disp(['SNR is ',num2str(10*log10(sum(d(:).^2)/sum(ddiff(:).^2))),' dB']); % Do they look similar? subplot(211) specgram(d(:,1),1024,sr); subplot(212) plot(1:5000,d(10000+(1:5000),1),1:5000,d2(10000+(1:5000))); % Yes, pretty close % % NB: lame followed by mpg123 causes a little attenuation; you % can get a better match by scaling up the read-back waveform: ddiff = d - 1.052*d2; disp(['SNR is ',num2str(10*log10(sum(d(:).^2)/sum(ddiff(:).^2))),' dB']);
SNR is 21.9693 dB
SNR is 24.0399 dB
External binaries
The m files rely on three external binaries, each of which is available for Linux, Mac OS X, or Windows:
mpg123 is a high-performance mp3 decoder. Its home page is http://www.mpg123.de/ .
mp3info is a utility to read technical information on an mp3 file. Its home page is http://www.ibiblio.org/mp3info/ .
lame is an open-source MP3 encoder. Its homepage is http://lame.sourceforge.net/ .
The various authors of these packages are gratefully acknowledged for doing all the hard work to make these Matlab functions possible.
Installation
The two routines, mp3read.m and mp3write.m, will look for their binaries (mpg123 and mp3info for mp3read; lame for mp3write) in the same directory where they are installed. Binaries for different architectures are distinguished by their extension, which is the standard Matlab computer code e.g. “.mac” for Mac PPC OS X, “.glnx86″ for i386-linux. The exception is Windows, where the binaries have the extension “.exe”.
Temporary files will be written to (a) a directory taken from the environment variable TMPDIR (b) /tmp if it exists, or (c) the current directory. This can easily be changed by editing the m files.
% Last updated: $Date: 2007/02/04 04:12:56 $ % Dan Ellis <dpwe@ee.columbia.edu>
Popularity: 3% [?]
Interfacing MATLAB and EXCEL
The first very basic things you may want to know are how to write and read from an .xls file.
- xlswrite: xlswrite(filename, M) writes matrix M to the Excel file filename. The filename input is a string enclosed in single quotation marks, and should include the file extension. The matrix M is an m-by-n numeric or character array. xlswrite writes the matrix data to the first worksheet in the file, starting at cell A1. For more click here.
- xlsread: num = xlsread(filename) returns numeric data in double array num from the first sheet in the Microsoft Excel spreadsheet file named filename. The filename argument is a string enclosed in single quotation marks. For more click here.
- Sometimes may also be useful the xlsfinfo to determine whether file contains a Microsoft Excel spreadsheet
And if you want to build an external application like a MATLAB made excel add-in you may want to give a look at:
- MATLAB Builder EX 1.2.13 : Deploy MATLAB code as Microsoft Excel add-ins.MATLAB® Builder™ EX lets you integrate MATLAB® applications into your organization’s Excel® workbooks as macro functions or add-ins that can be deployed royalty free. The MATLAB Builder EX product creates the add-ins by encrypting your MATLAB functions, packaging the functions as a DLL that is accessible from Excel, and generating a Microsoft® Visual Basic® for Applications (VBA) wrapper around them.
To edit properties of an xls file:
- Simple Excel sheet editing program: With this program you can edit simple things in an Excel sheet like:
Bold, Fontsize, border, font
To Add a figure into an excel spreadsheet:
- xlswritefig: XLSWRITEFIG allows you to programmatically place a MATLAB figure inside of an Excel spreadsheet. This can be a useful supplement to XLSWRITE.
You may also want a speed up:
- xlsread.m for faster data transfer:This modified version makes the original xlsread.m faster and also allows add-ins to be loaded.
If you are working with temporal data:
- xlsdate.m: converts a MS Excel date to year, month and day
And if you have 3D arrays:
- xlswrite 3D: xlswrite is limited to writing 2D arrays to Excel. This is a simple function that allows you to write 3D arrays to Excel
Ok something is not clear, but don’t worry, here is some tutorial:
- Graphical tutorial: importing data from Excel: This graphical tutorial shows how to bring data in from Excel and create a plot from it. Sample data file is included. Graphical tutorial is done in PowerPoint. Print in color if you can. Right click on the file .PPS to print once downloaded.
- Data Analysis with MATLAB for Excel Users: material from a matlab webinar.
Popularity: 3% [?]
The Future of MATLAB and Mathematical Interpreters – Going Mobile?
MATLAB has existed on the desktop and remains there to this day. However as the popularity of the iPhone and the buzz of the Apple tablet, Andriod phones, etc has pointed out, there are a large number of users who want to migrate to a mobile platform. Will MATLAB? Will any mathematical interpreter?
An interpreter may not seem an obvious choice but I can recall, along with many others, pulling out my calculator frequently during courses and for homework. Recently, I came across the iPhone app, iMathlab, on sale from the app store, and while it’s a light weight version of MATLAB or Octave, it’s a true mathematical interpreter made for a phone! As an engineer I can now make a phone call, plot a normal distribution, generate a random sample and make a histogram of data and then jump back onto my call all in a single device.
While the phone may not the ultimate form factor, it’s simply too small to work for any lengthy period of time, the upcoming tablet does seem to offer a more suitable form for the user who wants to seriously buckle down on their platform for 10 to 20 minutes at a time.
This raises the idea as to where will interpreters migrate in the upcoming years? I, personally, have been wondering when an open source project will migrate to a Google App Engine to take over a server and offer a dynamic interpreter capable of calculating with the vast server resources maintained by Google. Need a small lab comparable to Los Alamos? It’s there waiting for you to tap its potential.
With smart phones, a forthcoming tablet, and other web services taking over a larger and larger segment of the computing world it’s going to be a very interesting and dynamic area of software and services to see where and how any number of mathematical tools move into this area.
Popularity: 4% [?]
Free Sofwares alternative to Matlab
The Mathworks wont like this post
. Matlab is a great tool but it can be too costly for many of us. I show below a few FREE alternatives. They may not be Matlab, but sometimes they are enough.
Scilab
Scilab is a scientific software package for numerical computations providing a powerful open computing environment for engineering and scientific applications.
Scilab is an open source software.
Since 1994 it has been distributed freely along with the source code via the Internet. It is currently used in educational and industrial environments around the world.
Scilab is now the responsibility of the Scilab Consortium, launched in May 2003. There are currently 19 members in Scilab Consortium (Phase II).
Scilab includes hundreds of mathematical functions with the possibility to add interactively programs from various languages (C, C++, Fortran…).
It has sophisticated data structures (including lists, polynomials, rational functions, linear systems…), an interpreter and a high level programming language.
Octave
GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab. It may also be used as a batch-oriented language.
Octave has extensive tools for solving common numerical linear algebra problems, finding the roots of nonlinear equations, integrating ordinary functions, manipulating polynomials, and integrating ordinary differential and differential-algebraic equations. It is easily extensible and customizable via user-defined functions written in Octave’s own language, or using dynamically loaded modules written in C++, C, Fortran, or other languages.
GNU Octave is also freely redistributable software. You may redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation.
Octave was written by John W. Eaton and many others. Because Octave is free software you are encouraged to help make Octave more useful by writing and contributing additional functions for it, and by reporting any problems you may have.
Python
Python is a remarkably powerful dynamic programming language that is used in a wide variety of application domains. Python is often compared to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing features include:
- very clear, readable syntax
- strong introspection capabilities
- intuitive object orientation
- natural expression of procedural code
- full modularity, supporting hierarchical packages
- exception-based error handling
- very high level dynamic data types
- extensive standard libraries and third party modules for virtually every task
- extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
- embeddable within applications as a scripting interface
Popularity: 3% [?]
Coins
Coins
How do you choose the coins in your pocket to pay something? There is an algorithm to use the max numbers of coins? Of course there is, as shown in the book “L’algoritmo del parcheggio” (The parking algorithm) by Prof. Furio Honsell. This GUI help you to choose the exact combination of coins that you have in your pocket to pay the bill.
For example: Suppose you are in Naples (Italy, my city) and have in your pocket this situation. Now you are in “Piazza del Plebiscito” and you want to drink a coffee in the famous “Gambrinus” Bar. You go to the cash, order the coffee and the beautiful cashier give you the sales cash asking 0.80 euro (I wish…). All these coins in your pocket are very heavy to carry, and so you want to give as many as possible coins to the cashier (that will be happiest to have all these coins in the cash to give them as change). The situation can be resumed into a mathematical model:
|
Value (values) |
Quantity (coinsin) |
Total (coinval) |
Cumulative sum (V) |
|
0.01€ |
6 |
0.06€ |
0.06€ |
|
0.02€ |
5 |
0.10€ |
0.16€ |
|
0.05€ |
5 |
0.25€ |
0.41€ |
|
0.10€ |
5 |
0.50€ |
0.91€ |
|
0.20€ |
2 |
0.40€ |
1.31€ |
|
0.50€ |
1 |
0.50€ |
1.81€ |
|
1€ |
1 |
1€ |
2.81€ |
|
2€ |
1 |
2€ |
4.81€ |
|
TOTAL |
26 |
4.81€ |
4.81€ |
The bill to pay is stored into the T variable. As you can see, it is possible to us all coins less than 0.20€ to pay the bill. But what is the most efficient methods?
1 2 3 4 5 6 7 8 | while T>0 %saddle the cashier with coins V0=find(V>T,1,'first'); %find the first value in the V array greater than T coinsout(V0)=coinsout(V0)+1; %give the coin to the cashier coinsin(V0)=coinsin(V0)-1;%this coin is no more in your pocket coinval(V0)=coinval(V0)-values(V0); %update the array V=cumsum(coinval); %update the array T=T-values(V0); %update the bill to pay end |
But is it truly so simple? No, of course. The floating point representation of cents sometimes creates troubles: for example: 1.0000-1 could not be 0 but 1.45782e-17 (that is >0…. ). To fix this problem, multiply (and after divide before printing results) by 100: values, coinval and T.
Finally, this is the result:
If any problems occurs in execution, or if you found a bug, have a suggestion or question just contact me at: giuseppe dot cardillo-edta at poste dot it
You can visit my homepage http://home.tele2.it/cardillo
My profile on XING http://www.xing.com/go/invita/13675097
My profile on LinkedIN http://it.linkedin.com/in/giuseppecardillo
Download Now
Popularity: 1% [?]






















































