Audio Pitch Manipulation Through Time

Dear Community, I recently discovered the possibility to manipulate the pitch of a sine wave by changing the time interval values before the creation (y=sin(2*pi*f*t)) For my new project I would need to manipulate the pitch of an imported audio file in the same way but I can not figure out how to achieve it. Any help is very much appreciated! Thanks!

 Accepted Answer

I am not certain what you want to do. One option could be the resample: function.

6 Comments

The goal is to get a usable portamento transition between 2 notes. I will check out the resample function further tomorrow thanks for the tip!
The resample function will upsample or downsample the signal by a specific amount. It can also produce a new time vector, however the new time vector is not required. Playing the resampled signal at a specific sampling frequency supplied as an argument to the audioplayer or sound functions will change the pitch, as will supplying a different value for the sampling frequency without altering the file itself.
I just read my first post again and would like to explain it better. If the sampling interval is dt=1/44100 (= 0.00002267…) and I create a time axis like t=0:dt:12-dt, it is possible to change the frequency of a 220 to 440 sine wave by changing the interval to 0.00004535 (0.00002267 / 220 * 440). It is possible to get bends or portamentos by changing only the intervals over time. I would like to do the same manipulation on an imported complex audio file. I imagine there must be a deconstruction and insertion of a new timeline. I tried resample but could not get usable results. Thanks again!
The sampling frequency (and the sampling intervals) must be constant, however it is possible to interpolate the dignal to a new sampling frequency, and also possible to simply change the sampling frequency argument to the sound or audioplay functions to change the frequency of the reproduced recording.
To the best of my knowledge, there is no way to change the sampling frequency within the recording, at least smoothly, although it may be possible to resample sections of the recorded sound vector and then concatenate the results of the different resampled vectors. The effect would be apparent when the complete vector (or matrix) was played at a single sampling frequency.
I think you are right! Thanks for your help Star Strider!
As always, my pleasure!
EDIT — (3 Oct 2022 at 15:12)
Thinking about this further, while the sampling frequency must be kept constant, the intervals in the time vector used to create a specific sound does not.
Example —
Fs = 44100;
t = linspace(0, 3*Fs-1, 3*Fs).'/Fs; % Original Time Vector (Column Vector)
s = @(t) sin(2*pi*t*1000); % Original Sound Function
ts = 0.75*exp(-(t-1.5).^2*25); % 'Warped' Time Vector
th = hypot(t,ts); % Sampling Times Of 'Warped' Time Vector
figure
plot(t,th)
grid
xlabel('Time')
ylabel('Warped Time')
figure
plot(t,s(t))
grid
xlabel('Time')
ylabel('Amplitude')
title('Original Tone')
figure
plot(t,s(th))
grid
xlabel('Time')
ylabel('Amplitude')
title('''Warped'' Tone')
sound(s(t),Fs)
pause(3)
sound(s(th),Fs)
The sampling intervals must be monotonically increasing, and the sound function assumes that they are regularly-spaced, so varying the time intervals (created by taking the hypotenuse of the ‘warped’ time vector) used to calculate the tone frequency causes the frequency to change when the sound is played back. This example uses a Gaussian function to warp the time vector, however any continuouis function will likely work. (Discontinuous functions would create a ‘popping’ sound at the discontinuities, so I do not recommend them.)
.

Sign in to comment.

More Answers (1)

you can use shiftPitch for this:
%Read in an audio file and listen to it.
[audioIn,fs] = audioread('Counting-16-44p1-mono-15secs.wav');
sound(audioIn,fs)
%Increase the pitch by 3 semitones and listen to the result.
nsemitones = 3;
audioOut = shiftPitch(audioIn,nsemitones);
sound(audioOut,fs)
%Decrease the pitch of the original audio by 3 semitones and listen to the result.
nsemitones = -3;
audioOut = shiftPitch(audioIn,nsemitones);
sound(audioOut,fs)

Categories

Find more on Measurements and Spatial Audio in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!