Library Spectrum Analysis Statistics (matlab, c++, database)
Feb 13, 2013 at 8:30 PM Post #16 of 22
@shrimants
 
I would recommend you use Matlab if you want to invest $ in it (if you are a student you can get a good discount there), and if you are not planning to generate executables (MATLAB can do this through a toolbox but from memory it tends to be a bit inefficient.)
 
Some comments:
 
1) If you use vectors Matlab is fairly fast (in some cases very close to C++ generated code).
2) Matlab math is actually fairly accurate (by default, MATLAB data type is double 64 bits).
3) Multithreading is already supported by some built in functions in MATLAB. Parallel computing requires a toolbox.
 
Some recommendations:
 
1) To parse through directories use the "dir" function and navigate through the structure.
2) You might also want to apply the PSD to non-overlaping blocks of data to keep the output file size manageable (might one to play around with this).
3) Note that music can be bass heavy some places, but not through out. Not sure what would be an optimal block size.
4) Whatever the block size, try to approximate it to a power of 2 (or maybe 4.) FFTs are a little faster that way. There are methods to get around that constraint, but speed can still suffer.
 
Let me know if you have any specific questions (Matlab or C++)
 
Feb 13, 2013 at 8:47 PM Post #17 of 22
I already have matlab 2010 R14. I....acquired....it so that i wouldnt have to drive 35 minutes to school and back just to use matlab on the lab computers. Effectively, I could have used a trial version, but it was simply easier for me to just grab a copy. I think our school anyways sells it for cheap but thats besides the point.

The advantage of the C++ app would be if I could package the whole thing into an executable. I dont know if matlab has that kind of functionality.

From what I understand, the block size determines how many frequency bands i'll have for a given input file, and it also determines what the highest/lowest detectable frequencies will be, i think. I'd like to get a minimum of 32 frequency bands and a maximum of 2000. I say 32 because everyone is well aware of the 32 band equalizer and if I used that, it may yield some very useful data about getting an EQ setup or something.

I think considering matlab has the whole structure built in for me, it is the next best alternative to simply finding a program that already does what I'm after and setting up some sort of script to recurse thruogh directories and make text files and such. I'm going to see if I cant locate my matrices teacher and talk to him about this project. I know he works with matlab a bunch and I think he might provide some extremely valuable input and hints as to how i should go about this. For now I'm still trying to figure out the relevant parts of the FFT and how things are inter-related (like frequency, sample, block size, window, etc)
 
Feb 13, 2013 at 8:55 PM Post #19 of 22
Quote:
I already have matlab 2010 R14. I....acquired....it so that i wouldnt have to drive 35 minutes to school and back just to use matlab on the lab computers. Effectively, I could have used a trial version, but it was simply easier for me to just grab a copy. I think our school anyways sells it for cheap but thats besides the point.

The advantage of the C++ app would be if I could package the whole thing into an executable. I dont know if matlab has that kind of functionality.

From what I understand, the block size determines how many frequency bands i'll have for a given input file, and it also determines what the highest/lowest detectable frequencies will be, i think. I'd like to get a minimum of 32 frequency bands and a maximum of 2000. I say 32 because everyone is well aware of the 32 band equalizer and if I used that, it may yield some very useful data about getting an EQ setup or something.

I think considering matlab has the whole structure built in for me, it is the next best alternative to simply finding a program that already does what I'm after and setting up some sort of script to recurse thruogh directories and make text files and such. I'm going to see if I cant locate my matrices teacher and talk to him about this project. I know he works with matlab a bunch and I think he might provide some extremely valuable input and hints as to how i should go about this. For now I'm still trying to figure out the relevant parts of the FFT and how things are inter-related (like frequency, sample, block size, window, etc)

 
The toolbox for generating executable from Matlab is the "Matlab compiler"
 
As far as FFTs, the block size does not give you the highest and lowest detectable frequency, just resolution. I recommend that you use at least 2048 bins. You can actually "increase resolution" (really just interpolating values) by zero padding the FFT:
 
x = randn(1,8);
y = fft([x(1:4) 0 0 0 0]);
 
