Digital Signal Processing

Digital signal processing (DSP) is the mathematical manipulation of an information signal to modify or improve it in some way. It is characterized by the representation of discrete time, discrete frequency, or other discrete domain signals by a sequence of numbers or symbols and the processing of these signals.

Please refer following programs which are related to points such as, Discrete Fourier Transform (DFT), Fast Fourier Transform (FFT), Finite Impulse Response (FIR) and Infinite Impulse Response (IIR) filter design techniques. Above points are related to subject DSP.





Aim: - Develop a Matlab program to generate discrete signals.

clc;
clear all;
close all;
N=21;
n=0:1:N-1;
% Generation of Unit step signal:
x1=ones(1,N);
subplot(3,2,1);
stem(n,x1);
xlabel('n');ylabel('x1(n)');
title('Unit Step Signal');
% Generation of Cosine signal:
x2=2*cos(0.1*pi*n);
subplot(3,2,2);
stem(n,x2);
xlabel('n');ylabel('x2(n)');
title('Cosine Signal');
% Generation of sinusoidal signal:
x2=2*sin(0.1*pi*n);
subplot(3,2,3);
stem(n,x2);
xlabel('n');ylabel('x2(n)');
title('sin Signal');
% Generation of  Ramp signal:
x3=n;
subplot(3,2,4);
stem(n,x3);
xlabel('n');ylabel('x3(n)');
title('Unit Ramp Signal');
% Generation of Exponential signal:
x4=2.^n;
subplot(3,2,5);
stem(n,x4);
xlabel('n');ylabel('x4(n)');
title('Exponential Signal');
% Generation of Unit Impulse:
m=-4:1:4;
subplot(3,2,6);
x5=[zeros(1,4),1,zeros(1,4)];
stem(m,x5);
xlabel('m'); ylabel('x5(m)');
title('Unit Impulse Signal');





Aim: - Develop a Matlab program to compute linear convolution of two signals.



clc;
clear all;
close all;
x1=input('Enter the input1:');
subplot(3,1,1);
stem(x1);
xlabel('n');ylabel('x1(n)');
title('1st input sequence');
x2=input('Enter the input2:');
subplot(3,1,2);
stem(x2);
xlabel('n');ylabel('x2(n)');
title('2nd input sequence');
x3=conv(x1,x2);
disp('x3=');disp(x3);
subplot(3,1,3);
stem(x3);
xlabel('n');ylabel('x3(n)');
title('Convolution of x1 and x2');





Aim: - Develop a Matlab program to compute circular convolution of two signals.

clc;
clear all;
close all;
x1=input('Enter the 1st sequence:');
subplot(3,1,1);
stem(x1);
xlabel('k');ylabel('xk');
title('Sequence1');

x2=input('Enter the 2nd sequence:');
subplot(3,1,2);
stem(x2);
xlabel('k');ylabel('xk');
title('Sequence2');

x3=cconv(x1,x2);
disp('x3=');disp(x3);
subplot(3,1,3);
stem(x3);xlabel('n');
ylabel('xn');
title('Circular Convolution');




AIM: - Develop A Matlab Program To Compute DFT And IDFT Of  Given Signal.


clc;
clear all;
close all;
xn=input('Enter the sequence x(n)'); %Get the sequence from user
ln=length(xn); %find the length of the sequence
xk=zeros(1,ln); %initilise an array of same size as that of input sequence
ixk=zeros(1,ln); %initilise an array of same size as that of input sequence
% DFT of the sequence
for k=0:ln-1
    for n=0:ln-1
        xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
    end
end
disp('magxk=');disp(abs(xk));
disp('phasexk=');disp(angle(xk));
% plot the input sequence
t=0:ln-1;
subplot(221);
stem(t,xn);
ylabel ('Amplitude');xlabel ('Time Index');
title ('Input Sequence');
magnitude=abs(xk); % Find the magnitudes of individual DFT points
%code block to plot the magnitude response
%------------------------------------------------
t=0:ln-1;
subplot(2,2,2);
stem(t,magnitude);
ylabel ('Amplitude');xlabel ('K');
title ('Magnitude Response');

