גרפים

מתוך מעבדת מבוא בחשמל
קפיצה אל: ניווט, חיפוש

1 מטלאב

1.1 גרף הדגמת FFT ו-THD

איור 1: הדגמה של THD
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% FFT with THD example                                        %%%
  3. %%% based on https://www.mathworks.com/help/matlab/ref/fft.html %%%
  4. %%% with a few modifications                                    %%%
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. Fs = 1000; % Sampling frequency                    
  7. T = 1/Fs; % Sampling period       
  8. L = 300; % Length of signal
  9. t = (0:L-1)*T; % Time vector
  10. freq = 50; % frequency
  11. S1 = 5*sin(2*pi*freq*t); % 1st (base) harmony
  12. S2 = 2*sin(2*pi*3*freq*t); % 2nd harmony distortion
  13. S = S1 + S2;
  14. f = Fs*(0:(L/2))/L;
  15. Y = fft(S);
  16. P2 = abs(Y/L);
  17. P1 = P2(1:L/2+1);
  18. P1(2:end-1) = 2*P1(2:end-1);
  19.  
  20. figure('Name','THD example');
  21. subplot(311);
  22. plot(t,S1,t,S2);
  23. title('Two pure sine waves');
  24. ylabel('Amplitude [V]');
  25. xlabel('Time [S]');
  26. legend(['1st harmony: ',num2str(freq),' Hz'],['2nd harmony: ',num2str(3*freq),' Hz']);
  27. subplot(312);
  28. plot(t,S);
  29. title(['Addition of the above two sine waves with frequencies of ',num2str(freq),' and ',num2str(3*freq),' Hz']);
  30. ylabel('Amplitude [V]');
  31. xlabel('Time [S]');
  32. subplot(313);
  33. plot(f,P1);
  34. title('Single-Sided Amplitude Spectrum of 1st (base) harmony + 2nd harmony');
  35. xlabel('f (Hz)');
  36. ylabel('Amplitude [V]');
  37.  
  38. set(gcf, 'Position', [600, 80, 800, 900]);

1.2 ייצוג ספקטראלי של גלים יסודיים

יש לשנות את המשתנה wave לערכים של בין 1 ל-6 כדי לקבל את ששת הגלים השונים:

  1. סינוסי
  2. ריבועי
  3. שן-מסור
  4. משולש
  5. חצי-גל סינוסי מיושר
  6. סדרת-דפקים
איור 2: גל שן-מסור והייצוג הספקטראלי שלו
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% FFT based on                                       %%%
  3. %%% https://www.mathworks.com/help/matlab/ref/fft.html %%%
  4. %%% with a few modifications                           %%%
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. freq = 1000; % frequency
  7. Fs = freq*20; % Sampling frequency                    
  8. T = 1/Fs; % Sampling period       
  9. L = 200; % Length of signal
  10. t = (0:L-1)*T; % Time vector
  11.  
  12. % three different waves
  13. RMS_Amplitude = 1;
  14. x = 2*pi*freq*t;
  15. d=20/100;  % Duty cycle for pulse wave
  16. Names = {'Sine', 'Square', 'Sawtooth', 'Triangle','Half rectified sine','Pulse'};
  17. Amplitudes = [sqrt(2), 1, sqrt(3), sqrt(3), 2, 1/sqrt(d)] * RMS_Amplitude;
  18. half_wave = sin(x); half_wave(find(half_wave<0))=0;
  19. pulse_wave = pulstran(x,(0:9)*max(x)/10,@rectpuls,d*max(x)/10);
  20. Waves = {sin(x), square(x), sawtooth(x), sawtooth(x,0.5), half_wave, pulse_wave};
  21. wave = 6; % actual wave to display
  22.  
  23. S=Amplitudes(wave)*Waves{wave};
  24. f = Fs*(0:(L/2))/L;
  25. Y = fft(S);
  26. P2 = abs(Y/L);
  27. P1 = P2(1:L/2+1);
  28. P1(2:end-1) = 2*P1(2:end-1);
  29.  
  30. figure('Name','FFT example');
  31. set(gcf, 'Position', [600, 80, 800, 900]);
  32. ax=subplot(211);
  33. plot(t,S); % plot wave
  34. title(['Original ',Names{wave},' wave']);
  35. ylabel('Amplitude [V]');
  36. xlabel('Time [S]');
  37. if max(ax.YLim)==max(S)
  38.     ax.YLim=ax.YLim*1.1;
  39. end
  40. ax=subplot(212);
  41. P1_RMS=P1;
  42. non_DC=find(f>freq/2); % find non DC frequencies
  43. P1_RMS(non_DC)=P1_RMS(non_DC)/sqrt(2); % calculate RMS
  44. plot(f,P1_RMS); % plot FFT of wave
  45. title(['FFT of the ',Names{wave},' wave']);
  46. xlabel('f (Hz)');
  47. ylabel('Amplitude [RMS V]');
  48. if max(ax.YLim)==max(P1_RMS)
  49.     ax.YLim=ax.YLim*1.1;
  50. end

1.3 בניית גלים יסודיים באמצעות הרמוניות

זוהי תוכנה הופכית ממה שמופיע בייצוג ספקטראלי של גלים יסודיים, הפעם באמצעות נוסחא של ההרמוניות - בונים את הגל הסופי.

יש לשנות את המשתנה wave_num לערכים של בין 1 ל-6 כדי לקבל את ששת הגלים השונים:

  1. גל ריבועי
  2. סדרת-דפקים
  3. מיישר חצי-גל
  4. מיישר גל-מלא
  5. גל שן-מסור
  6. גל משולש
