How to create sound with variable pitch?

1 view (last 30 days)
Brian Bock
Brian Bock on 25 Apr 2017
Answered: Walter Roberson on 25 Apr 2017
I have an m-1 array of frequencies that I'd like Matlab to play back as one continuous tone of varying pitch. I do not want all the sounds to play at once - rather I want a tone that changes pitch. sound() doesn't want to accept an array for Fs. I tried iterating through a loop but the resulting audio is staccato and choppy, not continuous.

Answers (1)

Walter Roberson
Walter Roberson on 25 Apr 2017
You need to resample each of them into a single common frequency (use the highest frequency) and then put all of those results together and play it at one time.
t = linspace(0, 20, 5000);
t(end) = []; %remove final return to 0 so it is periodic
s = sin(t*2*pi);
max_freq = max(m);
b = [];
for freq = 1 : length(m)
b = [b, resample(s, max_freq, freq)];
end
sound(b, max_freq)
Or something like that.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!