Having issues getting magnitude frequency response for a Difference equation

조회 수: 5 (최근 30일)
Bernardo Rodriguez Jr
Bernardo Rodriguez Jr 2022년 4월 29일
답변: nick 2023년 11월 23일
I'm having trouble with an asignment (I started using Matlab a day ago) in which I need to get the magnitude of a difference equation as well as get the unit impulse response and store it in an array.
After some time looking online, and teaching myself how to do the z-transform, I managed to get this as my code:
% Difference equation -> y(n) = 0.2*x(n) + 0.34*x(n-10)
%Transform to z-plane -> H(z) = Y(z)/X(z) = 0.2 + 0.34z^-10
A = [0.2 0 0 0 0 0 0 0 0 0 0.34];
B = 1;
% Creates the transform function and plots magnitude/phase
H = filt(A,B);
figure;
bode(H);
% Plots unit impulse response
figure;
impulse(H);
The only probelm is that it isn't what my professor is looking for nor would he give an indication of what to do. I can't seem to find any documents online to help me with the problem, I'm not sure what it would fall under, however I think that I need to use the frequency response function? Any help would be much appreciated.
  댓글 수: 1
Bernardo Rodriguez Jr
Bernardo Rodriguez Jr 2022년 4월 29일
Update
I'm currently attempting this for the magnitude, but i'm still unsure if it is correct:
j = sqrt(-1);
w = linspace(-pi, pi);
H = 0.2 - 0.34*exp(-j*10*w);
figure;
stem(abs(H));

댓글을 달려면 로그인하십시오.

답변 (1개)

nick
nick 2023년 11월 23일
Hi Bernardo,
I understand from your query that you want to obtain the magnitude and impulse response of the difference equation.
I am assuming the given difference equation is a discrete time equation as you have used Z-transform. Thus, you are working with digital filters. You must use 'freqz' instead of 'bode' to obtain the frequency response, phase and magnitude, of digital filters. You may refer the following documentation of 'freqz' to learn more about it :
Similarly, you must use 'impz' instead of 'impulse' to obtain impulse response of digital filters. You may refer the following documentation to learn more about 'impz':
Hope this helps,
Regards,
Neelanshu

카테고리

Help CenterFile Exchange에서 Analog Filters에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by