How can I implement a simple difference equation and plot the resulting output, all using MATLAB
조회 수: 18 (최근 30일)
이전 댓글 표시
I have a simple case of all initial conditions to be zero. We can consider a general form as:
a0y(n) = b0x(n) + b1x(n-1) + b2x(n-2) + ...+ bM x(n-M)
-a1y(n-1) - a2y(n-2) - ...- aN y(n-N)
I have to plot the output y(n) with n varying from 0 to 500.
Both y(n) and x(n) are zero for n<0.
댓글 수: 1
Ahmed ElTahan
2016년 3월 25일
Here is a function I have built to calculate it with added example. https://www.mathworks.com/matlabcentral/fileexchange/56142-output-estimation-difference-equation
답변 (4개)
Wayne King
2013년 12월 4일
You have not said what x(n) is, is it a white noise input. Is it the Kronecker delta sequence.
If we don't know that x(n) is we certainly can't tell you what y(n) is.
If you know x(n), you can implement using filter
B = [b0 b1 b2 b3 .... bM];
A = [1 a1/a0 a2/a0 ... ];
x(n) = zeros(100,1);
x(1) = 1; % Kronecker delta input
y = filter(B,A,x);
Wayne King
2013년 12월 5일
편집: Wayne King
2013년 12월 5일
Please look at the help for rand
x = -1+ 2*rand(100,1);
B = [b0 b1 b2 b3 .... bM];
A = [1 a1/a0 a2/a0 ... ];
y = filter(B,A,x);
sixwwwwww
2013년 12월 5일
may be you can try something like this:
N = 500;
for n = 1:N
xValues = sum(randi(10, 1, n) .* (rand(1, n) - 1));
yValues = sum(randi(10, 1, n - 1) .* (rand(1, n - 1) - 1));
y(n) = xValues - yValues;
end
plot(1:N, y)
Mohazam Awan
2017년 10월 10일
y1=zeros(1,length(n)); % Pre-allocating
for i=1:length(n)
if(n(i)<0)
y1(i)=0; % $ y[n]=0 for n<0
end
if (n(i)>=0)
y1(i)=y1(i-1)+x(i);
end
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!