N N N N U: Generation of Discrete Time Signals and Spectrum

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 22

Exp :1 Date:

Generation of Discrete time signals and Spectrum


x (n)

A discrete-time signal

represents a phenomenon for which the independent

variable is inherently discrete. Signals such as demographic data are examples for this. The discrete-time signals arise from the sampling of continuous-time signals. The following discrete time signals are referred to as standard discrete time signals.
1.

Unit step signal: The discrete-time unit step, denoted by u[n] is defined by

2.

Unit ramp signal: The unit ramp signal is denoted as ur[n] and is defined as

0, n < 0 u[ n] = 1, n 0

3.

Unit sample signal: The unit sample sequence is denoted as ( n ) and defined as

n, n 0 u r [ n] = 0, n < 0
1, n = 0 ( n) = 0, n 0

4. 5.

Exponential function: The exponential signal is a sequence of the form x( n ) = a n for all n Sinc pulse: Sinc pulse is defined as sin n sinc ( n ) =
n

6.

Rectangular signal: The rectangular signal of size N is defined as u ( n ) u ( n N ) 7. Complex exponential(sinusoid and cosinusoid): A discrete sinusoid signal is defined as,
x ( n) = A sin( 2 f n) fs

where, A is the amplitude of the sinusoid, f is the analog frequency in Hz f s is the sampling frequency in samples/sec, n is then sample index and
f fs

is defined as Discrete Frequency in cycles/sample.


x ( n) = A cos( 2 f n) fs

A discrete co-sinusoid signal is defined as, is the amplitude of the sinusoid,


f

where, A
fs

is the analog frequency in Hz


f fs

is the

sampling frequency in samples/sec, n is then sample index and defined as Discrete Frequency in cycles/sample. Spectrum of standard discrete time signals

is

The spectrum of standard discrete time signals are calculated through Discrete Fourier Transform(DFT) and a N point DFT of a sequence x (n ) is defined as,
X ( k ) = x ( n)e
n =0 N 1 j 2kn N

0 k N1

1.1 OBJECTIVE To view the graphical representation of the following standard discrete time signals and its Spectrum. Unit step Unit Ramp Unit Sample Exponential Sinc Rectangular

Exercise Problems:

1a) Simulate Unit Sample, Unit Step & Unit Ramp Signals for the sample index ranges 10n 10. Plot the spectrum for the above signals. clc; clear all; close all; n=-10:10; a=[zeros(1,10),1,zeros(1,10)]; subplot(2,1,1); stem(n,a,'r+-'); xlabel('samples'); ylabel('amplitude'); title('impulse signal'); subplot(2,1,2); y=abs(fft(a)); plot(y,'r+-'); xlabel('frequency index'); ylabel('madnitude'); title('impulse signal spectrum'); figure; s=[zeros(1,10),ones(1,11)]; subplot(2,1,1); stem(n,s,'r+-'); xlabel('samples'); ylabel('amplitude'); title('step signal'); subplot(2,1,2); y=abs(fft(s)); plot(y,'r+-'); xlabel('frequency index'); ylabel('madnitude'); title(' step signal spectrum'); figure; a=1:1:10; r=[zeros(1,11),a]; subplot(2,1,1); stem(n,r,'r+-'); xlabel('samples'); ylabel('amplitude'); title('ramp signal');

subplot(2,1,2); y=abs(fft(r)); plot(y,'r+-'); xlabel('frequency index'); ylabel('madnitude'); title('ramp signal spectrum');

impulse signal 1

amplitude

0.5

0 -10

-8

-6

-4

0 2 samples impulse signal spectrum

-2

10

madnitude

1 0

10 15 frequency index step signal

20

25

amplitude

0.5

0 -10

-8

-6

-4

0 2 samples step signal spectrum

-2

10

15

madnitude

10

10 15 frequency index

20

25

ramp signal 10

amplitude

0 -10

-8

-6

-4

0 2 samples ramp signal spectrum

-2

10

60

madnitude

40

20

10 15 frequency index

20

25