איור 3: הדגמה של בניית סדרת-פולסים באמצעות הרמוניות
איור 4: סדרת-פולסים אשר מורכבת מ-1000 הרמוניות
  1. % structure for fourer waves
  2. % 1: Name, 2: RMS Coefficient, 3: DC Average, 4: Series of harmonies, 5: Stand alone harmony if any
  3. fourier_waves = {;
  4.     {'Square', '1', '0', '4*A/pi*sin((2*n-1)*w0.*t)/(2*n-1)'};
  5.     {'Pulse', '1/sqrt(d)', 'A*d', '2*A/(n*pi)*sin(n*pi*d)*cos(n*w0.*t)'};
  6.     {'Half wave rectified sine', '2', 'A/pi', '-2*A/pi*cos(2*n*w0.*t)/(4*n^2-1)', 'A/2*sin(w0.*t)'};
  7.     {'Full wave rectified sine wave', 'sqrt(2)', '2*A/pi', '-4*A/pi*cos(2*n*w0.*t)/(4*n^2-1)'};
  8.     {'Saw tooth wave', 'sqrt(3)', '0', '-2*A/pi*sin(n*w0.*t)/n'};
  9.     {'Triangle wave', 'sqrt(3)', '0', '8*A/pi^2*cos((2*n-1)*w0.*t)/(2*n-1)^2'}
  10. };
  11. wave_num = 2;                   % which wave to depict
  12. wave = fourier_waves{wave_num}; % get data for selected wave
  13.  
  14. A_RMS = 1; % Amplitude in volts RMS
  15. d=20/100;  % Duty cycle for pulse wave
  16. RMS_coef=eval(wave{2});
  17. A=A_RMS * RMS_coef;
  18. f = 1000;  % frequency in Hz
  19. harmonies = 1000; % How many harmonies to sum up
  20. T=1/f;     % period
  21. t=linspace(-T,T,1001); % resolution of two full periods
  22. w0=2*pi*f;             % fundamental harmony
  23. y=zeros(size(t));      % allocate memory for the harmonics addition
  24. figure('Name', [wave{1},' wave']);         % create a plot window
  25. set(gcf, 'Position', [600, 80, 800, 900]); % change window size
  26. fourier_wave_prefix=wave{3}; % prefix of Fourier series
  27. fourier_wave=wave{4};        % addends of the Fourier series
  28. if length(wave)==5
  29.     fourier_wave1=wave{5};   % out of serise harmony
  30. else
  31.     fourier_wave1=0;
  32. end
  33. subplots=9;                  % how many subplot steps to show
  34. rows=sqrt(subplots); cols=rows;
  35. axs=cell(1,subplots);        % save all axes for normalization
  36. y_max=0; y_min=0;
  37. for harmony=0:harmonies            % sums up all the harmonis
  38.     switch harmony
  39.         case 0
  40.             n=0;
  41.             % calculate DC (harmony 0)
  42.             f_n=eval(fourier_wave_prefix);
  43.         case 1
  44.             % calculate another harmony
  45.             if fourier_wave1==0
  46.                 f_n=eval(fourier_wave);
  47.             else
  48.                 f_n=eval(fourier_wave1);
  49.                 n=n-1;
  50.                 fourier_wave1=0;
  51.             end
  52.         otherwise
  53.             f_n=eval(fourier_wave);
  54.     end
  55.     y=y+f_n;
  56.     % plot the intermediary series summation
  57.     if harmony<subplots-1
  58.         axs{harmony+1}=subplot(rows,cols,harmony+1);
  59.         plot(t,y);
  60.         switch harmony
  61.             case 0
  62.                 title('DC (harmony 0)');
  63.             case 1
  64.                 title('First harmony only');
  65.             otherwise
  66.                 title(sprintf('Summation of %d harmonies',harmony));
  67.         end
  68.         y_min=min(min(y), y_min); y_max=max(max(y), y_max);
  69.     end
  70.     n=n+1;
  71. end
  72. axs{subplots}=subplot(rows,cols,subplots);
  73. plot(t,y); % plot the final wave
  74. title(['Summation of ',num2str(harmonies),' harmonies']);
  75. % normalize all axes
  76. dy=y_max-y_min;
  77. ylim=[y_min-dy/10, y_max+dy/10];
  78. for i=1:subplots
  79.     axs{i}.YLim=ylim;
  80. end
  81.  
  82. % plots actual wave (with 1k harmonies) in a new window
  83. figure('Name','Actual wave');
  84. plot(t,y);
  85. ax=gca;
  86. ax.YLim=ylim;
  87. xlabel('Time [S]');
  88. ylabel('Amplitude [V]');
  89. title([wave{1},' wave']);

1.4 גרף הפרש-מופע

איור 5: הפרש-מופע בציר הזמן
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% Plots two sine waves with       %%%
  3. %%% phase and amplitude differences %%%
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. f = figure; % create a plot window
  6. cycles = 2+1/16;    % display about 2 cycles
  7. frequency = 1000; % 1 kHz frequency
  8. total_x = 2*pi*cycles; % total horizontal length
  9. x = linspace(0,total_x,1000); % horizontal axis - time scale
  10. A1 = 1; % 1st amplitude
  11. y1 = A1*sin(x); % vertical axis - voltage/current scale
  12. phase = 2*pi/3; % create a phase difference
  13. A2 = 0.7; % 2nd amplitude
  14. y2 = A2*sin(x-phase); % another wave with phase difference
  15. plot(x,y1,'k',x,y2,'b','LineWidth',3); % plot the graphs
  16. h1 = gca; % Get handle to Current Axis (1)
  17. h1.YLim = [-1.25, 1.25]; % set scale of figure 1
  18. left1 = pi/2; % left cursor at maximum point
  19. right1 = left1 + 2*pi; % next peak
  20. dx = (right1-left1)/20;
  21. annotation('doublearrow',x_to_norm_v2(left1+dx, right1-dx),y_to_norm_v2(A1, A1),'Color','k','LineWidth',2);
  22. text(left1+(right1-left1)/2,A1+0.1,'T','Color','k','HorizontalAlignment','Center');
  23. refline(0,0); % add horizontal reference line
  24. left2 = pi/2 + phase;
  25. right2 = left2 + 2*pi; % next peak
  26. annotation('doublearrow',x_to_norm_v2(left2+dx, right2-dx),y_to_norm_v2(A2, A2),'Color','b','LineWidth',2);
  27. text(left2+(right2-left2)/2,A2+0.1,'T','Color','b','HorizontalAlignment','Center');
  28. % plot vertical lines (cursors) for peaks
  29. hold on;
  30. cursor1x=[left1, left1]; cursor1y=[-0.75, A1]; % left cursor
  31. cursor2x=[left2, left2]; cursor2y=[-0.75, A2]; % right cursor
  32. plot(cursor1x, cursor1y, 'k--', cursor2x, cursor2y, 'b--','LineWidth',2); % plot cursors
  33. annotation('doublearrow',x_to_norm_v2(left1+dx, left2-dx), y_to_norm_v2(-0.75, -0.75), 'Color','r','LineWidth',2); % add ruler
  34. text(left1+(left2-left1)/2,-0.75+0.1,'\Delta T','Color','r','HorizontalAlignment','Center');
  35. % plot vertical lines (cursors) for zero crossings
  36. hold on;
  37. left1z=2*pi;
  38. right1z=2*pi+phase;
  39. cursor1xz=[left1z, left1z]; cursor1yz=[-1, 0]; % left cursor
  40. cursor2xz=[right1z, right1z]; cursor2yz=[-1, 0]; % right cursor
  41. plot(cursor1xz, cursor1yz, 'k--', cursor2xz, cursor2yz, 'b--','LineWidth',2); % plot cursors
  42. annotation('doublearrow',x_to_norm_v2(left1z+dx, right1z-dx), y_to_norm_v2(-1, -1), 'Color','m','LineWidth',2); % add ruler
  43. text(left1z+(right1z-left1z)/2,-1+0.1,'\Delta T','Color','m','HorizontalAlignment','Center');

1.5 גרף עקומות ליסאז'ו

איור 6: עקומות ליסאז'ו בקפיצות של 30°
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% Plots Lissajous curve shapes %%%
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. figure('Name','Liss');
  5. % draw a unit circle in the middle
  6. subplot(5,5,[7:9,12:14,17:19]);
  7. phi_ind=0:11;
  8. phi_rad=phi_ind*pi/6; % phase shifts in radians
  9. phi_deg=phi_ind*30;   % phase shifts in degrees
  10. z=exp(j*phi_rad);
  11. compass(z);
  12. numbers=findall(gcf,'Type','text');
  13. for i=1:numel(numbers)
  14.     txt = numbers(i).String;
  15.     if isempty(regexp(txt,'0$'))
  16.         % erase non degrees numbers
  17.         numbers(i).Visible='off';
  18.     else
  19.         % add degrees symbol
  20.         numbers(i).String=[txt,'^\circ'];
  21.     end
  22. end
  23. xt=linspace(0,2*pi,1000);
  24. x=sin(xt);
  25. plot2angle=[15, 10, 4, 3, 2, 6, 11, 16, 22, 23, 24, 20];
  26. for i=phi_ind
  27.     ax = subplot(5,5,plot2angle(i+1));
  28.     y=sin(xt + phi_rad(i+1)); % add phase to y
  29.     plot(x,y); % plot the curve
  30.     % increase gap between plot and frame
  31.     ax.XLim=ax.XLim*1.1;
  32.     ax.YLim=ax.YLim*1.1;
  33.     % remove labels
  34.     ax.YTickLabel={};
  35.     ax.XTickLabel={};
  36.     % create title for each subplot
  37.     phis = [phi_deg(i+1), phi_deg(i+1)-360];
  38.     if (phis(1) > 180)
  39.         phis = fliplr(phis);
  40.     else
  41.         if phis(1) == 0
  42.             phis(2) = 360; % instead of -360
  43.         end
  44.     end
  45.     title(sprintf('%d^\\circ = %d^\\circ', phis));
  46.     grid on;
  47. end
  48. % equalize the scale of y and x axes
  49. set(gcf, 'Position', [100, 100, 900, 1000]);

1.6 תגובה לתדר של מעגל RC

איור 7: תגובה לתדר של מעגל RC
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% Create a frequency response for RC circuit %%%
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. f = 1000;         % 1kHz frequency
  5. R = 1000;         % 1kΩ Resistance
  6. C = 1/(2*pi*f*R); % 0.159µF Capacitance
  7. numer = [1]; denom = [R*C*1 1]; % Hc(s)=1/(1+RCs)
  8. w = logspace(0,6,1000); % 10^0 to 10^6 angular-frequency range
  9. freqs(numer,denom,w); % create the graph
  10. set(gcf, 'Position', [600, 80, 800, 900]); % enhance resolution


1.7 אופיין חשל מגנטי

איור 8: עקומת חשל מגנטי
  1. %%%%%%%%%%%%%%%%%%%%%%
  2. %%% Plot B-H curve %%%
  3. %%%%%%%%%%%%%%%%%%%%%%
  4. try
  5.   % worked on matlab version R2017a
  6.   bhsim = sim('elec_inductor_hysteresis','MaxStep','1e-5');
  7.   simlog = get(bhsim,'simlog_elec_inductor_hysteresis');
  8. catch
  9.   % worked on matlab version R2016b
  10.   bhsim = sim('elec_inductor_with_hysteresis','MaxStep','1e-5');
  11.   simlog = get(bhsim,'simlog');
  12. end
  13. inductor=simlog.Nonlinear_Inductor.inductor;
  14. H=inductor.H.series.values;
  15. B=inductor.B.series.values;
  16. figure('Name','B-H Hysteresis');
  17. plot(H,B);
  18. set(gcf, 'Position', [100, 100, 900, 1000]);
  19. grid on;
  20. xlabel('H [A/m]');
  21. ylabel('B [T]');
  22. % to disable 'Error due to multiple causes' for next runs
  23. close_system();


1.8 גרף תופעת מעבר במעגל RL

