我想实现一个消除更高频率的滤波器。在这个例子中,我想消除 sin 曲线并保持线性曲线。
编辑:
我更正了我的代码,但是我为过滤而实现的功能显着改变了数据的边缘,这是不可接受的。
clc; clear all;
xaxis = linspace(1, 10, 1000);
data = xaxis + sin(xaxis*3);
Nf = 2^12;
xAxisf = linspace(-10,10,Nf);
% plot(xaxis, data);
% FFT
xsize = numel(data);
Xf = zeros([1 Nf]);
indices = Nf/2-floor(xsize/2):Nf/2-floor(xsize/2)+xsize - 1;
Xf(indices) = data;
% Xf = fftshift(Xf);
Xf = fft(Xf);
Xf = fftshift(Xf);
% plot
Xfa = abs(Xf); plot(xAxisf, Xfa);
% generate super-gaussian filter function
Nf = numel(Xf);
widthfilter = 0.12;
filterpower = 2;
filter = exp(-(xAxisf.^2./widthfilter^2).^filterpower);
% filter
filtertimes = 20;
Xf = Xf .* filter.^filtertimes;
% plot
Xfa = abs(Xf); plot(Xfa);
% iFFt
Xfs = ifftshift(Xf);
Xif = ifft(Xfs);
% Xif = ifftshift(Xif);
result = abs(Xif);
plot(result(indices))