(2 intermediate revisions by the same user not shown) | |||
Line 29: | Line 29: | ||
==Part 2== | ==Part 2== | ||
− | Consider the non-periodic function | + | Consider the non-periodic function <math>f(t)=e^{-0.2t}*sin(10t)</math>. |
+ | |||
+ | [[Image:Nonperiodic_blaskows_ECE301Fall2008mboutin.jpg|frame|center|Non-periodic function <math>f(t)=e^{-0.2t}sin(10t)</math>.]] | ||
+ | |||
+ | If we run the following MATLAB code, we can create a signal with an arbitrary period. Presented here is a signal with period 5. | ||
+ | |||
+ | <pre> | ||
+ | %Set up the environment | ||
+ | clear | ||
+ | clc | ||
+ | |||
+ | %Define parameters for shifiting the function | ||
+ | delta=0.0001; %step size | ||
+ | period=5; %period of function to produce | ||
+ | nperiod=5; %number of periods to reproduce | ||
+ | |||
+ | %define an x-vector for the inputs to the function | ||
+ | x=-2*period:delta:(nperiod+2)*period; | ||
+ | |||
+ | %intermediate results -- this gets shifted and added as necessary | ||
+ | f=exp(-0.2.*x).*sin(10.*x); | ||
+ | |||
+ | %preallocate the y-vector for speed (MATLAB's suggestion) | ||
+ | y=zeros(size(x)); | ||
+ | |||
+ | %for each period we are to reproduce, add the appropriate section of the | ||
+ | %f-vector (shifted horizontally) to the output vector. | ||
+ | for count=1:period/delta:(nperiod+8)*period/delta | ||
+ | y(1,count:size(y,2))=y(1,count:size(y,2))+f(1,1:size(y,2)-count+1); | ||
+ | end | ||
+ | |||
+ | %plot the results | ||
+ | plot(x,y) | ||
+ | grid | ||
+ | axis([0,nperiod*period,min(y),max(y)]); | ||
+ | </pre> | ||
+ | |||
+ | Running this code produces this figure. | ||
+ | |||
+ | [[Image:HW2a1f_blaskows_ECE301Fall2008mboutin.jpg|frame|center|Non-periodic function <math>f(t)=e^{-0.2t}sin(10t)</math> shifted and added several times to produce a periodic function.]] |
Latest revision as of 10:07, 10 September 2008
Part 1
Changing a Periodic Continuous Time Signal to a Non-Periodic Discrete Time Signal
One can take a signal that would be periodic in continuous time and turn it into a signal that is not periodic in discrete time. Consider the continuous time signal $ x(t)=sin(t) $. Plotting this signal yields a smooth waveform that repeats itself with period $ T=2\pi $.
Sampling this signal at every integer time yields something altogether different.
The new discrete time function looks like this on its own.
For the signal to be periodic, there must exist an integer N such that $ x[n]=x[n+N] $. For the signal defined as it is here, no such integer N exists.
Changing a Periodic Continuous Time Signal to a Periodic Discrete Time Signal
Suppose our sampling frequency, instead of being 1, was $ \frac{\pi}{8} $. Then the newly sampled function overlaid with the continuous function would look something like
Part 2
Consider the non-periodic function $ f(t)=e^{-0.2t}*sin(10t) $.
If we run the following MATLAB code, we can create a signal with an arbitrary period. Presented here is a signal with period 5.
%Set up the environment clear clc %Define parameters for shifiting the function delta=0.0001; %step size period=5; %period of function to produce nperiod=5; %number of periods to reproduce %define an x-vector for the inputs to the function x=-2*period:delta:(nperiod+2)*period; %intermediate results -- this gets shifted and added as necessary f=exp(-0.2.*x).*sin(10.*x); %preallocate the y-vector for speed (MATLAB's suggestion) y=zeros(size(x)); %for each period we are to reproduce, add the appropriate section of the %f-vector (shifted horizontally) to the output vector. for count=1:period/delta:(nperiod+8)*period/delta y(1,count:size(y,2))=y(1,count:size(y,2))+f(1,1:size(y,2)-count+1); end %plot the results plot(x,y) grid axis([0,nperiod*period,min(y),max(y)]);
Running this code produces this figure.