Is there any easy way to handle difference equation in MATLAB ?
10 次查看（过去 30 天）
So currenlty i am working on difference equation and for example i am just taking the differnce equation as :
h(n) = 0.1δ(n) + 0.2δ(n − 2) + 0.5δ(n − 3).
what i have been doing so far is the trivial approrach of iterating over all values of n and making a vector 'h' out of that but that will become useless if the number of n goes to very large .So i am looking currently if i can have a optimistic way to get the frequency/Phase/Magnitude responses.
Thanks for your time and patience.
Harsh Kumar 2023-6-28
I understand that you are trying to solve difference equations optimistically in MATLAB.
To do this , you can take the Discrete Time Fourier Transform of ‘h_n’ initially only to convert your system to frequency domain instead of iterating it over the whole values of n.
Please refer to the below code snippet for better understanding.
%defining the h_n using logic operations
title('Real part of DTFT')
You can refer to this documentation as well if you want to use the inbuilt DTFT function :- Link
Consider looking into the freqz function. An example code that I was able to create is as follows:
% Defining the coefficients of the difference equation
b = [0.1, 0.2, 0.5]; % Numerator coefficients corresponding to the equation you mentioned
a = ; % Denominator coefficients (default is 1)
% Compute the frequency response
[h, w] = freqz(b, a);
% Plot the magnitude response
subplot(2, 1, 1);
% Plot the phase response
subplot(2, 1, 2);