sonify
Description
sonify(
converts the numeric data
specified in yData
)yData
into sound and provides immediate playback
capabilities.
sonify(___,
specifies
additional options using one or more name-value arguments.Name=Value
)
[
returns the sonified audio samples sonifiedData
,Fs
] = sonify(___)sonifiedData
and the sample rate
Fs
.
Examples
Sonify Data
Load the co2emission.mat
file. This file contains the data set for carbon dioxide emission data from 1949 to 2022. Download the file attached with this example.
load co2emission.mat
Sonify the carbon dioxide emission data. The sound plays once you run this command.
sonify(co2);
Sonify Data and Save to Audio File
Load the co2emission.mat
file. This file contains the data set for carbon dioxide emission data from 1949 to 2022. Download the file attached with this example.
load co2emission.mat
Sonify carbon dioxide data in the frequency range of 1000 to 3000 Hz. Play the generated sound for 5 seconds and return the sonified data and the sampling frequency.
[sonifiedData,Fs] = sonify(co2,'FrequencyRange',[1000,3000],'Playback',true,'Duration',5);
Write the sonified data and the sampling rate to an audio file by using the audiowrite
function. The function saves the file in the current folder.
audiowrite("sonifiedOutput.wav",sonifiedData,Fs);
Sonify Nonuniform Data
Load the sample data set population.mat
. The data set contains nonuniform population data for years 1949 to 2024 where the data for some of the years is missing. Download the file attached with this example.
load population.mat
Sonify the year and population values. The sound plays once you run this command.
sonify(year,population);
Sonify Nonuniform Data and Control Audio
Load the sample data set population.mat
. The data set contains nonuniform population data for years 1949 to 2024 where the data for some of the years is missing. Download the file attached with this example
load population.mat
Sonify the year and population values in the frequency range of 1000 Hz and 2000 Hz. Disable automatic playback and set the duration of the generated sound to 10 seconds. Return the sonified data and the sampling frequency.
[sonifiedData,Fs] = sonify(year,population,'FrequencyRange',[1000,2000],'Playback',false,'Duration',10);
Create an audioplayer object with the sonified data and the sampling frequency.
playerObj = audioplayer(sonifiedData,Fs);
Play audio from the audioplayer
object for 2 seconds.
play(playerObj); pause(2);
Pause playback of the audioplayer
object for 2 seconds.
pause(playerObj); pause(2);
Resume playback of the audioplayer
object and play for 2 seconds.
resume(playerObj); pause(2);
Stop playback of the audioplayer
object.
stop(playerObj);
Input Arguments
yData
— Data for sonification
scalar | vector
Data for sonification, specified as a scalar or a vector. You can sonify the data based on parameters such as FrequencyRange, Playback, and Duration.
Example: sonify(yData)
Data Types: double
xData
— Data corresponding to time, sequence, or spatial positioning of yData
scalar | vector
Data corresponding to time, sequence, or spatial positioning of
yData
, specified as a scalar or a vector. The values in xData must
be real and monotonically increasing and they can increase uniformly or
nonuniformly.
Example: sonify(xData, yData);
Data Types: double
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: sonify(xData, yData,'FrequencyRange', [600,1800])
FrequencyRange
— Frequency range
[392,1397] (default) | two-element vector
Frequency range to which you want to map your input data, specified as a two-element vector. You can set the frequency range between 16 Hz to 4095 Hz.
Example: sonify(xData, yData,'FrequencyRange', [600,1800])
Data Types: double
Playback
— Stop or play sonified data
true
or 1
(default) | false
or 0
Stop or play sonified data, specified as a numeric or logical 1
(true
) or 0
(false
).
Example: sonify(xData, yData,'Playback', true)
Data Types: logical
Duration
— Duration of playback in seconds
6 (default) | positive integer
Duration of playback in seconds, specified as a positive integer.
Example: sonify(xData, yData,'Duration', 10)
Data Types: double
Output Arguments
sonifiedData
— Sonified audio samples
numeric vector
Sonified audio samples, returned as a numeric vector.
Fs
— Sample rate
scalar
Sample rate, returned as 8192 Hertz (Hz).
Note
You can use the sonifiedData and Fs outputs with
the audioplayer
object to play, pause, resume,
and stop the sound. You can write the sonified data to a .wav
file by
using the audiowrite
function.
Version History
Introduced in R2024b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)