b)Simulate the signal x(n)=2 (n+2)-4(n-4) clc; clear all; close all; x=[zeros(1,8),2,zeros(1,5),-1,zeros(1,6)]; n=-10:1:10; stem(n,x,'r+-'); xlabel('samples'); ylabel('amplitude'); y=fft(x); figure,plot(abs(y),'r+-'); xlabel('frequency index'); ylabel('magnitude'); title('shifted impulse'); legend('shifted impulse');

1.5

1 amplitude

0.5

-0.5

-1 -10

-8

-6

-4

-2

0 samples

10

shifted impulse 3 shifted impulse 2.8 2.6 2.4 2.2 magnitude 2 1.8 1.6 1.4 1.2 1 0 5 10 15 frequency index 20 25

(c)Simulate the signal x(n)=u(n)-u(n-10). Observe its spectrum clc; clear all; close all; n=-10:10; figure; a=[zeros(1,10),ones(1,11)]; stem(n,a,'r+-'); figure; b=[zeros(1,20) 1]; stem(n,b,'r+-'); figure; r=(a-b); stem(n,r,'r+-'); xlabel('samples'); ylabel('amplitude'); title('shifted step signal');
1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -10

-8

-6

-4

-2

10

1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 -10

-8

-6

-4

-2

10

shifted step signal 1 0.9 0.8 0.7 0.6 amplitude 0.5 0.4 0.3 0.2 0.1 0 -10

-8

-6

-4

-2

0 samples

10

d) Simulate the sequence x (n) =a n where n10; case i)a>1; case ii)0<a<1 case iii) -1<a<0 case iv) a<-1 clc; clear all; close all; n=-10:1:10; a=2; figure; x=[a.^n]; subplot(2,1,1); stem(n,x); xlabel('samples'); ylabel('amplitude'); title('a>1'); legend('time domain'); y=fft(x); subplot(2,1,2); stem(n,abs(y)); xlabel('frequency index'); ylabel('magnitude'); title('a>1 spectrum'); legend('freq domain'); a=0.5; figure; x=[a.^n]; subplot(2,1,1); stem(n,x); xlabel('samples'); ylabel('amplitude'); title('0<a<1'); legend('time domain'); y=fft(x); y=fft(x); subplot(2,1,2); stem(n,abs(y)); xlabel('frequency index'); ylabel('magnitude'); title('0<a<1'); legend('freq domain');

a=-0.5; figure; x=[a.^n]; subplot(2,1,1); stem(n,x); xlabel('samples'); ylabel('amplitude'); title('-1<a<0'); legend('time domain'); y=fft(x); subplot(2,1,2); stem(n,abs(y)); xlabel('freq index'); ylabel('magnitude'); title('-1<a<0'); legend('freq domain'); a=-2; figure; x=[a.^n]; subplot(2,1,1); stem(n,x); xlabel('samples'); ylabel('amplitude'); title('a<=-1'); legend('time domain'); y=fft(x); subplot(2,1,2); stem(n,abs(y)); xlabel('freq index'); ylabel('magnitude'); title('a<=-1');

legend('freq domain');
a>1 1500 time domain amplitude 1000

500

0 -10

-8

-6

-4

-2

0 2 samples a>1 spectrum

10

3000 freq domain magnitude 2000

1000

0 -10

-8

-6

-4

-2 0 2 frequency index 0<a<1

10

1500 time domain amplitude 1000

500

0 -10

-8

-6

-4

-2

0 samples 0<a<1

10

3000 freq domain magnitude 2000

1000

0 -10

-8

-6

-4

-2 0 2 frequency index

10

-1<a<0 2000 time domain amplitude 1000

-1000 -10

-8

-6

-4

-2

0 samples -1<a<0

10

3000 freq domain magnitude 2000

1000

0 -10

-8

-6

-4

-2

0 freq index a<=-1

10

2000 time domain amplitude 1000

-1000 -10

-8

-6

-4

-2

0 samples a<=-1

10

3000 freq domain magnitude 2000

1000

