f



help #208

i need help with the code for this. I am ne to Matlab and dont really know how to use the program...

sampling a continuous time signal and plotting the results.
The generic cosine wave is a continuous time signal and is given as:

 s(t) = A*cos(2pi*f*t +y )

 where A is the amplitude, f is the frequency (Hz), and 
 is the phase shift. 
 simulate and plot the sampling of three cosine waves with
 amplitudes A = 1; A = 2; A = 4, 
 frequencies f = 2; f = 1; f = 0:1, 
 phase  = 0; = pi/2, = pi/4 respectively. Setting sampling rate to

0.01s, the duration of the sampling to 10s, and clip any sample above +3 and below -3. 

The plot should have time as the x-axis (0s-10s) and the sampled wave as the y axis (set bounds to -4 to +4) .
0
vyasa
12/17/2016 9:36:03 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader. Post Follow

1 Replies
533 Views

Similar Articles

[PageSpeed] 16

On 12/17/2016 3:36 PM, vyasa ownby wrote:
> i need help with the code for this. I am ne to Matlab and dont really know how to use the program...
>
> sampling a continuous time signal and plotting the results.
> The generic cosine wave is a continuous time signal and is given as:
>
>  s(t) = A*cos(2pi*f*t +y )
>
>  where A is the amplitude, f is the frequency (Hz), and
>  is the phase shift.
>  simulate and plot the sampling of three cosine waves with
>  amplitudes A = 1; A = 2; A = 4,
>  frequencies f = 2; f = 1; f = 0:1,
>  phase  = 0; = pi/2, = pi/4 respectively. Setting sampling rate to
>
> 0.01s, the duration of the sampling to 10s, and clip any sample above +3 and below -3.
>
> The plot should have time as the x-axis (0s-10s) and the
>sampled wave as the y axis (set bounds to -4 to +4) .
>


% HW assignment December 17, 2016
% Completed used Matlab 2016a. Did it all by myself

close all;
s=@(t,A,f,phase_shift) A*cos(2*pi*f*t +phase_shift);

ts  = 0.01;
T   = 10;
t   = 0:ts:T;
A   = [1,2,4];
f   = [2,1,0.1];
phase_shift = [0,pi/2,pi/4];

for i=1:3
     figure(i);
     y       =  s(t,A(i),f(i),phase_shift(i));  %sample

     y(y>3)  =  3;   %clip
     y(y<-3) = -3;

     plot(t,y,'-');
     title(sprintf('A=%d,f=%f,phase=%f',A(i),f(i),phase_shift(i)));
     ylim([-4,4]); xlim([0,10]);
     grid;
end

--Nasser
0
Nasser
12/18/2016 4:09:30 AM
Reply: