Reputation: 1232
I have been working on a (potentially super simple) assignment in which one of the steps is to get a Fourrier transform. I have followed a guide from my university to transform a wave-sound which can be found here (channels: 2, samples: 17600, sample frequency: 16KHz).
Looking at the graph, it seems to work:
[y,fs,wmode,fidx]=readwav('piano.wav','r',-1,0);
left=y(:,1);
amountOfSlices = 6;
samplesPerSlice = fix(length(left) / 6);
frames=enframe(left, samplesPerSlice);
frames=transpose(frames);
fftdata=rfft(frames);
fftdata=fftdata.*conj(fftdata);
plot(fftdata);
Next, I created a code file with the tutorial code as a basis with the addition of accepting parameters (which are needed for the assignment, but have been left out for brevity).
samplerate = 512;
% Read the file with raw unscaled audio data from begin to end
[multiData,fs,wmode,fidx]=readwav(filename,'r',-1,0);
disp(sprintf('Number of channels: %d', fidx(5)))
disp(sprintf('Number of samples: %d', fidx(4)))
disp(sprintf('Sample frequency: %d Hz', fs))
% Extract the left channel of the data
leftData = multiData(:, 1);
% Slice the left channel into pieces of the size of 'samplerate'
samplesPerSlice = samplerate
% Splits the leftData vector up into frames of length equal to sample rate
slicedLeftData = enframe(leftData, samplerate)';
% Apply the real data fast fourrier transformation on each data slice
fftdata=rfft(slicedLeftData);
fftdata=fftdata.*conj(fftdata);
plot(fftdata);
Do you guys have any idea what I'm doing wrong here?
What my actual question is: Why isn't the second data in the frequency domain of 0 to 16.000 Hz? What am I doing wrong?
Upvotes: 0
Views: 1673
Reputation: 2317
I guess by "whats wrong here" you mean the multiple colors? If so, looks like the fftdata plottet in both images are matrices (you want an array, correct?). Doesn't the .* perform the operation on each and every element? Check the dimensions for your ingoing arguments.
Furthermore, remember Nyquist theorem: You can never resolve any frequencies greater than half your sample frequency. In the case of having a sample frequency of 16KHz, you may have datapoints beyong 8kHz but it will not contain any information, so no need to include that in the frequency domain plot.
Upvotes: 1