איור 9: תופעת מעבר הזרם של מעגל RL טורי
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% Draw transient reponse of RL circuit %%%
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. V=10;     % power-supply voltage [V]
  5. R=10000;  % resistor value [Ω]
  6. L=10;     % inductor value [H]
  7. tau=L/R;  % time constant tau [s]
  8. t=linspace(0,10*tau,1001); % time axis
  9. il=V/R+(0-V/R)*exp(-t/tau);
  10. figure('Name','RL circuit');
  11. plot(t,il,'LineWidth',2);
  12. % signage
  13. xlabel('time [s]');
  14. ylabel('i_L [A]');
  15. title('RL circuit transient response');
  16. hold on;
  17. % extract special tau points
  18. x = (1:5)*tau;
  19. [~,il_tau]=intersect(t,x);
  20. y = il(il_tau);
  21. % calculate axis limits
  22. max_y = max(y) * 1.2;
  23. max_x = max(t) * 1.1;
  24. min_y = -max_y / 12;
  25. min_x = -max_x / 11;
  26. % draw cross lines to emphasize special tau points
  27. for i = 1:length(x)
  28.     plot([min_x,x(i),x(i)],[y(i),y(i),min_y]);
  29. end
  30. legend('i_L','1\tau','2\tau','3\tau','4\tau','5\tau');
  31. % change axis
  32. ax=gca;
  33. ax.YLim=[min_y max_y];
  34. ax.YAxis.Exponent = -3;
  35. ax.XLim=[min_x max_x];

1.9 תגובה לתדר ותדר-זוויתי של מעגל RL טורי

איור 10: תגובה לתדר-זוויתי של מעגל RL טורי
איור 11: תגובה לתדר של מעגל RL טורי
  1. R=10000;   % Resistor value [Ω]
  2. L=10;      % Inductor value [H]
  3. tau=L/R;   % time constant
  4. cutoff=1/(2*pi*tau);         % Cutoff frequency [Hz]
  5. f=linspace(0,cutoff*5,1000); % Frequency sweep [Hz]
  6. w=2*pi*f;      % Angular frequency sweep [rad/sec]
  7. Vin=10;
  8. ZL=j*w*L; % Inductor Impedance
  9. Vr=Vin*R./(R+ZL);  % Complex Voltage of resistor
  10. VL=Vin*ZL./(R+ZL); % Complex Voltage of inductor
  11. mag_vr=abs(Vr);% get the magnitude of resistor's voltage
  12. mag_vL=abs(VL);% get the magnitude of inductor's voltage
  13.  
  14. % Plot voltage vs. angular frequency
  15. figure; hold on;
  16. set(0, 'DefaultLineLineWidth', 2);
  17. plot(w,mag_vr,w,mag_vL);            % plot graphs
  18. plot([2*pi*cutoff 2*pi*cutoff],[0 Vin]);        % mark the cutoff vertically
  19. plot([0 max(w)],[Vin/sqrt(2) Vin/sqrt(2)]); % mark the cutoff horizontally
  20. % add signage
  21. title('V_{OUT} vs. Angular Frequency');
  22. xlabel('Angular Frequency [rad/s]');
  23. ylabel('Voltage [V]');
  24. legend('Resistor voltage','Inductor voltage','Cutoff X','Cutoff Y');
  25.  
  26. % Plot voltage vs. frequency
  27. figure; hold on;
  28. plot(f,mag_vr,f,mag_vL);            % plot graphs
  29. plot([cutoff cutoff],[0 Vin]);        % mark the cutoff vertically
  30. plot([0 max(f)],[Vin/sqrt(2) Vin/sqrt(2)]); % mark the cutoff horizontally
  31. % add signage
  32. title('V_{OUT} vs. Frequency');
  33. xlabel('Frequency [1/s]=[Hz]');
  34. ylabel('Voltage [V]');
  35. legend('Resistor voltage','Inductor voltage','Cutoff X','Cutoff Y');

1.10 תופעת מעבר במעגל RC עם מקור סינוסי

איור 12: תופעת מעבר במעגל RC עם מקור סינוסי והעלמתה באמצעות שינוי זווית המופע של אות המקור
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% Plot RC circuit transient response with Sine wave input %%%
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. theta=pi/4; % Phase angle of AC input
  5. AC = calcRC(theta,'ac');
  6.  
  7. % RC Transient response equation
  8. RCTrans=calcRC(theta,'trans');
  9. RCSteadyState=calcRC(theta,'steady');
  10. RCTransWithSine=RCTrans+RCSteadyState;
  11.  
  12. % calculate exponential decay
  13. RCDecay=calcRC(theta,'decay');
  14.  
  15. % calculate theta which will cancel the transient response
  16. corrected_theta=calcRC(0,'correction');
  17. RCNoTrans=calcRC(corrected_theta,'both');
  18.  
  19. % plot input and output of original theta
  20. figure('Name','RC with AC source');
  21. subplot(2,1,1);
  22. t=calcRC(0,'time');
  23. plot(t,AC,t,RCTransWithSine,t,RCDecay,[min(t),max(t)],[0,0]);
  24. legend('AC Input','Output (capacitor)','Decay envelope','Reference point');
  25. xlabel('Time [s]'); ylabel('Voltage [v]');
  26. title(calcRC(theta,'title'));
  27. % plot input and output of corrected theta
  28. subplot(2,1,2);
  29. plot(t,calcRC(corrected_theta,'ac'),t,RCNoTrans,[min(t),max(t)],[0,0]);
  30. legend('AC input shifted','Output (capacitor)','Reference point');
  31. xlabel('Time [s]'); ylabel('Voltage [v]');
  32. title(calcRC(corrected_theta,'title'));
  33. % change axis
  34. ax=gca;
  35. top=max(AC);
  36. ax.YLim=[-top-1, top+1];
  37. set(gcf, 'Position', [100, 100, 600, 800]);
  38.  
  39. % AC input/Transient/SteadyState response of RC circuit
  40. function response = calcRC(angle,role)
  41.     Vm=10; % Amplitude of sine wave
  42.     V0=2; % Initial voltage of capacitor
  43.     f=700; % frequency of AC input
  44.     w=2*pi*f; % angular frequency
  45.     count=10; % how many time constants to plot
  46.     R=10e3; % Resistor of 10kΩ
  47.     C=0.1e-6; % Capacitor of 0.1µF
  48.     tau=R*C; % Time constant
  49.     t=linspace(0,count*tau,1000); % Time axis
  50.  
  51.     switch lower(role)
  52.         case 'title'
  53.             response = sprintf('V_S(t)=%dsin(2\\pi\\cdot%dt+%d^\\circ); V_0=%dV',Vm,f,round(angle/pi*180),V0);
  54.         case 'time'
  55.             %%% returns the time axis
  56.             response = t;
  57.         case 'correction'
  58.             %%% returns angle to cancel out transient response
  59.             response = asin(V0/Vm*sqrt(1+(w*tau)^2))-atan(-w*tau);
  60.         case 'both'
  61.             %%% return entire response (transient and steady state)
  62.             response = calcRC(angle,'trans') + calcRC(angle,'steady');
  63.         case 'trans'
  64.             %%% return transient response
  65.             response = (V0-Vm*sin(angle+atan(-w*tau))/sqrt(1+(w*tau)^2))*exp(-t/tau);
  66.         case 'steady'
  67.             %%% return steady state response
  68.             response = Vm/sqrt(1+(w*tau)^2)*sin(w*t+angle+atan(-w*tau));
  69.         case 'ac'
  70.             %%% AC input of circuit;
  71.             response = Vm*sin(w*t+angle);
  72.         case 'decay'
  73.             %%% returns decay envelope
  74.             % max voltage of full response
  75.             [peakVolt, peakInd]=max(calcRC(angle,'both'));
  76.             peakTime=t(peakInd);
  77.             % voltage diff of peak and steady state
  78.             MAXSteady=max(calcRC(angle,'steady'));
  79.             dV=peakVolt-MAXSteady;
  80.             response = dV*exp(-(t-peakTime)/tau)+MAXSteady;
  81.     end
  82. end

