Two examples of frequency manipulation

Solution



function [freqs,amps] = sampleSound(theSound,numFreq,Fs);
% samples the numFreq frequencies of largest amplitude
% in the FFT of theSound with sampling frequency Fs
% and return the vector of amplitudes
% (in descending order) and the corresponding vector of frequencies
L = length(theSound);
L1 = floor(L/2);
y = fft(theSound);
f = Fs/2*linspace(0,1,L1);
absy = abs(y);
absy = absy(1:length(f));
[amps,iSpect]=sort(absy,'descend');
freqs = f(iSpect);
if numFreq < length(f)
amps = amps(1:numFreq);
freqs = freqs(1:numFreq);
end