How can I plot the spectrogram of a WAV file without using predefined function? i mean i dont want use FFT or spectrogram functions .
my windows i want to take over the whole signal should be Hamming windows with size 256 and overlap 50%.
could you please give me some advice ?
best regards .
i tried the following code for DFT . but i got error : ??? Error using ==> times Matrix dimensions must agree.
the code :
n=256;
wholeFile=wavread('C:\Users\alireza\Desktop\alireza bahrami\New folder\Sound clip 32.wav');
for ii = 1:4096
waveform = wholeFile(128*ii + (1:256)); % a bit of background noise...
alpha = 0.54; beta = 1 - alpha; % hamming coefficients
hwin = alpha - beta * cos(2 * pi * (1:n) / (n - 1)); % from http://en.wikipedia.org /wiki/Window_function#Hamming_window
fSample = 8192; % sampling frequency
t = (0.5:1:n) / fSample; % actual time
waveformHW = waveform .* hwin; % the windowed form of the waveform
frequencies = (0:(n/2)-1) * fSample / n;
myFFT = zeros(size(frequencies));
for fi = 1:n/2
c = cos(2*pi*frequencies(fi) * t);
s = sin(2*pi*frequencies(fi) * t);
myFFT(fi) = (sum(c .* waveformHW) + 1i * sum(s .* waveformHW))/sum(c.*c.*hwin);
end
end
figure; semilogy(frequencies, abs(myFFT))
xlim([0 1000])
xlabel 'frequency'
ylabel 'amplitude'
title 'two tones plus noise'
For my example to work, your t vector must be a column vector, change this line
t = (0.5:1:n) / fSample; % actual time
to
t = (0.5:1:n)' / fSample; % actual time
You can use regress to get the amplitude of the sine and cosine components. Delete this line of your code:
myFFT(fi) = (sum(c .* waveformHW) + 1i * sum(s .* waveformHW))/sum(c.*c.*hwin);
Replace it with
b = regress(waveformHW, [c, s]; % c and s must be column vectors
myFFT(fi) = b(1) + 1i * b(2);