I am trying to map values of a saw-wave that goes from -1 minimum value to 1 maximum value as a periodic signal onto a sine-wave. Repeating the matrix of this waveform that is 257 element in length oscillates as expected as a saw-wave, but if I change the function into a sine-wave -1 maps to 0, then 1 also maps to 0, and when two zeros are together when we loop the waveform with "repmat" matlab function, there appears discontinuities in the sine-wave function...How can I map this saw-wave, so the sine-wave perfectly oscillates with all the values used from the saw-wave that is between -1 and 1 values?



c2=sin(pi*c1);   % -1 of saw wave maps to 0, 1 maps also to 0 

sound(c2,44100); % two adjacent 0's cause discontinuities

I also tried the fft method which gives me the needed coefficients but if my waveform is complex this would become more complicated to adapt:








1 Answer 1


You can scale your sawtooth before you put it into the sine function, like so:


ramp = f * (length(f)-1)/length(f);  % Scale down to not include the last 1 into the sine

c2=sin(pi*c1);   % -1 of saw wave maps to 0, 1 maps also to 0 

plot([c1 c2]);
%sound(c2, 44100);
  • $\begingroup$ I need this in my static non-linearity waveshaper function, and if I exclude the last value I can't represent the signal correctly, I need a sinewave waveform that can be used as function to transform all values of this saw wave between -1 to 1 values, due to linear interpolation I have to adapt in my waveshaper, and it is not possible to linear interpolate with 256 values because of matlabs integer indexing system. $\endgroup$ Dec 21, 2017 at 9:27
  • $\begingroup$ I made some edit, to not erase the last sample, but scale the whole ramp by a bit $\endgroup$ Dec 21, 2017 at 9:32
  • $\begingroup$ Scaling makes sense, but my question is why mapping a periodic signal such as saw wave would break down when a sinewave function is used, we have a perfect oscillation that is -1 to 1, which is also a linear function but once this saw wave is mapped to sinewave discontinuities happen ? Is this something similar to fft symmetry where nyquist bin drops out when odd number of points are used, since fft is periodic too ? $\endgroup$ Dec 21, 2017 at 11:14
  • $\begingroup$ discontinuities do not mean it is not periodic. if $f(t)$ is periodic with period T (your ramp), then certainly $sin(f(t))$ is also periodic. But periodic does not mean, it's smooth. It is not smooth, because, as you saw, -1 and 1 are both mapped to 0. You may understand this, that the 1 of the ramp is actually already part of the new period (when considering the argument to be a full period of the sine wave). $\endgroup$ Dec 21, 2017 at 11:36
  • $\begingroup$ Is this why an 8 bit signal has a range between 0-255 values, and falls short to represent the maximum value which is 1 ? Or in this 8 bit scenario we just exclude one bit because there aren't enough bits ? $\endgroup$ Dec 21, 2017 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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