⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spec_go.m

📁 这是一个用于语音信号处理的工具箱
💻 M
字号:
%
% Callback function for Apply button in the Frequency Analysis window
% Author : Minkyu Lee
% Date : 4-Feb-1995
% Modified by Karthik May 27 1997
% Modified by D. G. Childers


% Set position and size of analysis window
PV=[275 100 519 240];
s2 = 'Frequency Domain Analysis - Output';

% Open analysis window
while exist('freq_out_win_h')==1
   try1 = 'get(freq_out_win_h,''position'');';
   eval(try1,catch2);
   if check ==0
      clear freq_out_win_h;
      check = 1;
      break;
   end
   s1 = get(freq_out_win_h,'Name');
   if ~strcmp(s1,s2)
      clear freq_out_win_h;
      break;
   end
   figure(freq_out_win_h);
   break;
end;

if exist('freq_out_win_h')~=1;
	freq_out_win_h=figure('Position',PV,...
		'Resize','on',...
      'Numbertitle','off',...
      'Name',s2);
end

if (RIGHT-LEFT+1) < spec_frame_len
   disp('The current data length is less than the analysis frame length');
   disp('The analysis will continue with the frame length being set to ');
   disp('the length of the data.');
   spec_frame_len=RIGHT-LEFT+1;
end

maxlag=ceil(0.1*spec_frame_len); % for Blackman-Tukey

if spec_window == 1
   window = hamming(spec_frame_len);	% Window type
   winbktk=hamming(2*maxlag+1); %window for Blackman-Tukey
elseif spec_window == 2
   window = hanning(spec_frame_len);	% Window type
   winbktk=hanning(2*maxlag+1); %window for Blackman_Tukey
elseif spec_window == 3
	beta=0.5;
   window = kaiser(spec_frame_len,beta);	% Window type
   winbktk=kaiser(2*maxlag+1,beta); %window for Blackman-Tukey
elseif spec_window == 4
   window = triang(spec_frame_len);	% Window type
   winbktk=triang(2*maxlag+1); %window for Blackman-Tukey
elseif spec_window == 5
   window = bartlett(spec_frame_len);	% Window type
   winbktk=bartlett(2*maxlag+1); %window for Blackman-Tukey
elseif spec_window == 6
   window = blackman(spec_frame_len);	% Window type
   winbktk=blackman(2*maxlag+1); %window for Blackman-Tukey
elseif spec_window == 7
   window = boxcar(spec_frame_len);	% Window type
   winbktk=boxcar(2*maxlag+1); %window for Blackman-Tukey
elseif spec_window == 8
	rdb=3;
   window = chebwin(spec_frame_len,rdb);	% Window type
   winbktk=chebwin(2*maxlag+1,rdb); %window for Blackman-Tukey
end

val=get(spec_po_method_h,'Value');
button=1;
while button == 1
	if freq_spec_mark_flag == 0
		S=sprintf('The analysis frame is the first %d points of current data window',spec_frame_len);
		disp(S);
		speech1=SPEECH_OLD(LEFT:LEFT+spec_frame_len-1);
      button=0;
      x=LEFT;
	else
		disp('Please select a starting point of analysis frame');
		figure(ana_wav_win_h);
      [x,y,button]=ginput(1);
      x=round(x);
		if button ~= 1
			return;
		end
   end
   
   x_end=x+spec_frame_len-1;
   if x > RIGHT
      disp('You have reached the end of the data.  The analysis will use');
      disp('the last data point.');
      x=RIGHT-spec_frame_len;
      x_end=x+spec_frame_len-1;
   end
   if x_end > RIGHT
      disp('You have reached the end of the data.  The analysis will use');
      disp('the last data point.');
      x_end=RIGHT;
      x=RIGHT-(spec_frame_len-1);
   end
   

   speech1=SPEECH_OLD(x:x_end);
   figure(freq_out_win_h);
   window = window(1:(x_end-x+1));
   speechbktk=speech1; %This is the unwindowed speech for Blackman-Tukey
   speech1=window.*speech1;
   

	% The following two lines should be changed
	Fs = 10000; 		% Sampling frequency
	epsilon=1e-15;		% A small number to test for the ill-conditioning
                     % of matrix  
	if val == 1
		disp('FFT analysis');
		FFT = fft(speech1);
		vh=1:length(FFT(1:spec_frame_len/2));
      vh=vh/length(FFT(1:spec_frame_len/2))*1/(2*Ts);
      plot(vh, 20*log10( abs(FFT(1:spec_frame_len/2)) ) );
      fsave = 20*log10( abs(FFT(1:spec_frame_len/2)));
      title('Spectrum Analysis FFT');
      Gs=FFT(1:spec_frame_len/2);
		hold on
   elseif val == 2
      N=length(speech1);
      disp('Periodogram');
      FFTPER = fft(speech1)/N;
		vh=1:length(FFTPER(1:spec_frame_len/2));
      vh=vh/length(FFTPER(1:spec_frame_len/2))*1/(2*Ts);
      plot(vh, 20*log10( abs(FFTPER(1:spec_frame_len/2)) ) );
      fsave = 20*log10( abs(FFTPER(1:spec_frame_len/2)));
      title('Spectrum Analysis Periodogram');
      Gs=FFT(1:spec_frame_len/2);
		hold on

   elseif val == 3
      disp('Blackman-Tukey analysis');
      [rcorr lags]=xcorr(speechbktk,maxlag,'biased');
      rcorr=winbktk.*rcorr;
      FFT=fft(rcorr, spec_frame_len);
      vh=1:length(FFT(1:spec_frame_len/2));
      vh=vh/length(FFT(1:spec_frame_len/2))*1/(2*Ts);
      plot(vh,10*log10(abs(FFT(1:spec_frame_len/2))));
      title('Spectral Analysis Blackman Tukey');
      hold on
  
   elseif val == 4
%  The following uses MATLAB's function pmusic.
%  For additional information on pmusic see help pmusic or
%  the Signal Processing Toolbox manual page 6-217.
%  December 1996 edition
%
%  D. G. Childers, June 5, 1997
%
      [PP,ff]=pmusic(speech1,num_poles,spec_frame_len,10000,[],[]);
      plot(ff, 10*log10(PP));   %  Pxx is the power spectrum so use 10log10
      title('Spectrum Analysis MUSIC');
      fsave=10*log10(PP);
		hold on

   elseif val == 5
      disp('ESPRIT spectral analysis  ')
		nv=1;
      [fr,bw,la] = esprit(speech1, num_poles, nv);
      %num_poles is the assumed number of real signals present
      %The number of complex exponentials is twice this amount.
      %This doubling is taken care of in esprit.m
      %Note that this feature is apparently handled in pmusic.m
      %in a similar manner, but I did not verify this.
      A=poly(la);
      [H,W]=freqz(1,A, spec_frame_len/2);
      vh=1:spec_frame_len/2;
      vh=vh/(spec_frame_len/2)*1/(2*Ts);
      plot(vh,20*log10(abs(H)));
      xlabel('Frequency in (Hz)');
      fsave=20*log10(abs(H));
      title('Spectral Analysis ESPRIT');
      hold on;
   end
   clear speech1
 end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -