changing value in the center of an array
Show older comments
Hi, I would like to change the value of the center of any array:
This is my example code:
-I am designing an LPF filter
-I resolved the LPF filter, in correlation to n (LPF(n) = sin(omegac*n)./(n*pi)).
-HOWEVER, my center value is NaN (not applicable anyways).
-I'd like to change the center value of the array LPF_n with LPF_n0.
-For example: LPF_n = [1, 3, 5, NaN, 7, 8, 12]
-LPF_n0 = 3
-I want LPF_n = [1, 3, 5, "3", 7, 8, 12] (I highlighted "3" for better understanding, it doesn't belong there)
-My vectors will change, according to n values. So I attempted to do it by trying this:
fs = 8000
fc = 900
tap = 31
M = (taps-1) / 2
n = [ -M:M ]
omegac = (2*pi*fc)/fs
LPF_n = sin(omegac*n)./(n*pi)
LPF_n0 = omegac/pi
x = length(LPF_n)
x_2 = [x-1/2,0]
LPF_n(x_2) = LPF_n0
Any help is greatly appreciated, Thank you!
Accepted Answer
More Answers (1)
Turlough Hughes
on 25 Nov 2019
You could search for the nan value and set it equal to LPF_n0
LPF_n(isnan(LPF_n))=LPF_n0;
3 Comments
Turlough Hughes
on 25 Nov 2019
Happy to help. You get NaNs at n=0 because that results in 0/0 in your equation for LPF. Although since there are other ways you can end up with NaNs it would be better to find where n=0 rather than using isnan and then letting LPF=LPF_n0 at the corresponding indices:
LPF(n==0)=LPF_n0;
Norman Do
on 29 Nov 2019
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!