Impulse response of a FIR-filter in Matlab

조회 수: 74 (최근 30일)
Arjun Suhass
Arjun Suhass 2022년 1월 25일
댓글: tecnologynew 2024년 1월 29일
a have a simple question about a course i've been studying called "introduction to signal processing with matlab". I've been given a FIR-filter with coefficients b=[0.0201 0.2309 0.4981 0.2309 0.0201] and I have to calculate the impulse response of APKLUB. The impulse response from theory is the response of a system to unit impulse as an entry. the following commants in matlab give the same results:
b=[0.0201 0.2309 0.4981 0.2309 0.0201];
impz(b);
OR
b=[0.0201 0.2309 0.4981 0.2309 0.0201];
d_10=zeros(1,50);
d_10(10)=1;
x=conv(b,d_10);
stem(x,'r');
Are the results of these two the impulse rensponse of the Fir-filter or a have to do something more? Thank you...
  댓글 수: 2
Paul
Paul 2022년 1월 25일
The results from impz and x are not the the same, so both can't be the impulse response. Why make d_10(10) = 1 for computin the impulse response? Shouldn't the first element of d be 1 to compute the impulse response via convolution? Also, keep in mind that the single argument form of stem() as used above assumes that first point is at n = 1, but you really want the first point to be n = 0.
tecnologynew
tecnologynew 2024년 1월 29일
In MATLAB, you can obtain the impulse response of a Finite Impulse Response (FIR) filter using the filter function or the impz function. Here, I'll provide you with an example using the impz function.
Let's assume you have the coefficients of your FIR filter stored in a vector called h (representing the impulse response coefficients). You can use the impz function to obtain and plot the impulse response.
matlabCopy code
% FIR filter coefficients (replace this with your actual coefficients) h = [1, -0.5, 0.2, -0.1]; % Get and plot the impulse response impulse_response = impz(h); % Plot the impulse response stem(impulse_response); title('Impulse Response of FIR Filter'); xlabel('Sample Index'); ylabel('Amplitude'); % Optionally, you can also use the filter function to apply the filter to an impulse input % impulse_input = [1, zeros(1, 99)]; % Impulse signal % output_signal = filter(h, 1, impulse_input); % figure; % stem(output_signal); % title('Output of FIR Filter for Impulse Input'); % xlabel('Sample Index'); % ylabel('Amplitude');
Replace the h vector with the coefficients of your FIR filter. The impz function calculates the impulse response, and the stem function is used to plot the impulse response.
If you have the Signal Processing Toolbox, you can also use the fvtool function to visualize the filter's characteristics:
matlabCopy code
% FIR filter coefficients (replace this with your actual coefficients) h = [1, -0.5, 0.2, -0.1]; % Visualize the filter characteristics fvtool(h, 1, 'Analysis', 'impulse');
This will open the Filter Visualization Tool, where you can inspect various characteristics of your FIR filter, including the impulse response.

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

답변 (1개)

William Rose
William Rose 2022년 1월 26일
YOu can figure it out theoretically or by experiment.
Theoretical:
The Matlab help for filter() says:
In your case, a=1. If a had additional elements, it would be an IIR filter. You said it was FIR, so it must be the case that a=1. And therefore the equation above simplifies to
An impulse response is the sequence y(n), when x(n)=(1,0,0,0,0,...). Therefore, for an FIR filter, the impulse repsonse is just the vector b.
Experimental method:
Create an impulse signal, and filter it with b:
x=[1,0,0,0,0,0,0,0]; %impulse signal
b=[0.0201 0.2309 0.4981 0.2309 0.0201]; %FIR filter
yimpulse=filter(b,1,x) %filter the impulse with the FIR filter
yimpulse = 1×8
0.0201 0.2309 0.4981 0.2309 0.0230 0 0 0
Nice. The theoretical and experimental approaches give the same answer.
  댓글 수: 2
Paul
Paul 2022년 2월 1일
Why doesn't yimpulse(5) match the fifth element of b?
William Rose
William Rose 2022년 2월 1일
Good catch, @Paul!
I must have made a copy-paste mistake, because I just re-did the commands, the the output does match in the fifth position:

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

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by