Reputation: 437
I've been given the formula below to apply to a signal. I'm not sure how to plug this into Matlab, can anyone explain?
y(n) =1/8[2x(n) + x(n − 1) − x(n − 3) − 2x(n − 4)]
Upvotes: 2
Views: 1879
Reputation: 35088
If x
is your input signal and y
is your output, the expression you have can be regarded as an FIR filter. You can write the coefficients of x
in a vector as b = (1/8)*[2, 1, 0, -1, -2];
(the 0 in the middle is the coefficient of x(n-2)
). Then you can apply it to your input data vector x
using the filter
function: y = filter(b, 1, x);
(the 1 in the middle represents the coefficient of y(n)
).
It may also be of interest to see the frequency response of the filter. To do so, you can use the freqz
command: freqz(b,1);
. See the documentation for more details, including how to calibrate the x-axis of the plot in Hz. Use of this function requires the Signal Processing Toolbox from the Mathworks.
Upvotes: 4