0 -10

-8

-6

-4

-2

0 freq index

10

e) Observe the magnitude ,phase,real part and imaginary part of the complex exponential sequence y (n)=(exp(2+6j)*n) ; n10 clc; clear all; close all; n=0:10; y=(exp(2+6j)*n); mag=abs(y); phase=angle(y); rp=real(y); ip=imag(y); stem(n,mag,'r+-'); xlabel('samples'); ylabel('amplitude'); title('magnitude'); legend('magnitude'); figure; stem(n,phase,'r+-'); xlabel('samples'); ylabel('phase in radians'); title('phase'); legend('phase'); figure; stem(n,rp,'r+-'); xlabel('samples'); ylabel('amplitude'); title('real part'); legend('real part'); figure; stem(n,ip,'r+-'); xlabel('samples'); ylabel('amplitude'); title('imag part');

legend('imag part');
magnitude 80 magnitude 70 60 50 amplitude 40 30 20 10 0

5 samples phase

10

0 phase -0.05

-0.1 phase in radians

-0.15

-0.2

-0.25

-0.3

-0.35

5 samples

10

real part 80 real part 70 60 50 amplitude 40 30 20 10 0

5 samples imag part

10

0 imag part

-5

-10 amplitude

-15

-20

-25

5 samples

10

2 Simulate a co-sinusoid comprising of 10 samples at a discrete frequency of 0.1 .Observe the number of cycles.Change the number of samples to 30 and observe the number of cycles and comment on the result. clc; clear all; close all; n1=0:9; f=0.1; a=cos(2*pi*f*n1); stem(n1,a,'r+-'); xlabel('samples'); ylabel('amplitude'); title('cosine signal'); legend('cosine signal'); figure; n2=0:29; b=cos(2*pi*f*n2); stem(n2,b,'r+-'); xlabel('samples'); ylabel('amplitude'); title('cosine signal'); legend('cosine signal');

cosine signal 1 cosine signal 0.8 0.6 0.4 0.2 amplitude 0 -0.2 -0.4 -0.6 -0.8 -1

4 5 samples cosine signal

1 cosine signal 0.8 0.6 0.4 0.2 amplitude 0 -0.2 -0.4 -0.6 -0.8 -1

10

15 samples

20

25

30

sinusoidal:
clc; clear all; close all; n1=0:9; f=0.1; a=sin(2*pi*f*n1); stem(n1,a,'r+-'); xlabel('samples'); ylabel('amplitude'); title('sine signal'); legend('sine signal'); figure; n2=0:29; b=sin(2*pi*f*n2); stem(n2,b,'r+-'); xlabel('samples'); ylabel('amplitude'); title('sine signal'); legend('sine signal');

sine signal 1 sine signal 0.8 0.6 0.4 0.2 amplitude 0 -0.2 -0.4 -0.6 -0.8 -1

4 5 samples

3)Generate a Sinc Pulse from -8n 8 using 100 equally spaced points.Plot its spectrum. clc; clear all; close all; n=-50:-1; n1=1:1:50; fd=0.1; x=sin(pi*fd*n)./(pi*fd*n); y=sin(pi*fd*n1)./(pi*fd*n1); z=[x 1 y]; q=[n 0 n1]; subplot(2,1,1); stem(q,z); xlabel('samples'); ylabel('amplitude'); title('sinc pulse'); legend('time domain'); w=fft(z); s=fftshift(w); subplot(2,1,2); stem(q,abs(s)); xlabel('frequency index'); ylabel('magnitude'); title('freq spec');

legend('frequency domain');
sinc pulse 1 time domain amplitude 0.5

-0.5 -50

-40

-30

-20

-10

0 10 samples freq spec

20

30

40

50

15 frequency domain magnitude 10

0 -50

-40

-30

-20

-10 0 10 frequency index

20

30

40

50

OBSERVATIONS: Changes in the output signal by varying the type of input signal, number of samples, amplitude and delay is observed.

Different types of signal as a linear combination of standard input signals is generated.

You might also like