You are on page 1of 5

DSP Programming Using MATLAB

2013

%==============Program for the generation of basic Signals============= %============== Program 1.1 ===================================== % Generation of unit impulse n=-10:1:10; delta = [zeros(1,10),ones(1,1),zeros(1,10)]; subplot(2,2,1); stem(n,delta); grid on; xlabel ('Time');ylabel ('Amplitude'); title('Unit Impulse'); %============== Program 1.2 ===================================== % Generation of unit step signal n=-10:1:10; u_step = [zeros(1,5),ones(1,6)]; subplot(2,2,2); stem(n,u_step); grid on; xlabel ('Time'); ylabel ('amplitude'); title('Unit step');

Lab Task #1.1:

1.

Modify the program 1.1 to generate a delayed unit impulse sequence d_delta[n] with a delay of 5 samples. Run the modified program and display the sequence generated.

2.

Modify the program 1.1 to generate a delayed and scaled unit impulse sequence d_delta[n] with a delay of 5 samples and scaled by a factor of 3. Run the modified program and display the sequence generated.

3.

Modify the program 1.1 to generate an advanced unit impulse sequence a_delta[n] with an advance of 7 samples. Run the modified program and display the sequence generated.

4. Modify the program 1.2 to generate a unit step sequence Sd[n] with an advance of 3 samples. Run the modified program and display the sequence generated. 5. Modify the program 1.2 to generate an advanced and scaled unit impulse sequence a_step[n] with an advance of 3 samples and scaled by a factor of 2. Run the modified program and display the sequence generated.

AkU, CET, Dept of Electrical & Computer Engineering

Page 1

DSP Programming Using MATLAB

2013

%============== Program 1.3 ===================================== % Generation of unit ramp sequence n1=0:20; subplot(2,2,3); stem(n1,n1); grid on; xlabel('Time');ylabel('Amplitude'); title('Unit Ramp Signal'); %============== Program 1.4 ===================================== % Generation of sine wave [n] = A*sin(2*pi*n2*f + theta) n2=0:0.1:5; % sequence length A=2; f=0.25; theta=0; %Amplitude % normalized frequency % phase angle in radians

x = A*sin(2*pi*n3*f + theta); subplot(2,2,4); stem(n3,si); xlabel('Time'); ylabel('Amplitude'); title ('sine wave');

Lab Task # 1.2: 1. Write a MATLAB code that generates Ramp function scaled by a factor of 2.Run the modified program and display the sequence generated. Run the modified program and display the sequence generated. 2. Modify the program 1.3 to generate a ramp function with sequence of length 20(from -10:1:10) and amplitude 5 and display it. Compare it with sequence of Program 1.3. 3. Modify the program 1.4 to generate a sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5 and phase shift 90 degrees and display it. Compare it with sequence of Program 1.4.
%============== Program 1.5 ===================================== % Generation of Cosine wave n4=0:0.01:1; a2=2; co =a2*cos(2*pi*2*n4); figure(2); subplot(2,2,1); stem(n4,co); xlabel('Time');ylabel('Amplitude'); title ('Cosine wave');

AkU, CET, Dept of Electrical & Computer Engineering

Page 2

DSP Programming Using MATLAB

2013

%============== Program 1.6 ===================================== % Generation of Square wave n5=0:0.01:1; a3=2; sq =a3*square(2*pi*2*n5); subplot(2,2,2); stem(n5,sq); xlabel('Time');ylabel('Amplitude'); title ('Square wave'); %============== Program 1.7 ===================================== % Generation of Exponential waveform n6=0:0.01:1; a4=2; ew=a4*exp(2*pi*2*n6); subplot(2,2,3); stem(n6,ew); xlabel('Time');ylabel('Amplitude'); title ('Exponential wave'); %============== Program 1.8 ===================================== % Generation of saw-tooth n7=0:0.01:1; a5=2; sa=a5*sawtooth(2*pi*2*n7); subplot(2,2,4); stem(n7,sa); xlabel('Time');ylabel('Amplitude'); title ('Exponential wave'); %============== Program 1.9 ===================================== % Generation of Real Exponential n=-5:0.01:5; r=2; a=-2; re=r*a.^n; figure(3) subplot(3,3,1); stem(n,re); xlabel('Time');ylabel('Amplitude'); title('value of a<-1'); a1=-0.5; re1=r*a1.^n; subplot(3,3,2) stem(n,re1); xlabel('Time');ylabel('Amplitude'); title('value of -1<a<0'); %value of -1<a<0 %value of a<-1

AkU, CET, Dept of Electrical & Computer Engineering

Page 3

DSP Programming Using MATLAB

2013

a2=0.5; re2=r*a2.^n;

%value of 0<a<1

subplot(3,3,3); stem(n,re2); xlabel('Time');ylabel('Amplitude'); title('value of 0<a<1'); a3=2; re3=r*a3.^n; subplot(3,3,4); stem(n,re3); xlabel('Time'); ylabel('Amplitude'); title('value of a>1'); %============== Program 1.10 ===================================== % Generation of complex Exponential n=-5:0.1:5; r=2; a=2; c=1+1i; ce=r*a.^(n*c); % ce= real part + imaginary part figure(2); % new figure window subplot(3,3,5); stem(n,real(ce)); xlabel('Time');ylabel('Amplitude'); title('real part'); subplot(3,3,6); stem(n,imag(ce)); xlabel('Time');ylabel('Amplitude'); title('Imaginary part of ce'); %============== Program 1.11 ===================================== % PROGRAM for sampling of continuous time signal using MATLAB % sampling theorem states that fs (sampling frequency) >= 2Fmax (maximum frequency) clc; clear all;close all; t=-10:.01:10; T=8; fmax=1/T; subplot(2,2,1); plot(t,x);% plot of the continuous time signal x(t) xlabel('time in sec'); ylabel('x(t)'); title('continuous time signal xa(t)'); %====Continued in the Next Page============ % t vector %time Period % maximum frequency %value of a>1

x=cos(2*pi*fmax*t); % x(t) is analog cosine wave

AkU, CET, Dept of Electrical & Computer Engineering

Page 4

DSP Programming Using MATLAB

2013

%====contd======= % sampling of continuous time signal fs1=1.6*fmax; %fs<2fmax fs2=2*fmax; %fs=2fmax fs3=8*fmax; %fs>2fmax n1=-4:1:4; %index vector xn1=cos(2*pi*n1*fmax/fs1);% aliasing subplot(2,2,2); stem(n1,xn1); %aliasing discrete hold on; plot(n1,xn1); % aliasing continuous xlabel('n'); ylabel('x(n)'); title('discrete time signal with fs<2fmax'); n2=-5:1:5; %time index xn2=cos(2*pi*n2*fmax/fs2); %fs=2fmax subplot(2,2,3); stem(n2,xn2); %sampling for fs=2fmax hold on; plot(n2,xn2); %ploting fs=2fmax xlabel('n'); ylabel('x(n)'); title('discrete time signal with fs=2fmax'); n3=-20:1:20; %time index xn3=cos(2*pi*n3*fmax/fs3); %fs>2fmax subplot(2,2,4); stem(n3,xn3); %samples for fs>2fmax hold on; plot(n3,xn3); %ploting fs>2fmax xlabel('n'); ylabel('x(n)'); title('discrete time signal with fs>2fmax');

AkU, CET, Dept of Electrical & Computer Engineering

Page 5

You might also like