Write two Matlab functions that will apply the differentiator and integrator systems designed in section 2.1 to arbitrary input signals. T
时间: 2024-02-25 14:59:06 浏览: 72
Here are two Matlab functions that apply a differentiator and integrator system to arbitrary input signals:
1. Function for Differentiator System:
```matlab
function y = differentiator(x, fs)
% x: input signal
% fs: sampling frequency
% Differentiator Coefficients
a = [1 -1];
b = [1 0];
% Filter Signal
y = filter(b, a, x);
% Scale Filter Response
y = y .* (fs/2);
end
```
2. Function for Integrator System:
```matlab
function y = integrator(x, fs)
% x: input signal
% fs: sampling frequency
% Integrator Coefficients
a = [1 -1];
b = [1 1];
% Filter Signal
y = filter(b, a, x);
% Scale Filter Response
y = y ./ (fs/2);
end
```
Both functions take an input signal `x` and the sampling frequency `fs` as input arguments. The differentiator function applies a high-pass filter to the input signal, which amplifies the high frequency components of the signal and attenuates the low frequency components. The integrator function applies a low-pass filter to the input signal, which amplifies the low frequency components of the signal and attenuates the high frequency components.
Both functions use the `filter` function in Matlab to apply the filter coefficients to the input signal. After filtering, the output signal is scaled by a factor of `fs/2` for the differentiator function and `1/(fs/2)` for the integrator function to ensure that the gain of the filter is 1 at DC.
阅读全文