% Program P1_1 % Simulation of an M-point Moving Average Filter % Generate the input signal clear, close all, n = 0:100; s1 = cos(2pi0.05n); % A low-frequency sinusoid s2 = cos(2pi0.47n); % A high frequency sinusoid x = s1+s2; % Implementation of the moving average filter M = input('Desired length of the filter = '); num = ones(1,M); y = filter(num,1,x)/M; % Display the input and output signals subplot(2,2,1); plot(n, s1); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Signal #1'); subplot(2,2,2); plot(n, s2); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Signal #2'); subplot(2,2,3); plot(n, x); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Input Signal'); subplot(2,2,4); plot(n, y); axis([0, 100, -2, 2]); xlabel('Time index n'); ylabel('Amplitude'); title('Output Signal');y[n] = 0.5(x[n]+x[n-1])变成y[n] = 0.5(x[n]-x[n-1])实现代码
时间: 2024-04-01 21:33:10 浏览: 22
以下是将移动平均滤波器转换为差分滤波器的实现代码:
clear, close all, n = 0:100;
s1 = cos(2*pi*0.05*n); % A low-frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2; % Generate the input signal
M = input('Desired length of the filter = ');
num = [1, -1]/2; % Coefficients for the difference filter
y = filter(num, 1, x); % Apply the difference filter
% Display the input and output signals
subplot(2,2,1); plot(n, s1); axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude'); title('Signal #1');
subplot(2,2,2); plot(n, s2); axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude'); title('Signal #2');
subplot(2,2,3); plot(n, x); axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude'); title('Input Signal');
subplot(2,2,4); plot(n, y); axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude'); title('Output Signal');
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)