I have a signal in Malab, and I need a matrix, probably transposed specgram matrix without using specgram tool. Is it possible?
Yes, the easiest way to do this is using reshape and FFT, since reshape will give you a matrix and the FFT will operate along a dimension of the matrix. I've applied a 1024 rectangular window on a data set of 65536 points, sampling frequency Fs (1024), and signal frequency (100).
x = randn(1, 65536) + cos(2*pi*100/1024*(0:65536-1)); z = reshape(x, 1024, ); y = 20*log10(abs(fft(z))); imagesc(y)
This example doesn't have any overlap, but all you would need to do is shift z then concatenate it with z prior to taking the FFT. This all depends on your overlap percentage.
z = [z; circhift(z, [0 -1])];
This is not complete given the first column is now at the end, so you would have to omit that column, but you get the idea.
Do you need choose one chunk size, one window type, overlap percentage and of course use the matlab function FFT to returns the discrete Fourier transform, here a simple spectrogram using chunk = 2048, 50% of overlap and a hann window.
[x,Fs]=wavread('ederwander.wav'); CHUNK = 2048 OVERLAP = CHUNK / 2 NFFT = CHUNK num = [CHUNK : OVERLAP :length(x)]; SPEC = zeros( length(num), NFFT/2 ); for i=length(num):-1:1, framed = x( (num(i)-CHUNK) + 1 : num(i) ); windowed = framed .* hann(length(framed)); Fourrier = fft(windowed, NFFT); SPEC(i,:) = log(abs(Fourrier(1:NFFT/2))); end imagesc(flipud(SPEC'))
a little explanation
When I do
windowed = framed .* hann(length(framed)) Im applying a window over the signal, this step decreasing the amplitude component of the ends, this is used to avoid the appearance of spurious high frequency components of the Fourier transform, if you plot a Hann window you can see a similar Gaussian format !
The "CHUNK" is the slice cut audio, for this example I'm getting 2048 samples, and at each slice I'm overlapping 50% of samples!
The "num" are the linear calc of the position when cut the signal to analyses
protected by jojek♦ Jun 22 '15 at 14:14
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?