📄 colorig.m
字号:
function colea(filename,Srate1)
% Copyright (c) 1995 by Philipos C. Loizou
%
%clf reset
if (nargin < 1)
[pth,fname] = dlgopen('open','*.ils;*.wav');
if ((~isstr(fname)) | ~min(size(fname))), return; end
filename=[pth,fname];
end
pos = get(0, 'screensize'); % get the screensize
sWi = pos(3);
sHe = pos(4);
WIDTH =round(0.9375*sWi);
HEIGHT =round(0.48*sHe) ;
LEFT =round(0.025*sWi);
BOTTOM =round(0.767*sHe);
LPCSpec = 1; % if 0 display FFT, else LPC spectrum
TIME=1; % if 0 display spectrogram, else time waveform
WAV1=0; % If 1, then it is a .wav file with 8 bits/sample
CLR=1; % If 1 display spectrogram in color, else in gray scale
TWOFILES=0; % If 1, then display two files
wav(1)=0; wav(2)=0; % Used in case of dual-displays for 1-byte samples, as in WAV
upFreq=1.0; % Upper frequency (percentage of Srate/2) in spectrogram
upFreq2=1.0; % Upper frequency in spectrogram (1.0=Srate/2)
FIX_SCALE=-1; % if > 0, then channel y-axis is always 0-15 dB
SHOW_CRS=1; % if 1, show cursor lines, else dont
SHOW_CHN=1; % if 1, show channel output/LPC display
PREEMPH=1; % if 1, do pre-emphasis when computing the spectrogram
LPC_ONLY=0; % if 1, only the LPC specrtrum is displayed
lpcParam(1)=1; % if 1, use hamming window in LPC analysis, else use rectangular
lpcParam(2)=0; % if 1, first-order pre-emphasis in LPC analysis, else dont
% NOTE: this pre-emphasis is done in addition to the CIS pre-emphasis
lpcParam(3)=-1; % if 1, enhance spectral peaks in LPC analysis
fft_par(1)=1; % if 1, use lines when plotting FFT, else use pickets
NAR_BAND=0; % if 1, display narrowband spectrograms
SPEC_EXP=0.25; % Used in spectrogram display (root compression)
FILT_TYPE='broad'; % the filter type
VOL_MAX=0; % used for controling the volume
VOL_NORM=1; % if 1, then volume is normalized
fp = fopen(filename,'r');
if fp <=0
disp('ERROR! File not found..')
return;
end
ftype='short'; bpsa=2; % bytes per sample
ftype2='short'; bpsa2=1;
ind1=find(filename == '.');
if length(ind1)>1, ind=ind1(length(ind1)); else, ind=ind1; end;
ext = lower(filename(ind+1:length(filename)));
global filename
[HDRSIZE, xSrate, bpsa, ftype] = gethdr(fp,ext);
if xSrate==0, return;
else Srate=xSrate; end;
if strcmp(ftype,'ascii')
x=fscanf(fp,'%f',inf);
else
x = fread(fp,inf,ftype);
end
fclose(fp);
if Srate<6000 | Srate>45000 & nargin<2
h=warndlg('Sampling rate not in the range: 10,000 < F < 45,000 . Setting it to 10,000 Hz.','WARNING!');
disp('Warning! Sampling rate not in the range: 6,000 < F < 45,000');
disp('...Setting it to the default value of 10,000 Hz.');
Srate=10000;
end
x= x - mean(x); %----------remove the DC bias----
if (nargin==2)
Srate = str2num(Srate1);
if Srate<10000 | Srate>45000
error('Invalid sampling frequency specified: 10,000<F<45,000');
end
end
MAX_AM=2048; % This allows 12-bit resolution
mx=max(x);
agcsc=MAX_AM/mx;
n_samples = length(x);
n_Secs = n_samples/Srate;
Dur=10.0; % Duration in msec of window
S1=n_samples;
S0=0;
Be=S0;
En=S1;
OVRL=1; % if 1 then hold off plots, else hold on plots in 'pllpc'
fprintf('Samp.Freq: %d Hz, num.samples: %d (%4.2f secs)\n',Srate,n_samples,n_Secs);
fno = figure('Units', 'Pixels', 'Position', [LEFT BOTTOM WIDTH HEIGHT],...
'WindowButtonDownFcn','mclick','Pointer','crosshair',...
'Resize','on','Name',filename,'NumberTitle','Off',...
'Menubar','None','WindowButtonMotionFcn','showpt',...
'KeyPressFcn','getkb');
%------------ deterime the dimensions of the axis ------------
le=round(0.2*WIDTH);
bo=round(0.174*HEIGHT);
wi=round(0.773*WIDTH);
he=round(0.739*HEIGHT);
AXISLOC = [le bo wi he];
cAxes = axes('Units','Pixels','Position',AXISLOC);
axes(cAxes);
%----------------- Define Filterbank Characteristics---------
fftSize=512;
nChannels =6;
LowFreq =300;
UpperFreq =5500;
range=log10(UpperFreq/LowFreq);
interval=range/nChannels;
for i=1:nChannels % ----- Figure out the center frequencies for all channels
upper1(i)=LowFreq*10^(interval*i);
lower1(i)=LowFreq*10^(interval*(i-1));
center(i)=0.5*(upper1(i)+lower1(i));
end
%-------------- Design the Butterworth filter------------
nOrd=6;
FS=Srate/2;
if FS<upper1(nChannels), useHigh=1;
else useHigh=0;
end
for i=1:nChannels
W1=[lower1(i)/FS, upper1(i)/FS];
if i==nChannels
if useHigh==0
[b,a]=butter(3,W1);
else
[b,a]=butter(6,W1(1),'high');
end
else
[b,a]=butter(3,W1);
end
filterB(i,1:nOrd+1)=b; %-----> Save the coefficients 'b'
filterA(i,1:nOrd+1)=a; %-----> Save the coefficients 'a'
end
%----------------------------------------------------------
global fno Srate n_Secs filename AXISLOC nLPC HDRSIZE
global nChannels fftSize filterWeights UpperFreq LowFreq ChanpUp
global center LPCSpec SpecUp Dur DurUp filterA filterB S1 S0
global HDRSIZE cAxes En Be TIME centSMSP Asmsp Bsmsp OVRL WAV1 CLR
global TWOFILES wav agcsc MAX_AM upFreq upFreq2 FIX_SCALE
global SHOW_CRS SHOW_CHN ftype ftype2 bpsa bpsa2 PREEMPH LPC_ONLY
global lpcParam fft_par NAR_BAND SPEC_EXP FILT_TYPE VOL_MAX
global VOL_NORM
Et=1000*n_samples/Srate;
xax=0:1000/Srate:(Et-1000/Srate);
plot(xax,x)
xlabel('Time (msecs)');
ylabel('Amplitude');
%set(gca,'Units','points','FontSize',9);
if min(x)<-1000 | mx >1000
axis([0 Et min(x)-200 max(x)+200]);
else
axis([0 Et min(x) max(x)]);
end
xywh = get(fno, 'Position');
axi=AXISLOC;
% Buttons.
left = 10;
wide = 80;
top = xywh(4) - 10;
high = 22;
high=22;
if 9*(22+8) > xywh(4), high=17; end;
inc = high + 8;
%---------- Display the slider and the push-buttons-------------
sli = uicontrol('Style','slider','min',0,'max',1000','Callback',...
'getslide','Position',[axi(1) axi(2)+axi(4)+2 axi(3) 12]);
global sli n_samples
Zin = uicontrol('Style', 'PushButton', 'Callback','zoomi(''in'')', ...
'HorizontalAlign','center', 'String', 'Zoom In',...
'Position', [left top-high wide high]);
top = top - inc;
Zout = uicontrol('Style', 'PushButton', 'Callback','zoomi(''out'')', ...
'HorizontalAlign','center', 'String', 'Zoom Out',...
'Position', [left top-high wide high]);
if Srate>12000
nLPC=14;
else
nLPC=12; % initialize LPC order
end
top = top - inc-20;
uicontrol('Style','Frame','Position',[left top-high-10 wide+5 high+30],...
'BackgroundColor','b');
uicontrol('Style','text','Position',[left+wide/3 top 40 high-3],'BackGroundColor','b',...
'HorizontalAlignment','left','ForeGroundColor','w','String','Play');
plUp = uicontrol('Style', 'PushButton', 'Callback', 'playf(''all'')', ...
'HorizontalAlign','center', 'String', 'all',...
'Position', [left top-high wide/2 high]);
uicontrol('Style', 'PushButton', 'Callback', 'playf(''sel'')', ...
'HorizontalAlign','center', 'String', 'sel',...
'Position', [left+wide/2+5 top-high wide/2 high]);
top = top - inc-10;
ChanpUp = uicontrol('Style', 'Popup', 'Callback', 'setchan', ...
'HorizontalAlign','center', 'String', ['# Channels | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 12 | 14 | 16 | 18 | 20'],...
'Position', [left top-high wide high]);
top = top - inc;
DurUp = uicontrol('Style', 'Popup', 'Callback', 'setdur', ...
'HorizontalAlign','center', 'String', ['Duration | 10 ms | 20 ms | 30 ms | In samples | 64 | 128 | 256 | 512'],...
'Position', [left top-high wide high]);
top = top - inc;
uicontrol('Style', 'PushB', 'Callback', 'quitall',...
'HorizontalAlign','center', 'String', 'Quit', ...
'Position', [left top-high wide high]);
%top=top-inc;
%sliB = uicontrol('Style','slider','min',-1,'max',1','Callback',...
% 'getcontr','Position', [left top-high wide high]);
%global sliB
%---Draw the squares in case its TWOFILES
wwi=xywh(3); whe=xywh(4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -