Advertisement
Guest User

3DOF Decomposition

a guest
Apr 27th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.00 KB | None | 0 0
  1. % HW7
  2.  
  3. clc,clear,close all
  4.  
  5. %% Signals
  6.  
  7. addpath('/Users/jahdielgierboliniserrano/Desktop/INGE5037/HW7/');
  8. S1 = load('S1.txt')'; S2 = load('S2.txt')'; l = length(S1);
  9.  
  10. % time vector
  11. sf = 100; dt = 1/sf; t = 0:dt:dt*(l-1);
  12.  
  13. % figures
  14. subplot(211); plot(t,S1); ylabel('clean response');
  15. title('Clean (above) and noisy (below) signals vs time');
  16. subplot(212); plot(t,S2); ylabel('noisy response');
  17.  
  18. %% Part 1 (SNR)
  19.  
  20. noise = S2-S1; SNR = sum(S1.^2)/sum(noise.^2);
  21. N = sqrt(var(S1)/SNR);
  22. fprintf('SNR = %2.2f\n',SNR);
  23. fprintf('The level of noise is %0.3f\n\n',N);
  24.  
  25. %% Part 2 (FFT)
  26.  
  27. [f1,m1,p1] = osfft(t,S1,0,0,'none'); % clean signal
  28. [f2,m2,p2] = osfft(t,S2,0,0,'none'); % noisy signal
  29.  
  30. % figures
  31. figure;
  32. subplot(221); plot(f1,m1); ylabel('magnitude'); title('Clean Signal');
  33. xlim([0 10]);
  34. subplot(223); plot(f1,p1); ylabel('phase [rad]'); xlabel('freq. [Hz]');
  35. xlim([0 10]);
  36. subplot(222); plot(f2,m2); ylabel('magnitude'); title('Noisy Signal');
  37. xlim([0 10]);
  38. subplot(224); plot(f2,p2); ylabel('phase [rad]'); xlabel('freq. [Hz]');
  39. xlim([0 10]);
  40.  
  41. %% Bandpass Filters and Hilbert Transform
  42.  
  43. % from inspection of the FFT Spectra
  44. lba = 0; uba = 0.6/sf; lbb = uba; ubb = 1.3/sf; lbc = ubb; ubc = 2.7/sf;
  45.  
  46. % filter coefficients
  47. ba = pbfilter(l,sf,lba,uba,500); bb = pbfilter(l,sf,lbb,ubb,500);
  48. bc = pbfilter(l,sf,lbc,ubc,500);
  49.  
  50. % filtered signals
  51. S1a = conv(S1,ba,'same'); S1b = conv(S1,bb,'same'); % clean
  52. S1c = conv(S1,bc,'same'); S1f = [S1a' S1b' S1c']';
  53.  
  54. figure; subplot(211); plot(t,S1f); ylabel('amplitude'); title('Clean');
  55.  
  56. S2a = conv(S2,ba,'same'); S2b = conv(S2,bb,'same'); % noisy
  57. S2c = conv(S2,bc,'same'); S2f = [S2a' S2b' S2c']';
  58.  
  59. subplot(212); plot(t,S2f); ylabel('amplitude'); xlabel('time [s]');
  60. title('Noisy');
  61.  
  62. % Hilbert Transform
  63. [Am1,~,F1] = HilbertRes(S1f,sf);
  64. [Am2,~,F2] = HilbertRes(S2f,sf);
  65.  
  66. % Response Parameters
  67. [zi1,wn1,A1,phi1,s1] = fr1dof(t,S1f,Am1,F1);
  68. [zi2,wn2,A2,phi2,s2] = fr1dof(t,S2f,Am2,F2);
  69.  
  70. %% EMD and Hilbert Transform
  71.  
  72. %% Continuous Wavelet Transform
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement