Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2009-05-27, 16:50   #1
littlevalen
初级会员
 
注册日期: 2009-05-27
年龄: 35
帖子: 1
声望力: 0
littlevalen 正向着好的方向发展
默认 求助:关于一道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
littlevalen 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 10:43


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.