1.11 גרף מצבי ריסון

איור 13: ארבעת סוגי הריסון
  1. %%%%%%%%%%%%%%%%%%%%%%
  2. %%% Damping ratios %%%
  3. %%%%%%%%%%%%%%%%%%%%%%
  4. figure('Name','Damping');
  5. hold on;
  6. % iterate thru a few different resistor values
  7. Rs=[1000,5000,20e3,100e3,1e6];
  8. Rs_len = length(Rs);
  9. h = zeros(1,Rs_len);
  10. legend_text = cell(1,Rs_len);
  11. t=linspace(0,0.005,10000);
  12. for i=1:Rs_len
  13.     R=Rs(i); % Current resitor in Ω
  14.     vc=solve_ode(R); % solve current ODE
  15.     vct=double(vc(t)); % fill in values
  16.     h(i)=plot(t,vct,'LineWidth',2); % plot current solution
  17.     % create description for each resistor type
  18.     if R < 5e3
  19.         info = '- overdamped';
  20.     elseif R == 5e3
  21.         info = '- critically damped';
  22.     elseif R >= 1e6
  23.         info = '~ undamped (lossless)';
  24.     else
  25.         info = '- underdamped';
  26.     end
  27.     legend_text{i}=['R=',num2str(R),' \Omega ',info];
  28.     legend(h(1:i),legend_text{1:i}); % update legend
  29.     drawnow; % view plots during run
  30. end
  31. % signage
  32. xlabel('Time [S]');
  33. ylabel('V_C [V]');
  34. title('Different damping ratios');
  35. grid on;
  36. set(gcf,'Position',[100,100,800,600])
  37.  
  38. % solve second order ode of type
  39. % y''+2α*y'+w^2*y=w^2*V
  40. % y(0)=V0
  41. % y'(0)=-1/C*(V0/R+I0);
  42. function solution = solve_ode(R)
  43.     C=0.01e-6; % Capacitor in F
  44.     L=1; % Inductor in H
  45.  
  46.     tau=R*C; % Time constant
  47.     alpha=1/(2*tau); % Damping factor
  48.     w0=1/sqrt(L*C); % natural frequency
  49.  
  50.     V = 10; % Input voltage
  51.     V0=5; % Initial capacitor voltage
  52.     I0=0; % Initial inductor current
  53.  
  54.     dVc0=-1/C*(V0/R+I0); % Derivate of capacitor's voltage at t=0
  55.  
  56.     % Based on
  57.     % https://www.mathworks.com/help/symbolic/solve-a-single-differential-equation.html
  58.     syms y(t)
  59.     Dy = diff(y);
  60.     ode = diff(y,t,2)+2*alpha*Dy+w0^2*y == w0^2*V;
  61.     cond1 = y(0) == V0;
  62.     cond2 = Dy(0) == dVc0;
  63.     conds = [cond1, cond2];
  64.     ySol(t) = dsolve(ode, conds);
  65.  
  66.     solution = simplify(ySol);
  67. end

1.12 ניתוח נתונים מאורקד

איור 14: חישוב ערכי סימולציית אורקד באמצעות מטלאב
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. % Analyze rectifier data from orcad %
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. csv = load('orcaddata.csv');
  5. % get timestamps
  6. time = csv(:,1);
  7. % get voltage of resistor
  8. vr = csv(:,2);
  9. % maximum voltage
  10. Vm = max(vr);
  11. % calculate average
  12. VDC = mean(vr);
  13. % calculate rms
  14. VDCRMS = rms(vr);
  15. % calculate form factor
  16. FF = VDCRMS/VDC;
  17. % calculate ripple factor
  18. RF = sqrt(FF^2-1);
  19. % plot all data
  20. figure('Name','Rectifier');
  21. total_x=[0 max(time)];
  22. plot(time,vr,total_x,[Vm Vm],total_x,[VDC VDC],0,0,0,0,0,0);
  23. txtVm=['V_m=',num2str(Vm),'V'];
  24. txtVDC=['V_{DC}=',num2str(VDC),'V'];
  25. txtVDCRMS=['V_{DCRMS}=',num2str(VDCRMS),'V'];
  26. txtFF=['Form Factor=',num2str(FF)];
  27. txtRF=['Ripple Factor=',num2str(RF)];
  28. legend('V_R',txtVm,txtVDC,txtVDCRMS,txtFF,txtRF);
  29. xlabel('Time [s]');
  30. ylabel('Amplitude [V]');
  31. ax=gca;
  32. ax.YLim=[min(vr)-1, max(vr)+1];

1.13 שליפת הפרש-מופע מעקומת ליסאז'ו

איור 15: סימוני עקומת ליסאז'ו המדגימים כיצד לשלוף את הפרמטרים המאפשרים את חישוב הפרש-המופע בין שני גלים
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% Plot of Lissajous curve with  %%%
  3. %%%   markes to extract the phase %%%
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. t = linspace(0,2*pi,1000); % time between 0 and 2*pi
  6. f = 1; % frequency in Hz
  7. V1 = 4; % amplitude of first wave
  8. wave1 = V1*sin(2*pi*f*t); % a sine wave
  9. phi = pi/4; % phase difference of 45 degrees
  10. V2 = 30; % amplitude of second wave
  11. wave2 = V2*sin(2*pi*f*t+phi); % same sine wave but with a phase
  12.  
  13. figure('Name','Lissajous');
  14. hold on;
  15. plot(wave1, wave2, 'k','LineWidth',3); % plot the graphs
  16. ax = gca; % Get handle of Current Axis (1)
  17. ax.YLim = ax.YLim*1.25; % increase Y scale
  18. ax.XLim = ax.XLim*1.25; % increase X scale 
  19.  
  20. % calculate the contact points on the Lissajous curve
  21. a1 = [0, abs(V2*sin(phi))]; % top a
  22. a2 = [0, -abs(V2*sin(phi))]; % bottom a
  23. b1 = [V1*cos(phi), abs(V2)]; % top b
  24. b2 = [-V1*cos(phi), -abs(V2)]; % bottom b
  25.  
  26. % write the names of the points
  27. gap_x = V1*0.1;
  28. gap_y = V2*0.1;
  29. text(a1(1)+gap_x, a1(2), 'a1', 'FontSize', 14, 'Color', 'r');
  30. text(a2(1)+gap_x, a2(2), 'a2', 'FontSize', 14, 'Color', 'r');
  31. text(b1(1), b1(2)+gap_y, 'b1', 'FontSize', 14, 'Color', 'b');
  32. text(b2(1), b2(2)-gap_y, 'b2', 'FontSize', 14, 'Color', 'b');
  33.  
  34. % plot horizontal lines for the contact points
  35. a1x=[-V1/2, a1(1)]; a1y=[a1(2), a1(2)]; % top middle
  36. plot(a1x, a1y, 'r--', 'LineWidth',2); % plot line
  37. a2x=[-V1/2, a2(1)]; a2y=[a2(2), a2(2)]; % bottom middle
  38. plot(a2x, a2y, 'r--', 'LineWidth',2); % plot line
  39. b1x=[0, b1(1)+gap_x]; b1y=[b1(2), b1(2)]; % top middle
  40. plot(b1x, b1y, 'b--', 'LineWidth',2); % plot line
  41. b2x=[b2(1), b1(1)+gap_x]; b2y=[b2(2), b2(2)]; % bottom middle
  42. plot(b2x, b2y, 'b--', 'LineWidth',2); % plot line
  43.  
  44. % plot a vertical line between a1 and a2
  45. annotation('doublearrow',x_to_norm_v2(-V1/3, -V1/3),y_to_norm_v2(a1(2), a2(2)),'Color','r','LineWidth',2);
  46. % plot a vertical line between b1 and b2
  47. annotation('doublearrow',x_to_norm_v2(b1(1), b1(1)),y_to_norm_v2(b1(2), b2(2)),'Color','b','LineWidth',2);
  48.  
  49. % write the names of the vertical lines
  50. text(-V1/3+gap_x, a1(2)/2, 'a', 'FontSize', 14, 'Color', 'r');
  51. text(b1(1)+gap_x, -V2/2, 'b', 'FontSize', 14, 'Color', 'b');
  52.  
  53. % turn on grid and draw X, Y axes
  54. grid on;
  55. gray=0.4*ones(1,3);
  56. annotation('arrow',x_to_norm_v2(ax.XLim(1), ax.XLim(2)),y_to_norm_v2(0, 0),'Color',gray,'LineWidth',2);
  57. annotation('arrow',x_to_norm_v2(0, 0),y_to_norm_v2(ax.YLim(1), ax.YLim(2)),'Color',gray,'LineWidth',2);
  58. text(0-gap_x,V2+gap_y,'y', 'FontSize', 14, 'Color', gray);
  59. text(V1+gap_x,0-gap_y,'x', 'FontSize', 14, 'Color', gray);
  60.  
  61. % draw green circles as the points
  62. for dots={a1,a2,b1,b2}
  63.     dot=dots{1};
  64.     plot([dot(1), dot(1)], [dot(2), dot(2)], 'o', 'Color', 'g', 'MarkerSize',10, 'MarkerFaceColor','g');
  65. end

2 ג'אווה-סקריפט

2.1 מסנן מעביר גבוהים או נמוכים

