Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.34 KB | None | 0 0
  1. q1=dlmread('D:\F19\MTE360\Lab1\Lab 1\lab1_q1a.txt')
  2. q1_tab= array2table(q1);
  3. q1_tab.Properties.VariableNames{1} = 'Time';
  4. q1_tab.Properties.VariableNames{2} = 'Input Voltage';
  5. q1_tab.Properties.VariableNames{3} = 'Output Voltage';
  6. findpeaks(q1(:,[3]), 'MinPeakDistance', 500, 'MinPeakHeight', 1);
  7. [pks, locs]=findpeaks(q1(:,[3]), 'MinPeakDistance', 500, 'MinPeakHeight', 1);
  8.  
  9. q1_tab=table(q1_tab.Time, q1_tab.("Output Voltage"));
  10. q1_tab_append=q1_tab(1500:2000, :);
  11. %Second cycle used
  12.  
  13. tau_v_Val= 0.6321*pks(2);
  14. [minDistance, indexOfMin]= min(abs(q1_tab_append.Var2-tau_v_Val));
  15. tau_v= q1_tab_append.Var1(indexOfMin)-1.5;
  16.  
  17. K_v= pks(2);
  18. t_v=tau_v;
  19.  
  20. open('vel_step.mdl'); % opens the model file
  21. sim('vel_step.mdl'); % runs the simulation
  22.  
  23. time=ScopeData1.time; %scope data in milliseconds
  24. response=ScopeData1.signals.values;
  25.  
  26. inTime=ScopeData.time;
  27. inVals=ScopeData.signals.values;
  28.  
  29. theoretical=table(time,  response);
  30.  
  31. figure(2)
  32. subplot(2,1,1);
  33. plot(theoretical.time, theoretical.response)
  34. hold on
  35. plot(q1(:,[1]),q1(:,[3]))
  36. xlim([0 4])
  37. ylim([-300 300])
  38. legend({'Theoretical', 'Measured'})
  39. title('Velocity Real vs. Theoretical');
  40. ylabel('Velocity [mm/s]');
  41. xlabel('Time [s]');
  42.  
  43. subplot(2,1,2);
  44. plot(inTime,inVals)
  45. xlim([0 4])
  46. ylim([-2 2])
  47. title('Input Voltage');
  48. ylabel('Voltage [V]');
  49. xlabel('Time [s]');
  50. legend({'Input'})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement