Sum of sine functions in Matlab -
i have create function following definition:
function [ s1,s2,sums ] = sines( pts,amp,f1,f2 )
the output argument s1 row vector length (number of elements) equals pts. elements of s1 values of sine function when given equally spaced arguments start @ 0 , extend through f1 periods of sine. amplitude of sine wave equals amp. vector s2 same s1 except s2 contains f2 periods. vector sums sum of s1 , s2. if f2 omitted, should set value 5% greater f1. if f1 omitted also, should set 100. if amp not provided, should default 1. finally, if pts omitted well, should set 1000. have done following:
function [ s1,s2,sums ] = sines( pts,amp,f1,f2 ) if nargin == 3 f2 = f1 + (f1*0.05); elseif nargin == 2 f1 = 100; f2 = f1 + (f1*0.05); elseif nargin == 1 amp = 1; f1 = 100; f2 = f1 + (f1*0.05); elseif nargin == 0 pts = 1000; amp = 1; f1 = 100; f2 = f1 + (f1*0.05); end t = 0:pts-1; s1 = amp * sin( 2*pi*f1.*t ); s2 = amp * sin( 2*pi*f2.*t ); sums = s1 + s2; end
the result should frequency modulated sine function, when plot sums
not sine function, looks more sawtooth function, sharp. doing wrong?
you have forgotten normalize time-steps t
between 0-1. f1
, f2
periods s1
, s2
respectively should have
t = (0:pts-1)/(pts-1);
Comments
Post a Comment