how to do implement difference equation in matlab

407 ビュー (過去 30 日間)
moonman
moonman 2011 年 11 月 14 日
コメント済み: Daniel 2024 年 3 月 27 日 15:52
Hi i am stuck with this question
Write a MATLAB program to simulate the following difference equation 8y[n] - 2y[n-1] - y[n-2] = x[n] + x[n-1] for an input, x[n] = 2n u[n] and initial conditions: y[-1] = 0 and y[0] = 1
(a) Find values of x[n], the input signal and y[n], the output signal and plot these signals over the range, -1 = n = 10.
The book has told to user filter command or filtic
my code is down kindly guide me about initial conditions
  5 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 15 日
編集済み: Walter Roberson 2021 年 3 月 5 日
My advice:
2. Use proper punctuation mark, e.g. comma, period, question mark.
3. Read your own question again after posting, e.g. what is x[n] = 2n u[n]?
4. Update your question with comments, not answers.
Ahmed ElTahan
Ahmed ElTahan 2016 年 3 月 25 日
編集済み: 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

サインインしてコメントする。

回答 (3 件)

Honglei Chen
Honglei Chen 2011 年 11 月 14 日
I think your b is incorrect, it should be [1 1] instead. To accommodate for the initial value of y and x, you need to translate them into the corresponding filter state. filter command is an implementation of direct form II transpose, so you can use filtic to convert y and x to the state.
Here is an example, where n runs from 1 to 10. Based on you example, x[0] is 1.
n = 1:10;
a = [8 -2 -1];
b = [1 1];
yi = [1 0];
xi = 1;
zi = filtic(b,a,yi,xi)
y = filter(b,a,2.^n,zi)
BTW, I doubt if the input is really 2.^n as this becomes unbounded very quickly. Are you sure it's not 2.^(-n)?
HTH
  8 件のコメント
Divya K M
Divya K M 2020 年 5 月 9 日
移動済み: DGM 2023 年 2 月 26 日
output of difference equation should be discrete but the output waveform is coming continuous
Aditya Kumar Singh
Aditya Kumar Singh 2020 年 11 月 17 日
移動済み: DGM 2023 年 2 月 26 日
use stem instead of plot... you should get the correct waveform after that

サインインしてコメントする。


Mohazam Awan
Mohazam Awan 2017 年 10 月 10 日
%%DSP LAb Task 4
% Difference equation implementation in matlab
%
clc
clear all
close all
% using filter function
n=-5:1:10;
index=find(n==0);
x=zeros(1,length(n));
x(index)=1;
subplot(2,2,1)
stem(n,x)
grid on
axis tight
b=[1 0];
a=[1 -2];
y=filter(b,a,x);
subplot(2,2,2)
stem(n,y,'filled','r')
grid on
axis tight
% Now without filter function
y1=zeros(1,length(n));
for i=1:length(n)
if(n(i)<0)
y1(i)=0;
end
if (n(i)>=0)
y1(i)=2*y1(i-1)+x(i);
end
end
subplot(2,2,3)
stem(n,y1,'filled','k')
grid on
axis tight
  2 件のコメント
Divya K M
Divya K M 2020 年 5 月 9 日

Is this code for given question if so means can I explain

Daniel
Daniel 2024 年 3 月 27 日 15:52
Why do you use negative samples in the n vector? I am trying to use only positve samples and it doesnt work

サインインしてコメントする。


Fangjun Jiang
Fangjun Jiang 2011 年 11 月 14 日
It might be a filter. But I thought all the assignment was asking you to do is to write a for-loop to generate the y series data based on the equation and the initial conditions.
  1 件のコメント
moonman
moonman 2011 年 11 月 14 日
移動済み: DGM 2023 年 2 月 26 日
no book has told to use filter is my code correct?? How to cater for initial conditions y[-1]=0 and y[0]=1

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by