Online · Live + on demand
February 9-11, 2027
Price goes up Nov 1: register now to lock in today's rate
Register Now →
function [y]=sinc_new(x)
i=find(x==0);
x(i)= 1; // don't need this is /0 warning is off
y = sin(%pi*x)./(%pi*x);
y(i) = 1;
endfunction//Transformation of LPF IIR Digital Butterworth Filter into BPF
clear all;
clc;
close;
omegaP = 0.2*%pi;
omegaL = (2/5)*%pi;
omegaU = (3/5)*%pi;
z=poly(0,'z');
H_LPF = (0.245)*(1+(z^-1))/(1-0.509*(z^-1))
alpha = (cos((omegaU+omegaL)/2)/cos((omegaU-omegaL)/2));
k = (cos((omegaU - omegaL)/2)/sin((omegaU - omegaL)/2))*tan(omegaP/2);
NUM =-((z^2)-((2*alpha*k/(k+1))*z)+((k-1)/(k+1)));
DEN = (1-((2*alpha*k/(k+1))*z)+(((k-1)/(k+1))*(z^2)));
HZ_BPF=horner(H_LPF,NUM/DEN)
disp(HZ_BPF,'Digital BPF IIR Filter H(Z)= ')
HW =frmag(HZ_BPF(2),HZ_BPF(3),512);
W = 0:%pi/511:%pi;
plot(W/%pi,HW)
a=gca();
a.thickness = 3;
a.foreground = 1;
a.font_style = 9;
xgrid(1)
xtitle('Magnitude Response of BPF Filter cutoff frequency [0.4,0.6]','Normalized Digital Frequency--->','Magnitude');//Determination of spectrum of a signal
//With maximum normalized frequency f = 0.4
//using Blackmann window
clear all;
close;
clc;
N = 11;
cfreq = [0.4 0];
[wft,wfm,fr]=wfir('lp',N,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
for n = 1:N
h_balckmann(n)=0.42-0.5*cos(2*%pi*n/(N-1))+0.08*cos(4*%pi*n/(N-1));
wft_blmn(n) = wft(n)*h_balckmann(n);
end
wfm_blmn = frmag(wft_blmn,length(fr));
WFM_blmn_dB =20*log10(wfm_blmn);
plot2d(fr,WFM_blmn_dB)
xtitle('Frequency Response of Blackmann window Filtered output N = 11','Frequency in cycles per samples f','Energy density in dB')//Caption: write a program for decimation and interpolation of given
//Speech Signal [ Multirate Signal Processing]
clear;
clc;
[x,Fs,bits]=wavread("E:\4.wav");
n = length(x)
DECIMATION_OF_X = x(1:2:length(x));
INTERPOLATION_OF_X = zeros(1,2*length(x));
INTERPOLATION_OF_X(1:2:2*length(x)) = x;
subplot(3,1,1)
plot([1:n],x)
xtitle("ORIGINAL Speech SIGNAL");
subplot(3,1,2)
plot([1:ceil((n/2))],DECIMATION_OF_X)
xtitle("DECIMATION BY A FACTOR OF 2")
subplot(3,1,3)
plot([1:2*n],INTERPOLATION_OF_X)
xtitle("INTERPOLATION BY A FACTOR OF 2")//Caption: Determination of Frequency Resolution of the
//[1]. Barlett [2]. Welch [3].Blackman Tukey Power Spectrum Estimation
//Methods
clear;
clc;
close;
Q = 10; //Quality factor
N = 1000; //Length of the sample sequence
//Bartlett Method
F_Bartlett = Q/(1.11*N);
disp(F_Bartlett,'Frequency Resolution of Bartlett Power Spectrum Estimation')
//Welch Method
F_Welch = Q/(1.39*N);
disp(F_Welch,'Frequency Resolution of Welch Power Spectrum Estimation')
//Blackmann-Tukey Method
F_Blackmann_Tukey = Q/(2.34*N);
disp(F_Blackmann_Tukey,'Frequency Resolution of Blackmann Tukey Power Spectrum Estimation')
//Result
//Frequency Resolution of Bartlett Power Spectrum Estimation
// 0.0090090
//Frequency Resolution of Welch Power Spectrum Estimation
// 0.0071942
//Frequency Resolution of Blackmann Tukey Power Spectrum Estimation
// 0.0042735//Program to generate different window functions
//For FIR Filter design based on windowing techniques
clear all;
close;
clc
M =11 ;
for n = 1:M
h_Rect(n) = 1;
h_hann(n) = 0.5-0.5*cos(2*%pi*(n-1)/(M-1));
h_hamm(n) = 0.54-0.46*cos(2*%pi*(n-1)/(M-1));
h_balckmann(n) = 0.42-0.5*cos(2*%pi*n/(M-1))+0.08*cos(4*%pi*n/(M-1));
end
plot2d(1:M,[h_Rect,h_hann,h_hamm,h_balckmann],[2,5,7,9]);
legend(['Rectangular Window';'Hanning';'Hamming';'Balckmann']);
title('Window Functions for Length M = 11')function[n,p,r] = ReedSolomon_Codes(m)
// Reed-Solomon Codes
//Single-error-correcting RS code with a 2-bit byte
//m = m-bit symbol
k = 1^m; //number of message bits
t =1; //single bit error correction
n = 2^m-1; //code word length in 2-bit byte
p = n-k; //parity bits length in 2-bit byte
r = k/n; //code rate
disp(n,'code word length in 2-bit byte n =')
disp(p,'parity bits length in 2-bit byte n-k=')
disp(r,'Code rate:r = k/n =')
disp(2*t,'It can correct any error upto =')
endfunction
//Result
//-->exec('C:\Users\SENTHILKUMAR\Desktop\Communication_Toolbox\Digital_Communication\ReedSolomon_Codes.sci', -1)
//
//-->m=2
// m =
//
// 2.
//
//-->[n,p,r] = ReedSolomon_Codes(m)
//
// code word length in 2-bit byte n =
//
// 3.
//
// parity bits length in 2-bit byte n-k=
//
// 2.
//
// Code rate:r = k/n =
//
// 0.3333333
//
// It can correct any error upto =
//
// 2.
// r =
//
// 0.3333333
// p =
//
// 2.
// n =
//
// 3.
//function [value] = xor(A,B)
if(A==B)
value = 0;
else
value = 1;
end
endfunction//Band Pass FIlter of length M = 16
//Lower Cutoff frequency fp = 0.2 and Upper Cutoff frequency fs = 0.3
// Choose the number of cosine functions and create a dense grid
// in [0,0.1) and [0.2,0.35] and [0.425,0.5]
//magnitude for pass band = 1 & stop band = 0 (i.e) [0 1 0]
//Weighting function =[10 1 10]
clear all;
clc;
close;
hn = 0;
hm = 0;
hn=eqfir(16,[0 .1;.2 .35;.425 .5],[0 1 0],[10 1 10]);
[hm,fr]=frmag(hn,256);
disp(hn,'The Filter Coefficients are:')
figure
plot(.5*(0:255)/256,20*log10(frmag(hn,256)));
a = gca();
xlabel('Normalized Digital Frequency fr');
ylabel('Magnitude in dB');
title('Frequency Response of FIR BPF using REMEZ algorithm M=16')
xgrid(2)//Continuous Time Fourier Transform of a
//Continuous Time Exponential Signal x(t)= exp(-A*t)u(t), A>0
//And Plotting its Magnitude response and phase response
clear;
clc;
close;
// Analog Signal
A =1; //Amplitude
Dt = 0.005;
t = 0:Dt:10;
xt = exp(-A*t);
//
// Continuous-time Fourier Transform
Wmax = 2*%pi*1; //Analog Frequency = 1Hz
K = 4;
k = 0:(K/1000):K;
W = k*Wmax/K;
XW = xt* exp(-sqrt(-1)*t'*W) * Dt;
XW_Mag = abs(XW);
W = [-mtlb_fliplr(W), W(2:1001)]; // Omega from -Wmax to Wmax
XW_Mag = [mtlb_fliplr(XW_Mag), XW_Mag(2:1001)];
[XW_Phase,db] = phasemag(XW);
XW_Phase = [-mtlb_fliplr(XW_Phase),XW_Phase(2:1001)];
//Plotting Continuous Time Signal
figure
a = gca();
a.y_location = "origin";
plot(t,xt);
xlabel('t in sec.');
ylabel('x(t)')
title('Continuous Time Signal')
figure
//Plotting Magnitude Response of CTS
subplot(2,1,1);
a = gca();
a.y_location = "origin";
plot(W,XW_Mag);
xlabel('Frequency in Radians/Seconds---> W');
ylabel('abs(X(jW))')
title('Magnitude Response (CTFT)')
//Plotting Phase Reponse of CTS
subplot(2,1,2);
a = gca();
a.y_location = "origin";
a.x_location = "origin";
plot(W,XW_Phase*%pi/180);
xlabel(' Frequency in Radians/Seconds---> W');
ylabel(' <X(jW)')
title('Phase Response(CTFT) in Radians')//Nonreturn-to-zero unipolar format: Discrete PAM Signals Generation
//Unipolar NRZ
clear;
close;
clc;
x = [0 1 0 0 0 1 0 0 1 1];
binary_zero = [0 0 0 0 0 0 0 0 0 0];
binary_one = [1 1 1 1 1 1 1 1 1 1];
L = length(x);
L1 = length(binary_zero);
total_duration = L*L;
//plotting
a =gca();
a.data_bounds =[0 -2;L*L1 2];
for i =1:L
if(x(i)==0)
plot([i*L-L+1:i*L],binary_zero);
poly1= a.children(1).children(1);
poly1.thickness =3;
else
plot([i*L-L+1:i*L],binary_one);
poly1= a.children(1).children(1);
poly1.thickness =3;
end
end
xgrid(1)
title('Unipolar NRZ')function [Cx,Xmax] = Alaw(x,A)
//Non-linear Quantization
//A-law: A-law nonlinear quantization
//x = input vector
//Cx = A-law compressor output
//Xmax = maximum of input vector x
Xmax = max(abs(x));
for i = 1:length(x)
if(x(i)/Xmax < = 1/A)
Cx(i) = A*abs(x(i)/Xmax)./(1+log(A));
elseif(x(i)/Xmax > 1/A)
Cx(i) = (1+log(A*abs(x(i)/Xmax)))./(1+log(A));
end
end
Cx = Cx/Xmax; //normalization of output vector
Cx = Cx';
endfunctionfunction [Cx,Xmax] = mulaw(x,mu)
//Non-linear Quantization
//mulaw: mulaw nonlinear quantization
//x = input vector
//Cx = mulaw compressor output
//Xmax = maximum of input vector x
Xmax = max(abs(x));
if(log(1+mu)~=0)
Cx = (log(1+mu*abs(x/Xmax))./log(1+mu));
else
Cx = x/Xmax;
end
Cx = Cx/Xmax; //normalization of output vector
endfunction
////////////////////////////////////////////////////
function x = invmulaw(y,mu)
//Non-linear Quantization
//invmulaw: inverse mulaw nonlinear quantization
//x = output vector
//y = input vector (using mulaw nonlinear comression)
x = (((1+mu).^(abs(y))-1)./mu)
endfunctionfunction [SQNR,xq,en_code] = uniform_pcm(x,L)
//x = input sequence
//L = number of qunatization levels
xmax = max(abs(x));
xq = x/xmax;
en_code = xq;
d = 2/L;
q = d*[0:L-1];
q = q-((L-1)/2)*d;
for i = 1:L
xq(find(((q(i)-d/2)<= xq)&(xq<=(q(i)+d/2))))=...
q(i).*ones(1,length(find(((q(i)-d/2)<=xq)&(xq<=(q(i)+d/2)))));
en_code(find(xq == q(i)))= (i-1).*ones(1,length(find(xq == q(i))));
end
xq = xq*xmax;
SQNR = 20*log10(norm(x)/norm(x-xq));
endfunctionfunction [c] = PCM_Encoding(x,L,en_code)
//Encoding: Converting Quantized decimal sample values in to binary
//x = input sequence
//L = number of qunatization levels
//en_code = normalized input sequence
n = log2(L);
c = zeros(length(x),n);
for i = 1:length(x)
for j = n:-1:0
if(fix(en_code(i)/(2^j))==1)
c(i,(n-j)) =1;
en_code(i) = en_code(i)-2^j;
end
end
end
disp(c)//PN sequence generation
//Maximum-length sequence generator
//Program to generate Maximum Length Pseudo Noise Sequence
clc;
//Assign Initial value for PN generator
x0= 1;
x1= 0;
x2 =0;
x3 =0;
N = input('Enter the period of the signal')
for i =1:N
x3 =x2;
x2 =x1;
x1 = x0;
x0 =xor(x1,x3);
disp(i,'The PN sequence at step')
x = [x1 x2 x3];
disp(x,'x=')
end
m = [7,8,9,10,11,12,13,17,19];
N = 2^m-1;
disp('Table Range of PN Sequence lengths')
disp('_________________________________________________________')
disp('Length of shift register (m)')
disp(m)
disp('PN sequence Length (N)')
disp(N)
disp('_________________________________________________________')function [value] = xor(A,B)
if(A==B)
value = 0;
else
value = 1;
end
endfunction// Hamming Weight and Hamming Distance
//H(7,4)
//Code Word Length = 7, Message Word length = 4, Parity bits =3
close;
clc;
//Getting Code Words
code1 = input('Enter the first code word');
code2 = input('Enter the second code word');
Hamming_Distance = 0;
for i = 1:length(code1)
Hamming_Distance =Hamming_Distance+xor(code1(i),code2(i));
end
disp(Hamming_Distance,'Hamming Distance')
//Result
//Enter the first code word [0,1,1,1,0,0,1]
//Enter the second code word[1,1,0,0,1,0,1]
//Hamming Distance 4.//Caption:Convolutional Code Generation
//Time Domain Approach
close;
clc;
g1 = input('Enter the input Top Adder Sequence:=')
g2 = input('Enter the input Bottom Adder Sequence:=')
m = input('Enter the message sequence:=')
x1 = round(convol(g1,m));
x2 = round(convol(g2,m));
x1 = modulo(x1,2);
x2 = modulo(x2,2);
N = length(x1);
for i =1:length(x1)
x(i,:) =[x1(N-i+1),x2(N-i+1)];
end
x = string(x)
//Result
//Enter the input Top Adder Sequence:=[1,1,1]
//Enter the input Bottom Adder Sequence:=[1,0,1]
//Enter the message sequence:=[1,1,0,0,1]
//x =
//!1 1 !
//! !
//!1 0 !
//! !
//!1 1 !
//! !
//!1 1 !
//! !
//!0 1 !
//! !
//!0 1 !
//! !
//!1 1 !//Hamming Encoding
//H(7,4)
//Code Word Length = 7, Message Word length = 4, Parity bits =3
//clear;
close;
clc;
//Getting Message Word
m3 = input('Enter the 1 bit(MSb) of message word');
m2 = input('Enter the 2 bit of message word');
m1 = input('Enter the 3 bit of message word');
m0 = input('Enter the 4 bit(LSb) of message word');
//Generating Parity bits
for i = 1:(2^4)
b2(i) = xor(m0(i),xor(m3(i),m1(i)));
b1(i) = xor(m1(i),xor(m2(i),m3(i)));
b0(i) = xor(m0(i),xor(m1(i),m2(i)));
m(i,:) = [m3(i) m2(i) m1(i) m0(i)];
b(i,:) = [b2(i) b1(i) b0(i)];
end
C = [b m];
disp('___________________________________________________________')
for i = 1:2^4
disp(i)
disp(m(i,:),'Message Word')
disp(b(i,:),'Parity Bits')
disp(C(i,:),'CodeWord')
disp(" ");
disp(" ");
end
disp('___________________________________________________________')
//disp(m b C)
//Result
//Enter the 1 bit(MSb) of message word [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1];
//Enter the 2 bit of message word [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1];
//Enter the 3 bit of message word [0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1];
//Enter the 4 bit(LSb) of message word [0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1];