This MATLAB code simulates three standard waveforms: square, triangular, and trapezoidal. It prompts the user to enter the number of waves and the width of each half period/peak value. It then displays a menu for the user to select which waveform to generate. Based on their selection, it will plot the corresponding waveform over time by creating and combining the appropriate segment vectors to represent each half period and piecewise define the shape. Axis labels and titles are also added to the plots.
This MATLAB code simulates three standard waveforms: square, triangular, and trapezoidal. It prompts the user to enter the number of waves and the width of each half period/peak value. It then displays a menu for the user to select which waveform to generate. Based on their selection, it will plot the corresponding waveform over time by creating and combining the appropriate segment vectors to represent each half period and piecewise define the shape. Axis labels and titles are also added to the plots.
This MATLAB code simulates three standard waveforms: square, triangular, and trapezoidal. It prompts the user to enter the number of waves and the width of each half period/peak value. It then displays a menu for the user to select which waveform to generate. Based on their selection, it will plot the corresponding waveform over time by creating and combining the appropriate segment vectors to represent each half period and piecewise define the shape. Axis labels and titles are also added to the plots.
n=input('enter the number of waves'); m=input('enter the width of each half period\peak value'); choice=menu('menu','square wave','triangular wave',..... 'trapezoidal wave'); if(choice==1) %option1 x=[]; t=m.*ones(1,12); for ii=0:m-1, x=[x,t,-t]; end plot(x); axis([0 250 -(m+1) m+1]); elseif(choice==2) TW=[]; T1=0:0.1:m; T2=m:-0.1:0; for ii =0:m-1, TW=[TW,T1,T2]; end plot(TW); grid(); xlabel('time'); ylabel('amplitude'); title('triangular wave'); %option2 display('option 2') else tp=[]; T1=0:0.1:m; t=m.*ones(1,12); T2=m:-0.1:0; T3=zeros(1,12); for ii=0:m-1, tp=[tp,T1,t,T2,T3]; end plot(tp); axis([0 700 -1 m+1]); %option3 display('option 3') end
Power of Habit: The Ultimate Guide to Forming Positive Daily Habits, Learn How to Effectively Break Your Bad Habits For Good and Start Creating Good Ones