I am new to programming and sound processing, I have been using matlab to process sound files, a few of which are ultrasonic. my sampling rate is 250kHz. I Would like to be able to play the sounds at an audible frequency, there for i need to lower the pitch of the sounds without changing the speed. The frequency in the sound files are around 70 kHz, and i need to lower them to about 20 kHz (human hearing range 20 Hz - 20 kHz), about 4 times lower. If i simply change the sampling rate to 250000*4, i get the right frequency but the file become shorter/faster.
I have tried a few things:
- Delete every 4th bin of the original vector and multiplying sampling rate by 4. it did the opposite of what i intended and also changed the length.
- Duplicate every bin the the audio 4 times and keep the sampling rate, it actually lowered the frequency and the length did not change, but the frequencies were mirrored it 4 times
- A method i found online,which i don't understand, this method gave the best result: lower frequency and same file length but it changed the structure of the sound file (see link to spectrogram)
here is the code sample of the last method:
function [signal]=lower_the_freq(original) % original = rawClip.values'; binlen=length(original); sfq=250000; duration=binlen/sfq;
% plot original signal subplot(211);
fourierTransform = fft(original); spectrogram(original,1024,512,1024,sfq,'yaxis'); %run the spectrogram title('Original signal')
% downsample spectrum by a factor of 2 n = 2; % downsampling factor newSpectrum = fourierTransform(1:n:end);
% zero-pad the positive and negative ends of the spectrum pad = floor(length(fourierTransform)/4); fourierTransform = [zeros(1,pad) fftshift(newSpectrum) zeros(1,pad)];
% inverse transform signal = ifft(length(original)*fftshift(fourierTransform),'symmetric');
% plot the downshifted signal subplot(212) spectrogram(signal,1024,512,1024,sfq,'yaxis'); %run the spectrogram title('Shifted signal')