Using real values will actually increase resolution (as opposed to interpolation)... Like:
 
y = fft(x);
 
Recrusing through directories with Matlab is fairly straight forward. Do ask
smile.gif

 
Feb 13, 2013 at 11:38 PM Post #20 of 22
Quote:
 I am 99% sure that the power spectral density function is what needs to be used to generate the data. I have no idea what that means though.

My only other reason for liking C++ is that it does math better than matlab does. But like I said, speed is not really a constraint for me.

 
To get you started, here is the piece of matlab code I used to do essentially the same thing, but for analyzing EEG (with options for normalization by log and square root).  The frequency ranges in the fourth line are relevant for brain activity but change them to whatever frequency ranges you need.
 
 
startPoint=1; endPoint=length(Signals); 
%display of y axis: yUnit='power' or 'sqrt' or 'log'

yUnit='power'; %energy of wave of each frequency
fBands=[0.5  2.5  4.5  8.5  14.5  21  32  58]; %Hz
nFFT=FFTwin*sampleRateEEG; 
    wIndow=hanning(nFFT);
    nOverlap=0; %nOverlap=round(nFFT/2);
    [Pxx,fxx]=psd(signal,nFFT,sampleRateEEG,wIndow,nOverlap,'linear');
   
    %-----total power
    for kk=1:length(fBands)-1
        bandLowLim=find(fxx>=fBands(kk)); bandHighLim=find(fxx<fBands(kk+1)); bandRange=intersect(bandLowLim,bandHighLim);
        PBands(kk)=sum(Pxx(bandRange)); rPBands(kk)=PBands(kk)/PBands(length(fBands)); %kk,Total
    end   
    rPBands(length(fBands))=1; %relative total power = 1
    %
    if strcmp(yUnit,'power'), 
        figure(h2); subplot(EEG_N,3,3*ii-2); plot(fxx,Pxx); xlim(fRange); ylabel('Power'); title('Spectrum'); grid on; zoom on; 
        subplot(EEG_N,3,3*ii-1); bar(PBands); title('Absolute'); grid on; zoom on; 
        subplot(EEG_N,3,3*ii); bar(rPBands); title('Relative'); grid on; zoom on;
    end
    if strcmp(yUnit,'sqrt'), 
        figure(h2); subplot(EEG_N,3,3*ii-2); plot(fxx,sqrt(Pxx)); xlim(fRange); ylabel('Sqrt(Power)'); title('Spectrum'); grid on; zoom on; 
        subplot(EEG_N,3,3*ii-1); bar(sqrt(PBands)); title('Absolute'); grid on; zoom on; 
        subplot(EEG_N,3,3*ii); bar(rPBands); title('Relative'); grid on; zoom on;
    end
    if strcmp(yUnit,'log'), 
        figure(h2); subplot(EEG_N,3,3*ii-2); plot(fxx,log(Pxx)); xlim(fRange); ylabel('Log(Power)'); title('Spectrum'); grid on; zoom on; 
        subplot(EEG_N,3,3*ii-1); bar(log(PBands)); title('Absolute'); grid on; zoom on; 
        subplot(EEG_N,3,3*ii); bar(rPBands); title('Relative'); grid on; zoom on;
    end
    ylabel(EEGNames(ii));
 
Feb 14, 2013 at 2:00 AM Post #21 of 22
It may be somewhat off-topic, but there is a small library of freely usable C++ code here that includes FFT (real and complex), sound file I/O (requires Erik de Castro Lopo's libsndfile library), audio file input with sample rate conversion (slow but high quality, and allows for any fractional resample ratio and delay), FIR filter, fast generation of fixed frequency sine/cosine waves (it can be used for "raised cosine" type of windows like Hann, Hamming, Blackman, etc.), and fast Gaussian window. Some other bits of code are not directly usable as a library, but can be extracted from the utilities, like generating various common test signals (e.g. MLS and JTest), impulse responses for FIR filtering, and measuring the frequency/amplitude/phase of a tone.
 
Feb 16, 2013 at 5:44 PM Post #22 of 22

 
just an example I stumbled across -I'm  not a Real programmer
 

Users who are viewing this thread

Back
Top