phase=angle(xk); % Find the phases of individual DFT points
%code block to plot the magnitude sequence
t=0:ln-1;
subplot(223);
stem(t,phase);
ylabel ('Phase');xlabel ('K');
title ('Phase Response');
% Code block to find the IDFT of the sequence
for n=0:ln-1
    for k=0:ln-1
        ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));
    end
end
ixk=ixk./ln;
disp('ixk=');disp(ixk);
%code block to plot the input sequence
t=0:ln-1;
subplot(224);
stem(t,xn);
ylabel ('Amplitude');xlabel ('Time Index');
title ('IDFT sequence');



PROGRAM FOR FINDING DFT AND IDFT BY BUILT-IN FUNCTIONS

clc;
clear all;
close all;
xn=input('Enter the Sequence:');
N=length(xn);
n=0:1:N-1;
subplot(2,2,1);
%display input sequence
stem(n,xn);
xlabel('n');ylabel('xn');
title('Input Sequence');
%display fft
xk=fft(xn,N);
disp('Amplitude:');
disp(abs(xk));
disp('Phase:');disp(angle(xk));
k=0:1:N-1;
subplot(2,2,2);
stem(k,abs(xk));
xlabel('k');ylabel('xk');
title('DFT');
%display phase
subplot(2,2,3);
stem(k,angle(xk));
xlabel('k');ylabel('xk');
title('Angle');
%display IDFT
x=ifft(xk,N);
disp('IDFT:');disp(x);
n=0:1:N-1;
subplot(2,2,4);
stem(n,abs(x));
xlabel('n');ylabel('xn');
title('IDFT');




Aim: - Develop a Matlab program to compute linear convolution using overlap add method.
Title: Execution of Overlap Add Method

clc;
clear all;
close all;
x=input('Enter the input sequence:');
subplot(3,1,1);
stem(x);
xlabel('n');ylabel('xn');
title('Input Sequence');

b=input('Enter the filter coeff.:');
subplot(3,1,2);
stem(b);
xlabel('n');ylabel('xn');
title(' filter coeff.');

n=8;
y=fftfilt(b,x,n);
disp(‘y=’); disp(y);
subplot(3,1,3);
stem(y);
xlabel('n');ylabel('xn');
title('Output');





FIR filter design using Frequency sampling method


clc;
clear all;
f=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
m1=[1 1 1 1 1 1 0 0 0 0 0];
h1=fir2(10,f,m1);
display('Coefficients of LPF');
display(h1);

m2=[0 0 0 0 0 1 1 1 1 1 1];
display('Coefficients of HPF');
h2=fir2(10,f,m2);
display(h2);

m3=[0 0 0 1 1 1 1 1 0 0 0];
display('Coefficients of BPF');
h3=fir2(10,f,m3);
display(h3);

m4=[1 1 1 0 0 0 0 0 1 1 1];
display('Coefficients of BRF');
h4=fir2(10,f,m4);
display(h4);



OUTPUT


Coefficients of LPF

h1 =
    0.0033    0.0072   -0.0365   -0.0323    0.2858    0.5488    0.2858    -0.0323   -0.0365    0.0072    0.0033


Coefficients of HPF

h2 =
   -0.0032    0.0075    0.0362   -0.0335   -0.2855    0.5508   -0.2855    -0.0335    0.0362    0.0075   -0.0032


Coefficients of BPF

h3 =
   -0.0001   -0.0003   -0.0005   -0.2137    0.0013    0.5020    0.0013    -0.2137   -0.0005   -0.0003   -0.0001


Coefficients of BRF

h4 =
    0.0001    0.0003    0.0005    0.2137   -0.0013    0.4980   -0.0013    0.2137    0.0005    0.0003    0.0001










FIR filter design using  Windowing  method



  1)      Rectangular window


%Program for N=11 with cut off freq. pi/2   

clc;
clear all;

wn=[0.001 0.5];
h1=fir1(10,wn,rectwin(11));
display('Coefficients of LPF');
display(h1);

wn=[0.5 0.999];
h2=fir1(10,wn,rectwin(11));
display('Coefficients of HPF');
display(h2);

wn=[0.25 0.75];
h3=fir1(10,wn,rectwin(11));
display('Coefficients of BPF');
display(h3);

wn=[0.001 0.25 0.75 0.999];
h4=fir1(10,wn,rectwin(11));
display('Coefficients of BRF');
display(h4);


OUTPUT


Coefficients of LPF
h1 =
    0.0618   -0.0010   -0.1057   -0.0010    0.3131    0.4924    0.3131   -0.0010   -0.1057   -0.0010    0.0618
Coefficients of HPF
h2 =
   -0.0618   -0.0010    0.1057   -0.0010   -0.3131    0.4924   -0.3131   -0.0010    0.1057   -0.0010   -0.0618


Coefficients of BPF
h3 =
   -0.0000    0.0000   -0.0000   -0.2800    0.0000    0.4399    0.0000   -0.2800   -0.0000    0.0000   -0.0000

Coefficients of BRF
h4 =
    0.0000   -0.0021    0.0000    0.3351   -0.0000    0.5276   -0.0000    0.3351    0.0000   -0.0021    0.0000

2)  Hanning window


%Program for N=11 with cut off freq. pi/2   

clc;
clear all;

wn=[0.001 0.5];
h1=fir1(10,wn,hann(11));
display('Coefficients of LPF');
display(h1);

wn=[0.5 0.999];
h2=fir1(10,wn,hann(11));
display('Coefficients of HPF');
display(h2);

wn=[0.25 0.75];
h3=fir1(10,wn,hann(11));
display('Coefficients of BPF');
display(h3);

wn=[0.001 0.25 0.75 0.999];
h4=fir1(10,wn,hann(11));
display('Coefficients of BRF');
display(h4);


OUTPUT

           
           Coefficients of LPF
h1 =
         0   -0.0001   -0.0387   -0.0007    0.2999    0.5214    0.2999   -0.0007   -0.0387   -0.0001         0

Coefficients of HPF
h2 =
         0   -0.0001    0.0387   -0.0007   -0.2999    0.5214   -0.2999   -0.0007    0.0387   -0.0001         0

Coefficients of BPF
h3 =
         0    0.0000   -0.0000   -0.2273    0.0000    0.5455    0.0000   -0.2273   -0.0000    0.0000         0

Coefficients of BRF
h4 =
0           -0.0002    0.0000    0.2621   -0.0000    0.6305   -0.0000    0.2621    0.0000   -0.0002         0


3 )  Hamming window

%Program for N=11 with cut off freq. pi/2   

clc;
clear all;

wn=[0.001 0.5];
h1=fir1(10,wn,hamming(11));
display('Coefficients of LPF');
display(h1);

wn=[0.5 0.999];
h2=fir1(10,wn,hamming(11));
display('Coefficients of HPF');
display(h2);

wn=[0.25 0.75];
h3=fir1(10,wn,hamming(11));
display('Coefficients of BPF');
display(h3);

wn=[0.001 0.25 0.75 0.999];
h4=fir1(10,wn,hamming(11));
display('Coefficients of BRF');
display(h4);



OUTPUT

Coefficients of LPF
h1 =
    0.0052   -0.0002   -0.0443   -0.0007    0.3010    0.5190    0.3010   -0.0007   -0.0443   -0.0002    0.0052

Coefficients of HPF
h2 =
   -0.0052   -0.0002    0.0443   -0.0007   -0.3010    0.5190   -0.3010   -0.0007    0.0443   -0.0002   -0.0052

Coefficients of BPF
h3 =
   -0.0000    0.0000   -0.0000   -0.2324    0.0000    0.5352    0.0000   -0.2324   -0.0000    0.0000   -0.0000

Coefficients of BRF
h4 =
    0.0000   -0.0004    0.0000    0.2690   -0.0000    0.6208   -0.0000    0.2690    0.0000   -0.0004      0.0000

 
 



Program for Kaiser window:


clc;
clear all;
close all;
ap=0.5;
as=40;
dp=1-10^(-ap/20);
ds=10^(-as/20);
f=[0 250];
a=[1 0];
[N,wn,b]=kaiserord(f,a,[dp ds],1000);
disp(N);
disp(b);
h=fir1(N-1,wn,kaiser(N,b));
display(h);






Program for butterworth filter




clc;
clear all;
close all;
wp=0.5;
ws=0.82;
Rp=0.2;
Rs=3;
[n,wm]=buttord(wp,ws,Rp,Rs);
display(n);
[b,a]=butter(n,1,'s');
[bz,az]=impinvar(b,a,100);
display(bz);
display(az);





No comments:

Post a Comment