Is there any easy way to handle difference equation in MATLAB ?
40 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ram
le 28 Juin 2023
Réponse apportée : Harsh Kumar
le 28 Juin 2023
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.
0 commentaires
Réponse acceptée
Harsh Kumar
le 28 Juin 2023
Hi Ram,
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.
n=-20:1:20;
%defining the h_n using logic operations
h_n=0.1*(n==0)+0.2*(n==2)+0.5*(n==3);
%frequency
w=-2*pi:(4*pi)/40:2*pi;
subplot(411)
stem(n,(h_n));
title('Original function')
%DTFT
subplot(412)
stem(w,real(dtft(h_n,n,w)));
title('Real part of DTFT')
%Angle plot
subplot(413)
stem(w,angle(dtft(h_n,n,w)));
title('Angle function')
%Magnitude plot
subplot(414)
stem(w,abs(dtft(h_n,n,w)));
title('Magnitude function')
p=dtft(h_n,n,w);
%DTFT function
function[x_w]=dtft(x_n,n,w)
x_w=x_n*(exp((1i)*-1*transpose(n)*w));
end
0 commentaires
Plus de réponses (1)
Jacob Mathew
le 28 Juin 2023
Hi Ram,
% Defining the coefficients of the difference equation
b = [0.1, 0.2, 0.5]; % Numerator coefficients corresponding to the equation you mentioned
a = [1]; % Denominator coefficients (default is 1)
% Compute the frequency response
[h, w] = freqz(b, a);
% Plot the magnitude response
subplot(2, 1, 1);
plot(w, abs(h));
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response');
% Plot the phase response
subplot(2, 1, 2);
plot(w, angle(h));
xlabel('Frequency');
ylabel('Phase');
title('Phase Response')
0 commentaires
Voir également
Catégories
En savoir plus sur Vibration Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!