2013-06-24 25 views
-1
function f = 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); 


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


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

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

for i = [rectPos:rectNeg] 

    %iterate through each value and plug into function in for loop 
    %each output of the function will be stored into another array 
f= 2*i; 
end 





end 

我已經編輯它,並認爲這會工作,但我得到的錯誤...陣環MATLAB

錯誤lowpassFIR(6號線) passEdge = 100;

在調用 「/Users/sergiogonzalez-palavicini/Documents/MATLAB/lowpassFIR.m >lowpassFIR」期間沒有分配輸出參數「f」(也可能是其他參數)。

+4

這不是很清楚.... – Oli

+0

退房[此帖](http://stackoverflow.com/questions/758736/how-do-i-iterate-through-each-element-in -n-dimensional-matrix-in-matlab),它可能會有幫助 –

+0

它取決於函數,如果它是矢量化的,那麼你可以簡單地執行'Y = f(rect)'。你能發佈實際功能嗎? – Dan

回答

1

可以使用arrayfun

>>> function a = func(b) 
> a = b*2; 
> end 
>>> arrayfun(@func,1:10) 
ans = 

    2 4 6 8 10 12 14 16 18 20 

>>> 

它需要一個函數作爲第一個參數和陣列作爲第二個參數。
它返回另一個數組,該函數應用於原始數組的每個元素。
Documentation

+0

如果OP希望每個輸出存儲在不同的數組(單元格)中,則必須使用UniformOutput'false'選項。 –

+0

現在應該更清楚了! – user2514874