Guest User

Untitled

a guest
Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. clc;
  2. close all;
  3. clear all;
  4.  
  5. % L1 - 14
  6. % L2 - 15
  7. % R9 - 22
  8. % R10 - 23
  9. % LHipAngleX - 470
  10. % RHipAngleX - 486
  11. % LKneeAngleX - 474
  12. % RKneeAngleY - 490
  13.  
  14. fileName_a = '..\data\cw_1_chod_do_przodu_T01a.CSV';
  15. fileName_v = '..\data\cw_1_chod_do_przodu_T01v.CSV';
  16.  
  17. % fileName_a = '..\data\cw_3_chod_szybki_do_przodu_T01a.CSV';
  18. % fileName_v = '..\data\cw_3_chod_szybki_do_przodu_T01v.CSV';
  19.  
  20. % fileName_a = '..\data\cw_3_chod_szybki_do_przodu_T02a.CSV';
  21. % fileName_v = '..\data\cw_3_chod_szybki_do_przodu_T02v.CSV';
  22.  
  23. importedData = importdata(fileName_a, ',', 1);
  24. data1 = importedData.data(:, 22)';
  25. data2 = importedData.data(:, 23)';
  26.  
  27. importedData = importdata(fileName_v, ',', 1);
  28. dataPosition = importedData.data(:, 490)';
  29.  
  30. fs = 1000;
  31. N = size(data1, 2);
  32. time = 0:(1/fs):((N-1)/fs);
  33.  
  34. color1 = 'magenta';
  35. color2 = 'r';
  36.  
  37. %% high pass filter
  38. [B,A] = cheby1(5, 2, 6/fs*2, 'high');
  39.  
  40. [h,w] = freqz(B,A);
  41. mag = abs(h);
  42. phase = angle(h);
  43.  
  44. x = 0.5*(1:size(mag,1))/size(mag,1);
  45.  
  46. filteredData1 = filter(B,A, data1);
  47. filteredData2 = filter(B,A, data2);
  48. %% MAV
  49. window = 10;
  50.  
  51. mavData1 = mav(data1, window);
  52. mavFilteredData1 = mav(filteredData1, window);
  53. mavFilteredData1_2 = mavFilteredData1.^2;
  54.  
  55. mavData2 = mav(data2, window);
  56. mavFilteredData2 = mav(filteredData2, window);
  57. mavFilteredData2_2 = mavFilteredData2.^2;
  58.  
  59. %% FFT
  60. fftOryginal1 = abs(fft(data1));
  61. fftOryginal2 = abs(fft(data2));
  62. fftFiltered1 = abs(fft(filteredData1));
  63. fftFiltered2 = abs(fft(filteredData2));
  64.  
  65. %% plot
  66.  
  67. % filter characteristic
  68. hFilChar = figure;
  69. subplot(2,1,1);
  70. plot(x, mag);
  71. title('magnitude characteristics');
  72. XLabel('f/fs');
  73. subplot(2,1,2);
  74. plot(x, phase/pi*180);
  75. title('phase characteristics');
  76. XLabel('f/fs');
  77.  
  78. % FFT of signal 1
  79. hSig1Char = figure;
  80. subplot(2,1,1);
  81. plot((0:(N/2-1))/N, fftOryginal1(1:N/2)/N*2, color1);
  82. title('oryginal syginal [rectus femoris]');
  83. XLabel('f/fs');
  84. subplot(2,1,2);
  85. plot((0:(N/2-1))/N, fftFiltered1(1:N/2)/N*2, color1);
  86. title('high pass filter [rectus femoris]');
  87. XLabel('f/fs');
  88.  
  89. % FFT of signal 2
  90. hSig2Char = figure;
  91. subplot(2,1,1);
  92. plot((0:(N/2-1))/N, fftOryginal2(1:N/2)/N*2, color2);
  93. title('oryginal syginal [rectus femoris]');
  94. subplot(2,1,2);
  95. plot((0:(N/2-1))/N, fftFiltered2(1:N/2)/N*2, color2);
  96. title('high pass filter [rectus femoris]');
  97.  
  98. % MAV on signal 1
  99. hSig1Mav = figure;
  100. subplot(3,1,1);
  101. plot(time, data1, color1);
  102. title('oryginal data [rectus femoris]');
  103. XLabel('time [s]');
  104. subplot(3,1,2);
  105. plot(time(1:10:end),mavFilteredData1, color1);
  106. title('high pass and MAV [rectus femoris]');
  107. XLabel('time [s]');
  108. subplot(3,1,3);
  109. plot(time(1:10:end),mavFilteredData1_2, color1);
  110. title('signal energy [rectus femoris]');
  111. XLabel('time [s]');
  112.  
  113. % MAV on signal 2
  114. hSig2Mav = figure;
  115. subplot(3,1,1);
  116. plot(time, data2, color2);
  117. title('oryginal data [biceps femoris]');
  118. XLabel('time [s]');
  119. subplot(3,1,2);
  120. plot(time(1:10:end),mavFilteredData2, color2);
  121. title('high pass and MAV [biceps femoris]');
  122. XLabel('time [s]');
  123. subplot(3,1,3);
  124. plot(time(1:10:end),mavFilteredData2_2, color2);
  125. title('signal energy [biceps femoris]');
  126. XLabel('time [s]');
  127.  
  128. % data normaliation
  129. dataPosition = dataPosition/90;
  130. mavFilteredData1_2 = mavFilteredData1_2/max(mavFilteredData1_2);
  131. mavFilteredData2_2 = mavFilteredData2_2/max(mavFilteredData2_2);
  132.  
  133. % plot summary
  134. hSum = figure;
  135. subplot(3,1,1);
  136. plot(time(1:10:end), dataPosition, time(1:10:end), mavFilteredData1_2, color1);
  137. title('summary [rectus femoris]');
  138. legend('knee position', 'rectus femoris');
  139. XLabel('time [s]');
  140. subplot(3,1,2);
  141. plot(time(1:10:end), dataPosition, time(1:10:end), mavFilteredData2_2, color2);
  142. XLabel('time [s]');
  143. title('summary [biceps femoris]');
  144. legend('knee position', 'biceps femoris');
  145. subplot(3,1,3);
  146. plot(time(1:10:end), dataPosition, time(1:10:end), mavFilteredData1_2, color1, time(1:10:end), -mavFilteredData2_2, color2);
  147. XLabel('time [s]');
  148. title('summary');
  149. legend('knee position', 'rectus femoris', 'biceps femoris');
  150.  
  151. %% figure saving
  152. folderName = 'images';
  153.  
  154. if exist(folderName, 'dir') == 0
  155. mkdir(folderName);
  156. end
  157.  
  158. delete('images\*');
  159. saveas(hFilChar, 'images\fiterCharacteristic', 'png');
  160. saveas(hSig1Char, 'images\signal1Characteritic', 'png');
  161. saveas(hSig2Char, 'images\signal2Characteritic', 'png');
  162. saveas(hSig1Mav, 'images\signal1Mav', 'png');
  163. saveas(hSig2Mav, 'images\signal2Mav', 'png');
  164. saveas(hSum, 'images\summary', 'png');
Add Comment
Please, Sign In to add comment