31
LAB 1 Signal Generation AIM: Generate analog and digital signals. RESPECTIVE MATLAB FUNCTIONS:- Graphics Function Linespace(0,2*pi,100) %create a linearly space 100 elements between 0 to 2*pi fplot %plot a function of a single variable hist %makes histograms bar %crate a bar graph pie %create a pi chart polar %plot curves in polar co-ordinates semilogx %make semi log plot with log scale on x axis semilogy %make semi log plot with log scale on y axis loglog %create plot with log scale on the both axis stem %plot a stem(discrete) graph area plot %plot the graph plot with style opti color style %select the color line style marker style subplot (m,n,p) %breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot xlabel %label on the x-axis ylabel %label on the y-axis title %title of the graph text %write notes at a specified location legend %produce a boxed legend on a plot hold on %hold the graph on figure window hold off axis %set the limits of the axis equal %sets equal scale on the both axis

DSP Lab 1-5.docx

Embed Size (px)

Citation preview

LAB 1Signal Generation

AIM: Generate analog and digital signals.

RESPECTIVE MATLAB FUNCTIONS:- Graphics Function

Linespace(0,2*pi,100) %create a linearly space 100 elements between 0 to 2*pi fplot %plot a function of a single variable hist %makes histograms bar%crate a bar graph pie%create a pi chart polar%plot curves in polar co-ordinates semilogx%make semi log plot with log scale on x axis semilogy%make semi log plot with log scale on y axis loglog%create plot with log scale on the both axis stem%plot a stem(discrete) graph area plot%plot the graph plot with style opti color style%select the color line style marker style subplot (m,n,p)%breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for thecurrent plot xlabel%label on the x-axis ylabel%label on the y-axis title%title of the graph text%write notes at a specified location legend%produce a boxed legend on a plot hold on%hold the graph on figure window hold off axis%set the limits of the axis equal%sets equal scale on the both axis

square%sets the default rectangular frame to a square normal%reset the axis to default values

Functions for signal generations: Sin, cos, zeros, stem, ones, square, expMatlab codes for generating different signals and their figures:1. Generating a Sine wave.f=50; t=0:0.0001:0.1;y=sin(2*pi*f*t);plot(t,y)

2. Generating a Cosine wave.f=50; t=0:0.0001:0.1;y=cos(2*pi*f*t);plot(t,y)

3. Generating a Square wave.f=50; t=0:0.0001:0.0625;y=square(2*pi*f*t);plot(t,y)

4. Generating a Ramp wave.t=0:1:10;x=t;plot(t,x)

5. Generating a Impulse wave.t=-10:1:10;z=[zeros(1,10) 5 zeros(1,10)];stem(t,z)

6. Generating a Unit Step wave.t=-10:1:10;z=[zeros(1,10) 1 ones(1,10)];stem(t,z)

7. Generating a Exponential wave.n=0:0.1:5;y=exp(n)plot(y)xlabel('Time')ylabel('Amplitude')title('Exponential Wave')

8. Generating a Sinc wave.

t=-4*pi:0.001:4*pi;y=sinc(t)plot(t,y)

Lab 2Signal Operation

AIM: Generate analog and digital signals

1) Signal Shifting

clc;clear all;close all;e=input('enter the range for ramp function\n');z=0:e;x=[z];n=input('entr shifting index\n');y=length(x);subplot(1,2,1);stem(x);xlabel('original signal')if nn2 y=[y zeros(1,n1-n2)]; else x=[x zeros(1,n2-n1)]; end z=x+y; subplot(2,2,3);stem(z);xlabel('addition of x and y');

for unequal length of signal:

Output screen:

For equal length of signal:

Output screen:

3) Signal Foldingclc;close all;clear all;x=input('Enter siganl samples')p=input('Enter starting point')a=length(x)t=p:1:(p+a-1)subplot(2,1,1)stem(t,x)l=t.*-1;subplot(2,1,2)stem(l,x)

Output screen:

