Data, which isn't missing, appears to be missing in surf plot
3 次查看(过去 30 天)
显示 更早的评论
Can anyone explain the gaps (white bars) which arise in my surf plot? The degree to which they appear changes depending on whether I plot the spectrogram as a full figure or a subplot... I would like to remedy this so there are no white bars in the subplot of the spectrogram.
subplot(3,1,3)
surf(t,f,A','FaceColor','interp',...
'EdgeColor','none','FaceLighting','phong');
set(gca,'tickdir','out','layer','top','fontname',... %change size of axes
'arial','fontsize',8);
ylim([50 2000]);
axis tight
view(0,90);
grid off
set(gca,'YScale','log'); %set y-axis scale to logarithmic
datetick('x','keepticks'); %change x axis to readable time
ylabel('Frequency ( Hz )','fontsize',14);
13 个评论
Mathieu NOE
2021-10-25
Hello Louise
this is a result with all spectrograms in one plot - the data are separated by zeros just to avoid any misinterpretation of the plot
of course the wav files should be sampled at the same sampling freq - but even in a different scenario we can find a fix fr that
of course I still need to figure out how to make the x axis labelling working - that is still work ahead
code so far :
% %% read multiple files
% fileDir = pwd; % currrent directory
%
% fileNames = dir(fullfile(fileDir,'*.wav')); % get list of files in directory
% fileNames_sorted = natsortfiles({fileNames.name}); % sort file names into order (https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
% nFiles = numel(fileNames_sorted);
%
clc
clearvars
close all
%%%%%%%%%%%%%%%%%%%%%%%%
% directory={'X:\SoundTrap\Boats\wav\Noises\LTSA test\LTSA test batch'}; %folder where wav files are
% folder=char(directory);
folder= pwd;
fullfnames=dir(fullfile(folder,'*.wav')); %list all .wavs in folder
nFiles=numel(fullfnames);
%get fs of first (i.e. all) files in folder
firstfile=fullfile(folder,char(fullfnames(1,1).name));
[xbit,fs]=audioread(firstfile,[1 2]);
tlo=1.0;
% thi=114.0;
thi=3.0; % for my demo
nlo=fs*tlo; %multiply fs by tlo to get starting point
nup=fs*thi; %do the same for end point
nfft=1024; % for my demo
% nfft=16384;
overlap=nfft/2; %50% overlap
% window=16384;
window=hanning(nfft);
cal=176.4;
cal=power(10,cal/20); %calculate calibration value
t0=0;
dt=1;
P_all = [];
for iFile = 1:3 %nFiles
fullfname = fullfnames(iFile).name;
%format is xxxx.yyMMddHHmmss.cut.wav
% you'll have to set/get/extract start-time for each spectrogram
fname=strsplit(fullfname,{'.'});
fname_st=fname(2);
fname_st=datenum(fname_st,'yyMMddHHmmss');
tStartstrings{iFile} = fname_st;% you'll have to set/get/extract start-time for each spectrogram
[xbit,fs]=audioread(fullfile(folder,fullfname), [nlo nup]); %read in wav
xbit=detrend(xbit); %remove DC offset
calxbit=xbit*cal; %apply calibration
%Perform FFT and plot:
[S,F,T,P] = spectrogram(calxbit,window,overlap,nfft,fs,'yaxis');
P_all = [P_all P zeros(length(F),25)]; % concatenate all P data with some blanks in between
T=fname_st+datenum(seconds(T)); %start time of .wav file + seconds of each chunk to produce informative x-axis
end
[a,samples] = size(P_all);
t = (0:samples-1)*1/fs;
h = pcolor(t,F,10*log10(P_all)); % Here you might want to add the start-time, t0, to T
colormap(jet);
set(h,'EdgeColor','none');
datetick('x','SS')
title(fullfname(1:length(fullfname)-4));
xlabel('Time');
ylabel('Frequency (Hz)');
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!