0
$\begingroup$

I have found out 20 dominant frequencies of a song by splitting it into 20 sound-clips and applying Fourier transform on each one of the sound-clips. Now I am trying to reconstruct the song back from these 20 dominant frequencies.

info_ = audioinfo('../wws.wav'); % 11 secs long song

Fs = info_.SampleRate;
chunkDuration = 0.6; 
numSamplesPerChunk = chunkDuration*Fs;

freq_vec = [];
for startLoc = 1:numSamplesPerChunk:info_.TotalSamples  
    endLoc = min(startLoc + numSamplesPerChunk - 1, info_.TotalSamples);
    [x, Fs] = audioread('../wws.wav', [startLoc endLoc]);
    x = x(:,1); 
    dt = 1/Fs; 
    t = 0:dt:(length(x)*dt)-dt; % time scale
    L = length(t); 
    nfft = 2^nextpow2(L);
    y = fft(x, nfft);
    y = abs(y.^2); 
    y = y(1:1+nfft/2); 
    [v,k] = max(y); 
    f_scale = (0:nfft/2)* Fs/nfft;
    freq_vec = [freq_vec, f_scale(k)];
end

freq_vec is the vector of dominant frequencies of the song. My question is how can I use these frequencies to build back the song.

$\endgroup$
2
  • 1
    $\begingroup$ How did you get the idea that you can reconstruct the song from those frequencies? In your code you throw away tons of information, so I don't understand how you can expect to be able to reconstruct anything. $\endgroup$
    – Matt L.
    Jan 3, 2018 at 11:18
  • 1
    $\begingroup$ @MattL. I was a bit hesitant at first, but in the end: questions of this type come up so often, we might even answer one. And the answer is what you say in your comment: If you irrevocably throw away information, its lost, and can't be recovered. $\endgroup$ Jan 3, 2018 at 11:49

2 Answers 2

2
$\begingroup$

Short answer: You can't.

Sound is more than its dominant frequencies, and you threw away anything but that.

$\endgroup$
2
$\begingroup$

First off, you don't even have the dominant frequencies, but only the frequencies of the nearest FFT result bins. Second, by taking the abs(), you have thrown away all the phase information, which is required to reproduce any transients or changes during each sound clip. Third, the phase information and all the spectrum not in the 20 dominant frequencies is required so as not to have potentially loud clicks between reproduced frames. etc.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.