איור 16: אופיין של מסנן מעביר נמוכים
  1. var rand = {random};
  2.  
  3. // high pass = 1, low pass = 0
  4. var high_pass = Math.round(rand);
  5. // grid frequency (MUST BE ROUND)
  6. var grid_frequency = Math.round(6*rand+4);
  7. // maximum voltage
  8. var volt_size = Math.round((10*rand+2)*100)/100;
  9. // Maximum frequency for sweep is between 100 kHz and 10 MHz
  10. var max_frequency = Math.pow(10,Math.round(3*rand+5));
  11.  
  12. // frequency of internal sine wave
  13. var frequency = 30;
  14. // the frequency in the middle of the sweep
  15. var middle_frequency = max_frequency / 2;
  16. // Resistor size in Ohm
  17. var R = 160;
  18. // Capcitor size in Farad
  19. var C = 1e-6;
  20.  
  21. // define a canvas dimensions along with grid lines
  22. var w=500;
  23. var h=360;
  24. var grid_y=grid_frequency;
  25. var grid_x=grid_frequency*2-1;
  26. var hs=h*(grid_y-1)/grid_y; // sub height
  27.  
  28. // create a canvas inside the table
  29. var c = document.createElement("canvas");
  30. c.setAttribute("width",w);
  31. c.setAttribute("Height",h);
  32. var element = document.getElementById("insertcanvashere_sweep");
  33. element.appendChild(c);
  34.  
  35. var ctx = c.getContext("2d");
  36. // set style of text
  37. ctx.font="20px Georgia";
  38.  
  39. ctx.save();
  40. // set the style of grid lines
  41. ctx.setLineDash([1, 3]);/*dashes are 5px and spaces are 3px*/
  42. ctx.strokeStyle="blue";
  43.  
  44. // dispersion of x grid lines
  45. var skip_x = w/(grid_frequency*2);
  46.  
  47. var y;
  48. // draw x grid
  49. var half = Math.floor(grid_y/2);
  50. // pixels amount of each y gridline
  51. var skip_h = h/grid_frequency;
  52. // position in which to right voltage
  53. var mark_y = Math.round(rand*(half-2))+1;
  54. for (var i=0; i<grid_y; i++) {
  55. 	y=(-half+i)*skip_h+h/2;
  56. 	ctx.beginPath();
  57. 	ctx.moveTo(0,y);
  58. 	ctx.lineTo(w,y);
  59. 	ctx.stroke();
  60. 	// write voltages
  61. 	if (i==half) {
  62. 		ctx.fillText("0 V",w/2,y - 5);
  63. 		// draw different color for the period
  64. 		ctx.save();
  65. 		ctx.setLineDash([1, 0]);
  66. 		ctx.strokeStyle="black";
  67. 		ctx.stroke();
  68. 		ctx.restore();
  69. 	}
  70. 	if (i==mark_y) {
  71. 		// calculate voltage at current point
  72. 		var voltage = (half - mark_y) * skip_h * 2 / hs * volt_size;
  73. 		round_volt = Math.round(voltage * 1000) / 1000;
  74. 		ctx.fillText(round_volt.toString() + 'V',w/2,y - 5);
  75. 		// draw different color for the period
  76. 		ctx.save();
  77. 		ctx.setLineDash([10, 6]);
  78. 		ctx.strokeStyle="black";
  79. 		ctx.stroke();
  80. 		ctx.restore();
  81. 	}
  82. }
  83. min_y=y;
  84.  
  85. // draw y grid
  86. var period=middle_frequency / grid_frequency;
  87. var total_period=0;
  88. var x_counter=0;
  89. for (var x=skip_x; x<w; x+=skip_x) {
  90. 	ctx.beginPath();
  91. 	ctx.moveTo(x,0);
  92. 	ctx.lineTo(x,h);
  93. 	ctx.stroke();
  94. 	// write time period
  95. 	total_period+=period;
  96. 	x_counter++;
  97. 	if ((x_counter==2) || (x_counter==grid_x-2)) {
  98. 		var round_period = Math.round(total_period * 10) / 10;
  99. 		var units = 'Hz';
  100. 		if (x_counter != 2) {
  101. 			round_period = total_period / 1000; 
  102. 			round_period = Math.round(round_period * 10) / 10;
  103. 			units = 'kHz';
  104. 		}
  105. 		ctx.fillText(round_period.toString() + units,x,h - 10);
  106. 		// draw different color for the period
  107. 		ctx.save();
  108. 		ctx.setLineDash([10, 6]);
  109. 		ctx.strokeStyle="black";
  110. 		ctx.stroke();
  111. 		ctx.restore();
  112. 	}
  113. }
  114. ctx.restore();
  115.  
  116. // choose LPF
  117. var filter_function='1/(omega*R*C+1)';
  118. if (high_pass == 1) {
  119. 	// choose HPF
  120. 	filter_function='omega*R*C/(omega*R*C+1)';
  121. }
  122. // draw a positive RC response graph
  123. ctx.beginPath();
  124. ctx.moveTo(0,h/2);
  125. var max_frequency_log=Math.log10(max_frequency);
  126. for (var x=1; x<w; x++) {
  127. 	// calculate the logarithmic frequency
  128. 	current_frequency=Math.pow(10,x/w*max_frequency_log);
  129. 	var omega = 2 * Math.PI * current_frequency;
  130. 	y=eval(filter_function);
  131. 	y=h/2-y*hs/2;
  132. 	ctx.lineTo(x,y);
  133. }
  134. ctx.strokeStyle="red";
  135. ctx.stroke();
  136. // draw a negative RC response graph
  137. ctx.beginPath();
  138. ctx.moveTo(0,h/2);
  139. for (var x=1; x<w; x++) {
  140. 	// calculate the logarithmic frequency
  141. 	current_frequency=Math.pow(10,x/w*max_frequency_log);
  142. 	var omega = 2 * Math.PI * current_frequency;
  143. 	y=eval(filter_function);
  144. 	y=y*hs/2+h/2;
  145. 	ctx.lineTo(x,y);
  146. }
  147. ctx.strokeStyle="red";
  148. ctx.stroke();
  149. // draw a sine wave inside the RC response
  150. ctx.beginPath();
  151. ctx.moveTo(0,h/2);
  152. for (var x=1; x<w; x++) {
  153. 	current_frequency=Math.pow(10,x/w*max_frequency_log);
  154. 	var omega = 2 * Math.PI * current_frequency;
  155. 	var amplitude=eval(filter_function);
  156. 	y=amplitude*hs/2*Math.sin(2*Math.PI*frequency*x/w)+h/2;
  157. 	ctx.lineTo(x,y);
  158. }
  159. ctx.strokeStyle="green";
  160. ctx.stroke();

2.2 ניתוח גל סינוס - הוצאת תדר

