【數字訊號去噪】 基於matlab小波軟閾值+硬閾值+改進閾值數字訊號去噪【含Matlab原始碼 1025期】
阿新 • • 發佈:2021-06-19
一、簡介
基於matlab小波軟閾值+硬閾值+改進閾值數字訊號去噪
二、原始碼
clc clear all close all fs = 20e3; % 取樣頻率 fn = 3e3; % 固有頻率 y0 = 5; % 位移常數 g = 0.1; % 阻尼係數 T = 0.01; % 重複週期 N = 4096; % 取樣點數 NT = round(fs*T); % 單週期取樣點數 t = 0:1/fs:(N-1)/fs; % 取樣時刻 t0 = 0:1/fs:(NT-1)/fs; % 單週期取樣時刻 K = ceil(N/NT)+1; % 重複次數 y = []; for i = 1:K y = [y,y0*exp(-g*2*pi*fn*t0).*sin(2*pi*fn*sqrt(1-g^2)*t0)]; end y = y(1:N); Yf = fft(y); % 頻譜 y5 = awgn(y,0.5,'measured'); % Add white Gaussian noise y10 = awgn(y,1,'measured'); % Add white Gaussian noise y15 = awgn(y,5,'measured'); % Add white Gaussian noise %%信噪比=0.5-------------------------------------------- mse12=MSE(y5,xdy12); PSNR12=PSNR(y5,xdy12); st=sprintf('經軟閾值函式去噪後的均方差=%.2f,信噪比=%.2f',mse12,PSNR12);disp(st) st=sprintf('經半軟閾值函式去噪後的均方差=%.2f,信噪比=%.2f',mse13,PSNR13);disp(st) figure(1); subplot(511);plot(t,y);axis([0,inf,-4,5]);title('原始訊號');xlabel('時間e(s)');ylabel('幅度') subplot(512);plot(t,y5);axis([0,inf,-4,5]);title('加入0.5db高斯白噪聲的訊號');xlabel('時間e(s)');ylabel('幅度') subplot(513);plot(t,xdy11);axis([0,inf,-4,5]);title('經硬閾值函式處理後的訊號');xlabel('時間e(s)');ylabel('幅度') subplot(514);plot(t,xdy12);axis([0,inf,-4,5]);title('經軟閾值函式處理後的訊號');xlabel('時間e(s)');ylabel('幅度') subplot(515);plot(t,xdy13);axis([0,inf,-4,5]);title('經半軟閾值函式處理後的訊號');xlabel('時間e(s)');ylabel('幅度') function X = denh(x, wname, n, thr) %硬閾值 [C, S] = wavedec2(x, n, wname); %進行小波分解 dcoef = C( prod(S(1, :)) + 1 : end); %高頻部分系數 ind = find( abs(dcoef) < thr) + prod(S(1, :)); %小於閾值thr的係數 C(ind)=0; % 直接置零 a=0.6; ind = find( abs(dcoef) >= thr) + prod(S(1, :)); %大於閾值thr的係數 C(ind) = C(ind); %按照公式處理 function X = denr(x, wname, n, thr) % 軟閾值 [C, S] = wavedec2(x, n, wname); %進行小波分解 dcoef = C( prod(S(1, :)) + 1 : end); %高頻部分系數 ind = find( abs(dcoef) < thr) + prod(S(1, :)); %小於閾值thr的係數 C(ind) = 0; % 直接置零
三、執行結果
四、備註
版本:2014a
完整程式碼或代寫加1564658423