Professional Documents
Culture Documents
DSP File Aim:: Generation of Elementary Signals
DSP File Aim:: Generation of Elementary Signals
scf;
//unit-step signal
close;
L=8;
n=-L:L;
x=[zeros(1,L),ones(1,L+1)]
subplot(2,3,2)
plot2d3(n,x)
scf;
//ramp-signal
close;
L=8;
n=-L:L;
x=[zeros(1,L),0:L];
a=gca();
a.y_location="middle"
subplot(2,3,3)
plot2d3(n,x)
scf;
//exponential-signal
close;
L=8;
n=0:L;
a=0.7;
x=a^n;
subplot(2,3,4)
plot2d3(n,x)
scf;
//sine-cosine-signal
close;
L=8;
n=0:L;
x=sin(n);
subplot(2,3,5)
plot2d3(n,x)
AIM: Time-shifting and time-reversal
CODE:
// Time-shifting of a discrete time sequence
clear;close;clc;
x=input('Enter the sequence');
nx=input('Enter the time domain information of sequence');
k=input('enter the shift value');
nx1=nx+k;
subplot(2,1,1);
plot2d3(nx,x)
subplot(2,1,2);
plot2d3(nx1,x)
//x(n)
p=0:1:m-1;
subplot(3,2,1),
a = gca();
a.x_location = "origin";
a.y_location = "origin";
plot2d3('gnn',p,x) //plot for x(n)
title('i/p sequencce x(n) is:');
xlabel('-->n');
x=[x,zeros(1,n)];
//h(n)
q=0:1:n-1;
subplot(3,2,2),
a = gca();
a.x_location = "origin";
a.y_location = "origin";
plot2d3('gnn',q,h) //plot for h(n)
title('i/p sequencce h(n) is:');
xlabel('-->n');
h=[h,zeros(1,m)];
//convoluted signal
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
r=0:1:m+n-2;
subplot(3,1,3)
a = gca ();
a.x_location = "origin";
a.y_location = "origin";
plot2d3('gnn',r,y) //plot of convoluted signal
title('convolution of x(n) & h(n) is :');
xlabel('-->n');
disp ( "The convoluted sequence") ;
disp ( y );
//Resulting seq will have length = sum of length of both the sequences - 1
clc ;
clear ;
close ;
x = input('Enter the Input Sequence =') // x=[1 2 3 1 ]
m = length(x);
xl = input('Enter the lower index of Input Sequence= ' )// 0
xh = xl +m -1;
n = xl:1:xh;
subplot(2,2,1);
a=gca();
a.x_location ='origin';
a.y_location ='origin';
plot2d3('gnn',n,x) ;
title('Input Sequence x[n]');
xlabel('Samples n');
ylabel('Amplitude');
z = xcorr (x , h ) ;
disp('Correlation of Sequence y(n)= ');
disp(z);
nx = xl + xl ;
nh = xh + xh ;
r = nx : nh ;
subplot(2,2,4);
a=gca();
a.x_location = 'origin';
a.y_location = "origin";
plot2d3 ('gnn',r,z) ;
title ('Output of Correlation of Sequence');
xlabel('Samples n');
ylabel('Amplitude');
//
applicati
on of
correlati
on-RADAR
clc ;
clear ;
close ;
scf () ;
subplot (2 ,1 ,1) ;
plot2d3(n,x,0.1);
title ( 'Original Transmitted Signal','color','red','fontsize',4) ;
xlabel ("Index","fontsize",2,"color","blue") ;
ylabel ("Amplitude","fontsize",2,"color","blue") ;
subplot (2 ,1 ,2) ;
plot2d3(nd,y,0.1);
title ( 'DelayedSignal','color','red','fontsize',4) ;
xlabel ("Index","fontsize",2,"color","blue") ;
ylabel ("Amplitude","fontsize",2,"color","blue") ;
subplot (2 ,1 ,2) ;
plot2d3(n_received , Received_Absence ,0.1);
title ( 'Correlation in the Absence of
Object','color','red','fontsize',4) ;
xlabel ("Index","fontsize",2,"color","blue") ;
ylabel ("Correlation Value","fontsize",2,"color","blue");
AIM: FFT
//FFT of a Sequence
clc;
clear all;
close;
x = input("Enter the sequence = ")
X = fft(x)
disp("The FFT is = ", X)
plot(X)
//formakinglengthofbothsignalsequal
N = max(m,l) ;
p=m-l;
if(p>=0) then
h =[h, zeros(1 , p)];
else
x =[x, zeros(1 , -p)];
end
for i=1:N
y(i)=0;
for j=1:N
k=i-j+1;
if(k<=0)
k= k+N ;
end
y(i)=y(i)+(x(j)*h(k)) ;
end
end
disp("Circularconvolutionbyequationisy[n]:");
disp(y);
nx=xl+hl;
r=nx:length(y)-1;
subplot(3,1,3);
a=gca();
a.x_location="origin";
a.y_location="origin";
a.foreground=5;
a.font_color=5;
a.font_style=5;
plot2d3("gnn",r,y);
title("OutputResponseSequenceofCircularConvolutiony[n]usingBasicEquation");
xlabel("Samplesn");
ylabel("Amplitude");
AIM: FIR filter design using window method
clc ;
clear ;
xdel ( winsid () ) ;
fc = input (" Enter Analog cut off freq in Hz=")
fs = input (" Enter Analog sampling Freq . in Hz=")
M = input (" Enter o r d e r of f i l t e r =")
w = (2* %pi ) *( fc / fs );
disp (w , "Dig i t a l cut off freq u e n c y i n r a d i a n s . c y c l e s /s am pl e s " ) ;
wc = w/ %pi ;
disp ( wc , " Normalized digital cut off frequency in cycles/ samples " ) ;
[wft,wfm,fr]=wfir("lp",M+1,[wc/2,0],"re",[0,0]) ;
disp ( wft , "Impulse Response of LPF FIR Filter: h [ n]=" );
// P l o t t i n g t h e Magni tude R e s po n s e of LPF FIR F i l t e r
subplot (2 ,1 ,1)
subplot (2 ,1 ,2)
plot (2* w * fs , abs ( Hw ) ) ;
xlabel ( " Analog F r e q u e n c y i n Hz f −−−> " )
ylabel ( " Magnitude |H(w)|= " )
title ( " Magnitude R e s po n s e of I IR LPF " )
xgrid (1)