% DSGex % % Demonstrates reading in DSG files, converting to Pascals, and calculating % dB-rms and spectrum level power spectrum % % 2011- David Mann, Loggerhead Instruments % www.loggerheadinstruments.com % The following are the hydrophone and DSG calibration settings % These may need to be modified based on the setup hydro_cal=-186; %hydrophone calibration e.g. -186 dBV/uPa DSG_gain=20; % gain on DSG; 20 dB is default % Select dsg file to load [FileName,PathName,FilterIndex] = uigetfile({'*.dsg','DSG files (*.dsg)'},'Select a dsg file'); if isequal(FileName,0)|isequal(PathName,0) return end cd(PathName); % Load DSG file % DF_HEAD and SID_SPEC are structures with file information % (e.g. sample rate, record date and time) % datacat are data strung together and scaled to +/-1 by MATLAB [DF_HEAD,SID_SPEC,totrecs,datacat]=DSGread(FileName,0,0); % convert to Pa VoltsPerPa=1000000*power(10,(hydro_cal+DSG_gain)/20); datacat=datacat/VoltsPerPa; % plot srate=1000000/(SID_SPEC.SP256/256); t=[0:length(datacat)-1]/srate; %create time scale figure(1) plot(t,datacat); xlabel('Time (s)'); ylabel('Sound Level (Pa)'); % Calculate rms SPL (dB re 1uPa) rmsdB=20*log10(std(1000000*(datacat-mean(datacat)))) %calculate dB re 1uPa % Calculate FFT using entire signal length freqres=srate/length(datacat); %frequency resolution hpts=floor(length(datacat)/2); %half of the number of FFT points DATACAT = abs(fft(datacat*1000000))/hpts; %calculate FFT and scale by half points in FFT DATACAT=20*log10(DATACAT); % convert to dB re 1 uPa DATACAT= DATACAT -(10*log10(freqres)); %scale to spectrum level % Plot Spectrum Level f=[0:hpts-1]*freqres; %create frequency scale figure(2) plot(f,DATACAT(1:hpts)); %plot first half of spectrum xlabel('Frequency (Hz)'); ylabel('Amplitude dB re 1uPa^2/Hz');