-1
function [h,w,y,graph] = lowpassFIR(sample)

%Calculates Finite Impulse Response low pass filter coefficient
%using the windowing methods as well

passEdge = 100;
StopbandAtt = 20;
passbandRip =.05;
transWidth = 10;
Fs = sample;





%Step One: select number of coefficients%
deltaF = transWidth/Fs;

%Normalize for each window


rectN = round(0.9/deltaF);

hannN = round(3.1/deltaF);
hammN = round(3.3/deltaF);
blackN = round(5.5/deltaF);

rectN = 1:rectN

%rectPos = round(rectN/2);
%rectNeg = round((rectPos*-1));


%For the Vector Array
%rect = rectNeg:rectPos;

deltaSum= passEdge + (transWidth/2);
deltaF2= deltaSum/Fs;

h=zeros(size(1:rectN(end)));
w=zeros(size(1:rectN(end)));
y=zeros(size(1:rectN(end)));
graph = plot(y)
for i = 1:rectN(end)

   %iterate through each value and plug into function in for loop
   %each output of the function will be stored into another array
    h(i) = 2*deltaF2*(sin(i*2*pi*deltaF2))/(2*i*pi*deltaF2);   
    w(i) = 0.5 + 0.5*cos(2*pi*i/rectN(end));
    y(i) = h(i)*w(i);
    graph(i) = y(i);
end

从代码中您可以看出我正在尝试从图形中获取图形结果....但是当它输出时,我在命令窗口中获得了值,但是该图显示了一条直线@零...我该怎么做在这里自动缩放y轴??

4

1 回答 1

0

我不认为自动缩放是这里的问题,而是事件的顺序。

您尝试在此行中“初始化”您的情节:

graph = plot(y);

但是,在上一行中,您定义

y=zeros(size(1:rectN(end)));

因此,您看到的图将是一条直线y=0。的值graph线对象的句柄,在本例中是您的线y=0
尝试设置绘图后,您进入一个循环,并在每次迭代时,为您的线句柄 ( graph(i) = y(i)) 添加一个值 - 但您不绘制任何内容。如果在循环之后,您查看 的值y或者graph您看到新值 - 但它们从未被绘制。
我怀疑在这种情况下你需要一个循环,也许试试这个:

I = 1:rectN(end);
h = 2.*deltaF2.*(sin(I.*2.*pi.*deltaF2))./(2.*I.*pi.*deltaF2);   
w = 0.5 + 0.5.*cos(2.*pi.*I./rectN(end));
y = h.*w;
graph = plot(y);

重要的是要注意元素明智的乘法.*

最后一条评论:您不应该使用i(或j就此而言)作为迭代器,因为它们也被用作 Matlab 中的虚数单位,如果您在代码中的某个地方需要,这可能会产生问题。

于 2013-06-25T12:14:39.430 回答