| 
			
			 初级会员 
			
			
			
			
				 
				注册日期: 2009-05-27 
				
				年龄: 36 
				
					帖子: 1
				 
				
				
				声望力:  0 
				
				     
			 
	 | 
	
	
	
		
		
			
			
				 
				求助:关于一道MATLAB程序题的翻译
			 
			 
			
		
		
		
			
			由于本人没有认真学MATLAB,所以老师布置的题不会做,想请教大家,希望以后能帮我好好了解学习MATLAB,这次就靠大家了!多谢!以下是题目:(需要逐句翻译) 
function psdplot(varargin) 
%PSDPLOT Plot Power Spectral Density (PSD) data. 
%   PSDPLOT(Pxx,W) plots the PSD, Pxx, computed at the frequencies 
%   specified in W (in radians/sample). 
%    
%   PSDPLOT(Pxx,W,UNITS) specifies the frequency (x-axis) units for the plot. 
%   UNITS can be either 'RAD/SAMPLE' (default) or 'Hz'. 
% 
%   PSDPLOT(Pxx,W,UNITS,YSCALE), where YSCALE can be either 'LINEAR' or 'DB', 
%   specifies the scaling of the Y-axis for the PSD plot. 
% 
%   PSDPLOT(Pxx,W,UNITS,YSCALE,TITLESTRING) will use the specified string for 
%   the title of the plot. 
% 
%   See also PERIODOGRAM, PWELCH, PEIG, PMTM, PMUSIC, PBURG, PCOV, PMCOV, 
%   and PYULEAR. 
 
%   Author(s): R. Losada  
%   Copyright 1988-2002 The MathWorks, Inc. 
%   $Revision: 1.11 $  $Date: 2002/03/28 17:30:16 $  
 
error(nargchk(2,5,nargin)); 
 
[inparg,msg] = parseinput(varargin{:}); 
error(msg); 
 
data = psdplotsetup(inparg); % Generate the plot data 
 
newplot; 
 
plot(data.freq,data.mag); 
ax = gca; 
xlabel(data.freqlabel); 
ylabel(data.maglabel); 
title(inparg.titlestring) 
axes(ax(1)); % Always bring the plot to the top 
set(ax,'xgrid','on','ygrid','on','xlim',data.freqlim); 
 
%------------------------------------------------------------------------------- 
function [inparg,msg] = parseinput(varargin) 
%PARSEINPUT   Setup a structure INPARG with the input args parsed. 
%   INPARG is a structure which contains the following fields: 
%   INPARG.w           - Frequency vector 
%   INPARG.Pxx         - Power Spectral Density 
%   INPARG.units       - Frequency units 'rad/sample' or 'Hz' 
%   INPARG.yscale      - 'db' or 'linear' 
%   INPARG.TITLESTRING - Title for the plot  
 
inparg.Pxx = varargin{1}; 
inparg.w = varargin{2}; 
 
% Generate defaults 
inparg.units  = 'rad/sample'; 
inparg.yscale = 'db'; 
inparg.titlestring = ''; 
msg = ''; 
 
if nargin > 2, 
    
   inparg.units = varargin{3}; 
   if isempty(strmatch(lower(inparg.units),{'rad/sample','hz'})), 
      msg = 'Units must be either in ''Hz'' or in ''rad/sample''.';  
      return 
   end 
    
   if nargin > 3, 
       
      inparg.yscale = varargin{4}; 
      if isempty(strmatch(lower(inparg.yscale),{'db','linear','squared'})), 
         msg = 'Can only plot in ''LINEAR'' scale or in ''DB'' scale.'; 
         return 
      end 
       
      if nargin > 4, 
         inparg.titlestring = varargin{5}; 
      end 
   end 
end 
%------------------------------------------------------------------------------- 
function data = psdplotsetup(inparg); 
%PLOTSETUP   Setup arguments to plot with PSDPLOT. 
%   PLOTSETUP returns a structure DATA to be used with PSDPLOT 
%   with the following fields: 
%   DATA.FREQ       = wplot (Frequency data) 
%   DATA.FREQLABEL  = xlab  (Frequency axis --x axis-- label) 
%   DATA.FREQLIM    = xlim  (Frequency axis --x axis-- limits) 
%   DATA.MAG        = Pxx   (Magnitude data (possibly in dB)) 
%   DATA.MAGLABEL   = ylab  (Magnitude label) 
 
Pxx = inparg.Pxx; 
w = inparg.w; 
 
% Generate the correct labels 
if strmatch(lower(inparg.units),'rad/sample'), 
   xlab = 'Normalized Frequency  (\times\pi rad/sample)'; 
   w = w./pi; 
   ylabend = '/ rad/sample)'; 
elseif strmatch(lower(inparg.units),'hz') 
   xlab = 'Frequency (Hz)'; 
   ylabend = '/Hz)'; 
end 
    
% Scale the psd correctly 
if strmatch(lower(inparg.yscale),'db'), 
   Pxx = db(Pxx,'power'); 
   ylab = ['Power Spectral Density (dB' ylabend]; 
elseif strmatch(lower(inparg.yscale),{'linear','squared'}), % 'squared' is allowed  
                                                            % for backwards compat. 
   ylab = ['Power Spectral Density (Power' ylabend]; 
end 
    
data.freq = w; 
data.freqlabel = xlab; 
data.freqlim = [w(1) w(end)]; 
data.mag = Pxx; 
data.maglabel = ylab; 
 
% [EOF] psdplot.m
		 
		
		
		
		
		
		
		
	 |