4) Signal Multiplicationclc;close all;clear all;x1=input('Enter siganl 1 samples\n');p=input('Enter starting point signal 1 \n');n1=p:(p+length(x1)-1); x2=input('Enter siganl 2 samples\n');q=input('Enter starting point signal 2 \n');n2=q:(q+length(x2)-1); n=min(min(n1),min(n2)):max(max(n1),max(n2));y1=zeros(1,length(n));y2=y1;y1(find((n>=min(n1))& (n=min(n2))&(n z(-n) = h(n) ** x(n)2) Auto correlation is having even symmetry. Rxx(n) = Rxx(-n)Correlation using inbuilt function:

A=[1 2 3 4];B=[1 2 3 4];s2=xcorr(A,B);stem(s2);xlabel('value of k')ylabel('value of s2(k)')title('correlation')

CONCLUSION:

By performing this practical we can conclude that we know the response of any kind of signal by convoluting it with impulse function. Convolution is specially used for Filter Designing. By performing correlation operation, we can find the relation between two signal means whats the delay or phase difference. This application is used in RADAR communication. In this when the two signal overlap on each other, we get maximum output and by that way we get the exact location.

ASSIGNMENTS:

1. Perform correlation operation without using functions.Ans. Correlation is convolution of first and folded second sequence.

u= [1 2 3 4];z= [1 2 3 4];a=0:3;[v,b]=sigfold (z,a); %use function to fold signal (like in lab 2)m=length (u);n=length (v);

for k:m+n-1;w(k)=0;for j=max (1,k+1-n): min (k,m);w(k)=w(k)+ (u(j)*v(k+1-j));endendstem(w);xlabel (value of k);ylabel (value of w(k));title (correlation);

LAB- 4APPLICATION OF CORRELATION USE IN RADAR AIM:To understand concept of correlation and to understand its use in RADAR application. THEORY:RADAR is acronym of Radio Detection And Ranging.As its full name says RADAR is used to detect if any object is there or not in the path of transmission of wave and to know how far it is.Above task can be done in this way:1)We transmit radio wave.After some delay time we can receive the reflected wave.2)We also know the propagation velocity of transmitted wave.3)So,according to v=d/t, we can calculate the distance of object from transmission place. CODE:

clc;clear all;close all;D=15; % Delay amountx=[0 1 2 3 2 1 0]; %Triangle pulse transmitted by radarn=[-3 -2 -1 0 1 2 3];% n=[0 1 2 3 4 5 6];[nd xd]=sigshift(x,n,D); % x(n-D)figure;subplot(2,1,1);stem(n,x);title('Original Signal');subplot(2,1,2);stem(nd,xd);title('Delayed Signal');

w=rand(1,length(x)); % Random noise w(n)nw=nd;figure;stem(nw,w);title('Noisy Signal');

% If object is present we receive the signal y(n)[ny y]=sigadd(xd,nd,w,nw); % Received signa at radar y(n) = x(n-D) + w(n)figure;stem(ny,y);title('Received Noisy Signal');

[nrxy rxy]=corr1(x,n,y,ny); % Cross correlaiton between x(n) and y(n)figure;subplot(2,1,1);stem(nrxy,rxy);title('Correlation in the Presenance of Object'); % If object is absent we recive only noise signal w(n)subplot(2,1,2);[nrxw rxw]=corr1(x,n,w,nw); % Cross correlation between x(n) and w(n)stem(nrxw,rxw);title('Correlation in the absenance of Object');For executing above program function files shown below should be made:1) function [n,y]=conv1(x1,n1,x2,n2)nmin=min(n1)+min(n2);% Lowest index of y(n)nmax=max(n1)+max(n2);% Highest index of y(n)n=nmin:nmax;y=conv(x1,x2);2) function [n,y]= corr1(x1,n1,x2,n2)[n3,x3]=timereversal(x2,n2); %Folding of x2(n)[n,y]=conv1(x1,n1,x3,n3); %convolution3) function [n,y]= sigadd(x1,n1,x2,n2)m1=min(n1);m2=min(n2);st=min(m1,m2);l1=max(n1);l2=max(n2);en=max(l1,l2);n=st:en;y1=zeros(1,length(n));y2=y1;y1(find((n>=m1)&(n=m2)&(n