[data,Fs]=audioread('audio_in_noise1.wav');
channel = 1;
signal = data(:,channel);
samples = length(signal);
dt = 1/Fs;
t = (0:dt:(samples-1)*dt);
samples = length(signal);
NFFT = 512*4;
NOVERLAP = round(0.75*NFFT);
w = hanning(NFFT);
[sensor_spectrum, freq] = pwelch(signal,w,NOVERLAP,NFFT,Fs);
figure(1),semilogx(freq,20*log10(sensor_spectrum));grid
title(['Averaged FFT Spectrum / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(freq(2)-freq(1)) ' Hz ']);
xlabel('Frequency (Hz)');ylabel('Amplitude (dB)');
saturation_dB = 80;
[sg,fsg,tsg] = specgram(signal,NFFT,Fs,w,NOVERLAP);
sg_dBpeak = 20*log10(abs(sg))+20*log10(2/length(fsg));
mini_dB = round(max(max(sg_dBpeak))) - saturation_dB;
sg_dBpeak(sg_dBpeak<mini_dB) = mini_dB;
figure(2);
imagesc(tsg,fsg,sg_dBpeak);axis('xy');colorbar('vert');grid
title(['Spectrogram / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(fsg(2)-fsg(1)) ' Hz ']);
xlabel('Time (s)');ylabel('Frequency (Hz)');
Best Answer