איור 17: גל סינוסואידלי לשליפת התדר
  1. var total_time = {total_time};
  2. var volt_size = {volt_size};
  3. var frequency = {frequency};
  4.  
  5. var w=500;
  6. var h=360;
  7. var grid_y=7;
  8. var grid_x=frequency*2-1;
  9. var hs=h*(grid_y-1)/grid_y; // sub height
  10.  
  11. var c = document.createElement("canvas");
  12. c.setAttribute("width",w);
  13. c.setAttribute("Height",h);
  14.  
  15. var element = document.getElementById("insertcanvashere_freq");
  16. element.appendChild(c);
  17.  
  18. var ctx = c.getContext("2d");
  19. ctx.font="20px Georgia";
  20.  
  21. ctx.save();
  22. ctx.setLineDash([1, 3]);/*dashes are 5px and spaces are 3px*/
  23. ctx.strokeStyle="blue";
  24.  
  25. var skip_x = w/(frequency*2);
  26.  
  27. var y, max_y;
  28. // draw x grid
  29. var half = Math.floor(grid_y/2);
  30. var skip_y = volt_size / half;
  31. var voltage = 1;
  32. for (var i=0; i<grid_y; i++) {
  33. 	y=(-half+i)*(h/grid_y)+h/2;
  34. 	if (i==0) {
  35. 		max_y=y;
  36. 	}
  37. 	ctx.beginPath();
  38. 	ctx.moveTo(0,y);
  39. 	ctx.lineTo(w,y);
  40. 	ctx.stroke();
  41. 	// write voltages
  42. 	if (i==half-1) {
  43. 		//ctx.fillText(skip_y.toString() + 'V',skip_x * 2,y - 5);
  44. 	}
  45. }
  46. min_y=y;
  47.  
  48. // draw y grid
  49. var period=total_time / frequency;
  50. var total_period=0;
  51. var half = Math.ceil(grid_x/2);
  52. for (var x=skip_x; x<w; x+=skip_x) {
  53. 	ctx.beginPath();
  54. 	ctx.moveTo(x,0);
  55. 	ctx.lineTo(x,h);
  56. 	ctx.stroke();
  57. 	// write time period
  58. 	total_period+=period;
  59. 	half--;
  60. 	if (half==0) {
  61. 		round_period = Math.round(total_period * 1000) / 1000;
  62. 		ctx.fillText(round_period.toString() + 'ms',x,min_y + 10);
  63. 		// draw different color for the period
  64. 		ctx.save();
  65. 		ctx.setLineDash([10, 6]);
  66. 		ctx.strokeStyle="black";
  67. 		ctx.stroke();
  68. 		ctx.restore();
  69. 	}
  70. }
  71. ctx.restore();
  72.  
  73. // draw a sine wave
  74. ctx.beginPath();
  75. ctx.moveTo(0,h/2);
  76. for (var x=1; x<w; x++) {
  77. 	y=hs/2*Math.sin(2*Math.PI*frequency*x/w)+h/2;
  78. 	ctx.lineTo(x,y);
  79. }
  80. ctx.strokeStyle="red";
  81. ctx.stroke();

2.3 ניתוח גל סינוס - מתח אפקטיבי

איור 18: גל סינוסואידלי לשליפת המתח
  1. var total_time = {total_time};
  2. var frequency = {frequency};
  3. var volt_size = {volt_size};
  4.  
  5. var w=500;
  6. var h=360;
  7. var grid_y=Math.round(frequency+4);
  8. var grid_x=frequency*2-1;
  9. var hs=h*(grid_y-1)/grid_y; // sub height
  10.  
  11. var c = document.createElement("canvas");
  12. c.setAttribute("width",w);
  13. c.setAttribute("Height",h);
  14.  
  15. var element = document.getElementById("insertcanvashere_volt");
  16. element.appendChild(c);
  17.  
  18. var ctx = c.getContext("2d");
  19. ctx.font="20px Georgia";
  20.  
  21. ctx.save();
  22. ctx.setLineDash([1, 3]);/*dashes are 5px and spaces are 3px*/
  23. ctx.strokeStyle="blue";
  24.  
  25. var skip_x = w/(frequency*2);
  26.  
  27. var y, max_y;
  28. // draw x grid
  29. var half = Math.floor(grid_y/2);
  30. var skip_y = volt_size / ((grid_y-1)/2);
  31. var voltage = 1;
  32. for (var i=0; i<grid_y; i++) {
  33. 	y=(-half+i)*(h/grid_y)+h/2;
  34. 	if (i==0) {
  35. 		max_y=y;
  36. 	}
  37. 	ctx.beginPath();
  38. 	ctx.moveTo(0,y);
  39. 	ctx.lineTo(w,y);
  40. 	ctx.stroke();
  41. 	// write voltages
  42. 	if (i==half) {
  43. 		ctx.fillText('0',w/2,y - 5);
  44. 		// draw different color for the period
  45. 		ctx.save();
  46. 		ctx.setLineDash([1, 0]);
  47. 		ctx.strokeStyle="black";
  48. 		ctx.stroke();
  49. 		ctx.restore();
  50. 	}
  51. 	if (i==half-1) {
  52. 		round_volt = Math.round(skip_y * 1000) / 1000;
  53. 		ctx.fillText(round_volt.toString() + 'V',w/2,y - 5);
  54. 		// draw different color for the period
  55. 		ctx.save();
  56. 		ctx.setLineDash([10, 6]);
  57. 		ctx.strokeStyle="black";
  58. 		ctx.stroke();
  59. 		ctx.restore();
  60. 	}
  61. }
  62. min_y=y;
  63.  
  64. // draw y grid
  65. var period=total_time / frequency;
  66. var total_period=0;
  67. var half = Math.ceil(grid_x/2);
  68. for (var x=skip_x; x<w; x+=skip_x) {
  69. 	ctx.beginPath();
  70. 	ctx.moveTo(x,0);
  71. 	ctx.lineTo(x,h);
  72. 	ctx.stroke();
  73. 	// write time period
  74. 	total_period+=period;
  75. 	half--;
  76. 	if (half==1000) {
  77. 		round_period = Math.round(total_period * 1000) / 1000;
  78. 		ctx.fillText(round_period.toString() + 'ms',x,min_y + 10);
  79. 		// draw different color for the period
  80. 		ctx.save();
  81. 		ctx.setLineDash([10, 6]);
  82. 		ctx.strokeStyle="black";
  83. 		ctx.stroke();
  84. 		ctx.restore();
  85. 	}
  86. }
  87. ctx.restore();
  88.  
  89. // draw a sine wave
  90. ctx.beginPath();
  91. ctx.moveTo(0,h/2);
  92. for (var x=1; x<w; x++) {
  93. 	y=hs/2*Math.sin(2*Math.PI*frequency*x/w)+h/2;
  94. 	ctx.lineTo(x,y);
  95. }
  96. ctx.strokeStyle="red";
  97. ctx.stroke();