1. We often use MATLAB when dealing with mathematics and signals, because it allows us to intuitively observe the model of the signal we need. Therefore, it is necessary to master the basic MATLAB. Here we will explain how to use MATLAB to generate four commonly used waveforms ( square wave, sine wave, triangle wave, sawtooth wave ). The corresponding codes and corresponding waveform diagrams are listed below for your study and reference! ! !
1. Square wave
n=0:31;
y=31*square(2*pi*n/32,50)+32;
k=round(y);
stem(k);
2. Sine wave
n=0:63;
y=127*sin(2*pi*n/64)+128;
k=round(y);
stem(k);
3. Triangle wave
n=0:31;
y=63*sawtooth(2*pi*n/31,0.5)+64;
k=round(y);
stem(k);
4. Sawtooth wave
n=0:63;
y=127*sawtooth(2*pi*n/32)+128;
k=round(y);
stem(k);
My level is limited, and the above information is for reference only. If there are any mistakes or inadequacies, please give me your advice.
In addition, it is not easy to create, please do not plagiarize. If it is helpful to everyone, I hope everyone can like it, thank you~