# Mapping Saw Wave That Is Between -1 And 1 To A Sine Wave

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?

f=(-1:1/128:1)';

c1=repmat(f,1000,1);

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:

f=(-1:1/128:1)';

m=fft(f);

m(3:256)=0;
m(1)=0;

m2=ifft(m);

m3=m2/max(abs(m2));

m4=repmat(m3,1000,1);

sound(m4,44100);


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

f=(-1:1/128:1)';

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

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

plot([c1 c2]);
%sound(c2, 44100);

• 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. – skyisfalling Dec 21 '17 at 9:27
• I made some edit, to not erase the last sample, but scale the whole ramp by a bit – Maximilian Matthé Dec 21 '17 at 9:32
• 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 ? – skyisfalling Dec 21 '17 at 11:14
• 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). – Maximilian Matthé Dec 21 '17 at 11:36
• 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 ? – skyisfalling Dec 21 '17 at 11:51