1

Good morning, I'm having trouble with pitch finding and shifting in MATLAB. The program compiles but when i try to sound the shifted track it exits a strange sound and the pitch found isn't correct. What's the problem?

 [audioIn,fs] = audioread('Silae.wav');
 [f0,idx] = pitch(audioIn,fs);

 subplot(3,1,1)    %2.1.1
 plot(audioIn)
 ylabel('Amplitude')

 subplot(3,1,2)    %2.1.2
 plot(idx,f0)
 ylabel('Pitch (Hz)')
 xlabel('Sample Number')

 [f1,idx] = pitch(audioIn,0.3*fs); 
 subplot(3,1,3)
 plot(idx,f1)
 ylabel('Pitch n (Hz)')
 xlabel('Sample Number n')
 [f1,idx] = pitch(audioIn,3*fs);  %2 o 4
 subplot(3,1,3)
 plot(idx,f1)
 ylabel('Pitch n (Hz)')
 xlabel('Sample Number n')
 sound(audioIn);
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Lory97
  • 35
  • 3
  • 3
    This is a duplicate of [your own question you deleted by now](https://stackoverflow.com/q/54332867/5211833) Note that it is against Stack Overflow policy to 'bump' posts by deleting them. This can get you a question ban. Instead, improve your question as best as you can, and, if you have enough reputation, [set a bounty on it](https://stackoverflow.com/help/privileges/set-bounties). You are not entitled to get help, it's a volunteer service after all, so please don't abuse the system. – Adriaan Jan 28 '19 at 13:09

1 Answers1

3

The function pitch returns the fundamental frequencies of the audio vector audioIn and the locations of these frequencies. This function does not modify its input, so when you do pitch(audioIn,0.3*fs), audioIn will remain unchanged.

So, regarding to what you perform on audioIn, your code could be summarized as:

[audioIn,fs] = audioread('Silae.wav');
sound(audioIn);

By default, the function sound (without argument about Fs):

sound(y) sends audio signal y to the speaker at the default sample rate of 8192 hertz.

So, the problem is, if your input Silae.wav file is at 44100 Hz, by playing it at 8192 Hz, you will play it about 5 times slower that you should, making it weird and deep sound.

alpereira7
  • 1,522
  • 3
  • 17
  • 30
  • Thank you for your answer. I'm often confused with the paramethers of the functions. However what can i do to shift the pitch? – Lory97 Jan 29 '19 at 11:21
  • You can accept the answer by clicking the green check mark, so people know you consider the answer as correct. I'm looking for some interesting pitch shift links. – alpereira7 Jan 29 '19 at 12:51