View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

5.0 | 5 ratings Rate this file 4 Downloads (last 30 days) File Size: 2.7 KB File ID: #11441 Version: 1.0



Alan Tan (view profile)


16 Jun 2006 (Updated )

This function plays musical tunes. Write your own musical tune and call the function to play it.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

This function plays musical tunes. Write your own musical tune and call the function to play it.
[CDEFGAB] keys, 5 full octaves
[12345678] key/rest duration, with the default [1] semiquaver, [2] quaver, [4] crochet and [8] minim
[#] sharp / [b] flat / [.] rest / [^] raise octave / [_] lower octave

The musical scores for Canon in D (Pachelbel), Prelude No 1 (Bach), The Globe Trotter and Fantasie Impromptu (Chopin) are also attached.

Essential files: playtune.m
Accompanying files: canon_in_d.m, prelude_no_1.m, the_globe_trotter.m, fantasie_impromptu.m

MATLAB release MATLAB 5.3.1 (R11.1)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
02 Aug 2011 Chihiro  
26 Oct 2008 Ameya Deoras

Ameya Deoras (view profile)

18 Apr 2007 Ruoting Yang  
20 Sep 2006 S Murphy  
29 Jun 2006 Alan Tan

Hi John, I've taken your advice and added some examples and included the notation (above) in the help of playtune.

Comment only
28 Jun 2006 John D'Errico


I do wish the author had included a bit more help with playtune. For example, the notation is described in the website description, but not in the help for playtune. (Please fix this!) I've rated it a 5 anyway.

20 Jun 2006

Edited the function for a more natural sounding tone.

21 Jun 2006

Added residual phase to generating signals.

22 Jun 2006

Added the musical score of Prelude No 1 by Bach.

27 Jun 2006

Enabled customizable tone generator; at the same time, set the lowest note to C(-2), i.e., two octaves below the middle C of the piano. Also added a new musical score "The Globe Trotter" which plays both right and left hands.

27 Jun 2006

Tidied up the codes.

28 Jun 2006

Edited description.

29 Jun 2006

Added additional help and examples in playtune.

31 Mar 2016 1.0

Added BSD license.

Contact us