1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| function [] = Filtering() clc; clear; close all;
m=100; dt=0.002; N=2^nextpow2(m); df=1/( N * dt );
[wavelet,~] = Ricker_zero(25,dt,m,3); wavelet(m+1:N) = 0;
fft_wavelet=fft(wavelet); amplitude_wavelet=abs(fft_wavelet);
f = 62.5; startFilter = f / df; endFilter = N - startFilter;
for i = 1 : N value(i) = 1; end for i = startFilter + 1 : endFilter - 1 value(i) = 0; end
for i = 1 : N value_slope(i)=1; end for i = (startFilter + 8) : (endFilter - 8) value_slope(i)=0; end for i = startFilter : startFilter + 8 value_slope(i) = -1/8 * i + 1 + 1/8 * startFilter; end for i = endFilter - 8 : endFilter value_slope(i) = 1/8 * i + 1 -1/8 * endFilter; end
for i = 1 : N freq_ideal(i) = value(i)*fft_wavelet(i); freq_slope(i) = value_slope(i)*fft_wavelet(i); end
ifft_wavelet_ideal=ifft(freq_ideal); ifft_wavelet_slope=ifft(freq_slope);
x=1:N; figure, subplot(2,3,1) plot(x,wavelet,'k','LineWidth',2.0) title('时间域雷克子波'),xlabel('Time(ms)'),ylabel('Amplitude'),axis([-inf inf -inf inf]),legend('主频25Hz,子波宽度3');
subplot(2,3,4) plot(x,amplitude_wavelet,'k','LineWidth',2.0) title('频率域振幅谱'),xlabel('Frequency(Hz)'),ylabel('Amplitude'),legend('主频25Hz'); set(gca,'XLim',[0 N]);
subplot(2,3,2) plot(x,value,'k',x,value_slope,'b','LineWidth',1.5) axis([-inf,inf,0,1.5]),title('低通滤波器'),xlabel('Frequency(Hz)'),legend('理想滤波器','带斜坡滤波器'); grid on subplot(2,3,5) plot(x,freq_ideal,'k',x,freq_slope,'b--','LineWidth',2.0) title('滤波后振幅谱'),xlabel('Frequency(Hz)'),ylabel('Amplitude'),legend('理想滤波器','带斜坡滤波器'),axis([-inf inf -inf inf]) grid on
subplot(2,3,3) plot(x,wavelet,'k',x,real(ifft_wavelet_ideal),'b-','LineWidth',2.0) title('理想滤波器'),legend('Origin Signal','After Filtering'),xlabel('Time(ms)'),ylabel('Amplitude'),axis([0 m -inf inf]) subplot(2,3,6) plot(x,wavelet,'k',x,real(ifft_wavelet_slope),'r-','LineWidth',2.0) title('带斜坡滤波器'),legend('Origin Signal','After Filtering'),xlabel('Time(ms)'),ylabel('Amplitude'),axis([0 m -inf inf]) end
function [wavelet_zero,time]=Ricker_zero(freqs,dt,nt,r)
tmin=0; tmax=dt*nt; time=tmin:dt:tmax; wavelet_zero=exp(-(2*pi*freqs/r)^2*time.^2).*cos(2*pi*freqs.*time); end
|