Getting a filter error today when yesterday didn't?
7 次查看(过去 30 天)
显示 更早的评论
Is MATLAB a time varying system? Everything was working swimmingly for me yesterday, but I'm riddled with errors today, for code that has been unchanged since written yesterday.
For reference, I'm getting: Error using filter Initial conditions must be a vector of length max(length(a),length(b))-1, or an array with the leading dimension of size max(length(a),length(b))-1 and with remaining dimensions matching those of x.
I was able to get the stem plot associated with it from yesterday, and I know that this is what it's supposed to look like, indicating that it was written correctly: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/600035/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/600035/image.png)
Using the code:
tmin = 0;
tmax = 0.1;
dt = 1/2000;
t = tmin:dt:tmax;
x = 3*cos(2*pi*30*t) + cos(2*pi*200*t);
n = 79;
d = [1 zeros(1,n)];
a = [1 -1.294 0.64];
b = [1.812 -2.932 1.812];
q = filter(b,a,d,x);
stem(q)
0 个评论
回答(1 个)
Chad Greene
2021-4-28
I suspect that yesterday you weren't including x in the filter. Yesterday you were filtering the d signal, which is just [1 0 0 0 0 ... 0]. When you filter d, all you're left with is the ringing from the impulse.
tmin = 0;
tmax = 0.1;
dt = 1/2000;
t = tmin:dt:tmax;
x = 3*cos(2*pi*30*t) + cos(2*pi*200*t);
n = 79;
d = [1 zeros(1,n)];
a = [1 -1.294 0.64];
b = [1.812 -2.932 1.812];
q = filter(b,a,d);
stem(q)
Were you intending instead to filter x?
q = filter(b,a,x);
stem(q)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!