الاخوة المهندسين خبراء الماتلاب .. طلب مساعدة

[SIZE=“4”][LEFT]Consider a discrete-time system described by the following difference equation:

y[n] = 0.4032x[n] - 0.7039x[n-2] + 0.4032x[n-4] + 0.2876y[n-2] - 0.3121y[n-4]

Implement a Matlab function called dtout.m that computes N output samples (y[0], y[1], … y[N-1]) given the following:

  • a vector of N+4 input samples (x[-4], x[-3], x[-2], x[-1], x[0], … x[N-1])
  • a vector of 4 initial conditions for the system (y[-4], y[-3], y[-2], y[-1])
  • the number of output samples N
    في حد عندو فكرة كيف تكتب الشفرة لهذا السؤال ؟؟[/left][/size]

اخى العزيز يمكنك البدء فى حل المطلوب وفى حالة اى مشكلة يمكنك طرح سؤالك هنا

شكرا على المتابعه اخي الكريم
هذا هو الكود الذي توصلت لكتابته

[LEFT]function out = dtout(in,Ic,N)
out = zeros(1,N+4);
for i= 1:4,
out(i)=Ic(i);
end

for i= 5:N+4,
out(i) = 0.4032in(i) - 0.7039in(i-2) + 0.4032in(i-4) + 0.2876out(i-2) - 0.3121*out(i-4);
end

[/left]

اعتقد بانه ليس من الممكن ان نعبر بشكل مباشر عن السستم باستخدام دالة فلتر filter لان السستم يحوي على انيشل كوندشنس لا تساوي اصفار

[CENTER]ممكن الحل يكون هكذا

clear all; clc;

% Our System
% y[n] = 0.4032x[n] - 0.7039x[n-2] + 0.4032x[n-4] + 0.2876y[n-2] - 0.3121y[n-4]


% Number of output samples
N=10;

% Initial conditions (Random N+4 values)
% Note : we cannot use negative index in Matlab=> the first element x(1) 
% is equivalent to x(-4)
x=rand(N+4,1);

% Vector of 4 initial conditions for the system (Random 4 values)
% Note : we cannot use negative index in Matlab=> the first element y(1) 
% is equivalent to y(-4)
yo=rand(4,1);

yout=dtout(N,x,yo)

القيم الاولية وضعتها عشوائية، يمكنك تغييرها بالطبع

والدالة تكون

function [y]=dtout(N,x,yo)
% Construct the y vector (N+4 values)
y=[yo;zeros(N,1)];

% Calculating
for i = 5:(N+4);
    y(i)=0.4032*x(i)-0.7039*x(i-2)+0.4032*x(i-4)+0.2876*y(i-2)-0.3121*y(i-4);
end

% output the N last velues of y
y=y(5:N+4);
end

الحل ليس معقد

فقط انتبه لل index الخاص بكل vector

بالتوفيق

[/center]

اخي الكريم DzArticles
احسنت على التوضيح … اعتقد ان الكود الذي كتبته انت مقارب ان لم يكن مشابه للكود الذي وضعته انا … مع فارق التوضيح … غير اني وضعت السستم في لوبين … اللوب الاول يمثل الانيشيل كوندشنز واللوب الثاني يمثل قم الاخراج تبعا للادخال

function out = dtout(in,Ic,N)
out = zeros(1,N+4);
for i= 1:4,
    out(i)=Ic(i);
end

for i= 5:N+4,
    out(i) = 0.4032*in(i) - 0.7039*in(i-2) + 0.4032*in(i-4) + 0.2876*out(i-2) - 0.3121*out(i-4);
end

هنا شطر اخر من السؤال
Plot the magnitude frequency response of the system . Plot the magnitude only and use a linear (rather than logarithmic, or dB) magnitude axis. Hint: freqz(), abs(), plot().