-1
$\begingroup$

I've been asked to recreate the square and sawtooth wave shown below: enter image description here

And I've managed to recreate the square wave form but I can't seem to get my sawtooth wave to match.

% Input Variables
L = 31; % Input Length
A = 1; % Peak Value
N = 10; %Input Period

% Define omega and time vector t
omega = 2*pi/N;
t = 0:omega:(L-1)*omega;

% X-axis lenghth determined by L-1
X = 0:L-1; 

Vsaw = A*sawtooth(t);
Vsquare = A*square(t,60);

hold on;
subplot(2,1,1)
stem(X,Vsaw)
xlabel('Time');
ylabel('Amplitude');

subplot(2,1,2), stem(X,Vsquare);
xlabel('Time');
ylabel('Amplitude');

enter image description here

Is it an error in the code or my values as I can't get the correct number of values or correct amplitude on the saw tooth.

$\endgroup$
0
$\begingroup$

You need to think of it as if you were sampling a sawtooth wave. The positive peak of your sawtooth wave actually occurs between your 11th and 12th sample but your sampling rate is just too low to catch it. You need to increase your input period and length to get your positive peak to hit +1.

$\endgroup$
0
$\begingroup$

In your book, the period of the sawtooth is 11 samples, not 10.

$\endgroup$
0
$\begingroup$

A simple way to obtain the first figure of the book is use this code:

Vsaw = A*[(-1:.2:1) (-1:.2:1) (-1:.2:.6)];
$\endgroup$
-1
$\begingroup$

You can use the following:

 Vsaw=linspace(-A,A,11);
 Vsaw=[Vsaw Vsaw Vsaw];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.