Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. clc, close all, clear all;
  2.  
  3. %% generate a signal
  4. fx = 10e3;
  5. fc = 25*fx;
  6. Tstop = 20/fx;
  7. Amp = 1;
  8. t = 0:(1/fc):Tstop;
  9. rand = 0.25 * randn(size(t)); % additive white noise
  10.  
  11. signal = Amp * sin(2*pi*fx*t) + rand;
  12.  
  13. % figure()
  14. % plot(t, signal);
  15. % title('segnale - dominio del tempo');
  16. % xlabel('time [s]');
  17. % ylabel('amplitude');
  18.  
  19. %% decompose signal using DWT (discrete wavelet transform)
  20. level = 5;
  21. wname = 'db30';
  22. type = 'a';
  23. [C, L] = wavedec(signal, level, wname); % performs a multilevel 1-D wavelet analysis. C contains the wavelet decomposition. L contains the number of coefficients by level
  24. xN = waverec(C, L, wname); % performs a multilevel 1-D wavelet reconstruction
  25.  
  26. cAppr = appcoef(C, L, 'db30', level); % calcola l'ultima approssimazione
  27. [cD1 cD2 cD3 cD4] = detcoef(C, L, [1,2,3,4]); % calcola i dettagli
  28.  
  29. A = wrcoef(type, C, L, wname, level); % reconstructs the coefficients of a 1-D signal
  30. % type determines whether approximation ('a') or detail ('d') coefficients are reconstructed.
  31. figure(),
  32. for i= 1:level
  33. DD(i,:) = wrcoef('d', C, L, wname, i);
  34. subplot(level+2, 1, i);
  35. plot(DD(i,:));
  36. stringa = sprintf('dettaglio D%d', i);
  37. title(stringa);
  38. end
  39.  
  40. subplot(level+2, 1, level+1), plot(A);
  41. stringa = sprintf('approssimazione A%d', level);
  42. title(stringa);
  43. subplot(level+2, 1, level+2), plot(signal, 'r');
  44. title('segnale');
  45.  
  46. %% denoise the signal
  47. signald = wden(signal, 'rigrsure', 's', 'sln', level, wname); % automatic 1-D denoising using wavelets
  48. % signal - threshold technique - soft thresholding - threshold rescaling using single estimate of noise based on the first level coefficent - decomposition level - wavelet
  49. figure(),
  50. subplot(2, 1, 1);
  51. plot(signal);
  52. axis tight;
  53. grid on;
  54. title('noisy signal');
  55.  
  56. subplot(2, 1, 2);
  57. plot(signald);
  58. axis tight;
  59. grid on;
  60. title('denoised signal');
  61.  
  62. %%
  63. DN = detcoef(C, L, 1); % extracts the detail coefficients at level N from the wavelet decomposition structure [C,L]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement