18ECL57
18ECL57
18ECL57
Management
SAVGAON ROAD, BELGAUM-590009
(Accredited by NAAC)
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
t=0:0.001:1;
fm=15;//hz
x=cos(2*%pi*fm*t);
//Under Sampling
fs=20;
n=0:1/fs:1;//n=Ts
Xn=cos(2*%pi*fm*n);
subplot(333);
plot2d3(n,Xn);
xtitle('undersampled signal fs<2fm','time','amplitude');
subplot(334);
plot2d(n,Xn);
xtitle('undersampled signal fs<2fm reconstructed','time','amplitude');
//Over Sampling
fs=1000;
n=0:1/fs:1;
Xn=cos(2*%pi*fm*n);
subplot(337)
plot2d3(n,Xn);
xtitle('sampled signal fs>2fm','time','amplitude');
subplot(338)
plot2d(n,Xn);
xtitle('reconstructed sampled signal fs>2fm','time','amplitude');
output:-
Clc;
clear all;
x=input('enter the first sequence: ');
y=input('enter the second sequence: ');
lc=conv(x,y);
disp(lc)
subplot(311)
plot2d3(x)
xtitle('first seq','time','magnitude')
subplot(312)
plot2d3(y)
xtitle('second seq','time','magnitude')
subplot(313)
plot2d3(lc)
xtitle('linear convolution','time','magnitude')
Input:
enter the first sequence: [ 1 2 3 4]
Output:
m=length(x);
n=length(h);
N=max(m,n);
for i=m+1:N
x(i)=0;
end
for i=n+1:N
h(i)=0;
end
y=zeros(1,N)
for n=1:N
for k=1:N
y(n)=y(n)+x(k)*h(pmodulo((n-k),N)+1)
end
end
disp(y);
//ploting
subplot(311);
plot2d3(x);
plot(x,"ok")
subplot(312);
plot2d3(h);
plot(h,"ok")
plot2d3(y);
plot(y,"ok")
Input:
enter the first sequence [1 2 3 4]
enter the second sequence [1 4 5 6]
Output:
44. 44. 40. 32.
function [y]=circ_conv(x, h)
m=length(x);
n=length(h);
N=max(m,n);
for i=m+1:N
x(i)=0;
end
for i=n+1:N
h(i)=0;
end
y=zeros(1,N);
for n=1:N
for k=1:N
y(n)=y(n)+x(k)*h(pmodulo((n-k),N)+1);
end
end
endfunction
///associativity x*(y*z)=(x*y)*z
f1=circ_conv(x,(circ_conv(y,z)));//lhs
g1=circ_conv(circ_conv(x,y),z);//rhs
if (f1==g1) then
disp('associativity property satisfies x*(y*z)=(x*y)*z');
disp('result f1=',f1);
else
disp('circular convolution is not associative');
end
//distributive property x1*(x2+x3)=(x1*x2)+(x1*x3)
f2= circ_conv(x,(y+z));//lhs
g2= circ_conv(x,y)+circ_conv(x,z);
if(f2==g2) then
disp('distributive property satisfies x1*(x2+x3)=(x1*x2)+(x1*x3)');
disp('result f2=',f2);
else
disp('distributive property is not satisfied');
end
Input:
enter the 1st sequence=[ 1 2 3 4]
enter the 2nd sequence=[5 6 7 8]
enter the 3rd sequence=[1 3 5 2 ]
//SYMMETRY PROPERTY
Rxx_flip=0;
Rxx_flip==Rxx($:-1:1)
if Rxx_flip==Rxx then
disp('Property 1: autocorelation of a sequence has even symmetry');
disp(Rxx_flip);
end
//PROPERTY 2
mx=max(Rxx);
if mx==Rxx(mid) then
disp('Property 2: maximum value of autocorrelation is obtained at n=0');
disp(mx,'max=Rxx(mid)');
end
//PROPERTY 3
E=sum(x.^2);
if mx==E then
disp('Property 3: Energy of the sequence is present at Rxx(0),max=E');
disp(E);
else
disp('Mean square value not verified');
end
//plotting
subplot(211);
t1=0:1:(length(x)-1)
xtitle('input x(n)','x(n)');
plot2d3(t1,x);
t=-(N-mid):1:(N-mid);//-(mid-1):1:(mid-1);-((N/2)-1):1:((N/2)-1);
subplot(212);
xtitle('autocorrelation Rxx','samples n','Rxx');
plot2d3(t,Rxx);
Input:
enter the input sequence:[ 1 3 2 4]
Output:
4. 14. 17. 30. 17. 14. 4.
"Property 2: maximum value of autocorrelation is obtained at n=0"
30.
"max=Rxx(mid)"
"Property 3: Energy of the sequence is present at Rxx(0),max=E"
30
Rxy=xcorr(x,y);//CROSS CORRELATION
disp(Rxy,'cross correlation of sequence Rxy=');
N=length(Rxy);
Ryx=xcorr(y,x);
disp(Ryx,'cross correlation of sequence Ryx=');
z=Rxy($:-1:1);//SIGNAL FOLDING
disp(z);
if z==Ryx then
disp('Property Rxy[-n]=Ryx[n] satisfied');
disp(Ryx);
else
disp('property Rxy[-n]=Ryx[n] not satisfied');
end
Input:
Input:
Output:
1. 0. -0.125 -0.09375
// Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum (using
DFT equation and verify it by built-in routine).
clc;
clear all;
N=length(y);
disp(y)
n=0:1:(N-1);
k=0:1:(N-1);
n=n'
w=exp(-%i*2*%pi*n*k/N)
disp(w)
Xk=y*w;
disp(Xk,'N point DFT');
mag=abs(Xk)
disp(mag,'magnitude response of X(k)');
subplot(222);
xtitle('magnitude response of X(k)','samples k','X(k)');
plot2d3(k,mag);
phase=atan(imag(Xk),real(Xk))
disp(phase,'phase of X(k)');
subplot(223);
xtitle('phase response of X(k)','samples k','X(k)');
plot2d3(k,phase);
//IDFT of X(k)
w1=exp(%i*2*%pi*n*k/N);
x2=(1/N)*Xk*w1;
x21=round(x2)
disp(x2,'IDFT of X(k)');
subplot(224);
xtitle('IDFT of X(k)','samples n','x2(n)');
plot2d3(k,x2);
//verification
Xk1=fft(y)
disp(Xk1,'verification by direct function');
disp([y])
X2=asciimat(x21);
disp(X2)
Input:
enter the sequence= [ 1 3 2 4]
Output:
1. 3. 2. 4.
1. + 0.i 1. + 0.i 1. + 0.i 1. + 0.i
1. + 0.i 6.123D-17 - i -1. - 1.225D-16i -1.837D-16 + i
1. + 0.i -1. - 1.225D-16i 1. + 2.449D-16i -1. - 3.674D-16i
1. + 0.i -1.837D-16 + i -1. - 3.674D-16i 5.511D-16 - i
10. + 0.i -1. + 1.i -4. - 1.347D-15i -1. - 1.i
"N point DFT"
10. 1.4142136 4. 1.4142136
"magnitude response of X(k)"
0. 2.3561945 -3.1415927 -2.3561945
"phase of X(k)"
1. - 6.661D-16i 3. - 2.959D-16i 2. + 1.225D-16i 4. + 3.751D-16i
"IDFT of X(k)"
10. + 0.i -1. + i -4. + 0.i -1. - i
"verification by direct function"
1. 3. 2. 4.
Input:
enter the first sequence [1 2 3 4]
DFT of LHS
DFT of RHS
clc;
clear all;
t=-%pi:0.05:2*%pi;
X=squarewave(t);
disp(X);
figure(1)
plot2d3(X);
f1=fft(X);
f2=abs(f1);
disp(f2);
figure(2)
plot2d(f2)
OUTPUT:-
N=length(x);
X=fft(x);
mag1=abs(X);
RHS=(1/N)*sum(mag1.^2);
disp(RHS,'Energy of the sequence in frequency domain');
Input:
30.
30.
OUTPUT:-
OUTPUT:-
65.
1.3744468
fp = input('Enter the Pass band frequency in Hz = ' ); //Define pass stop and ripple frequency
fs = input('Enter the Stop band frequency in Hz = ');
Fs = input('Enter the Sampling frequency in Hz = ');
Ap = input(' Enter the Pass band ripple in db:');
As = input('Enter theStop band ripple in db:');
wp=2*%pi*fp/ws;// Analog frequency
ws=2*%pi*Fs/ws;
Up = 2*tan(wp/2);// Prewrapped frequency
Us = 2*tan(ws/2);
[n,wn]= buttmag (Up,Us,Ap,As,'s');// Calculate order and cutoff freq
disp('order of the filter N =');
disp(N);
disp('Normalized cut off frequency = ');
disp(wn);
[num, den] = butter(n,wc,'s');// analog filter transfer
[b,a] = bilinear(num, den,1);
Freqz(b,a,512,Fs);
Printsys(b,a,’z’);
#include<stdio.h>
main()
{ int m=5; /*Lenght of i/p samples sequence*/
int n=4; /*Lenght of impulse response Co-efficients */
int i=0,j;
int x[10]={2,2,3,4,6}; /*Input Signal Samples*/
int h[10]={1,2,3,4}; /*Impulse Response Co-efficients*/
/*At the end of input sequences pad 'M' and 'N' no. of zero's*/
int *y;
y=(int *)0x0000100;
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
//int *y;
//y=(int *)0x00010400;
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
#include <stdio.h>
#include <math.h>
void main()
{
short i,j;
printf("Enter the length of the input sequence:\n");
scanf("%d",&N);
printf("Enter the input sequence:\n");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
void dft(int *x, short k, float *real, float *imaginary) //DFT function
{
float sumRe = 0; //initialize real component
float sumIm = 0; //initialize imaginary component
int i = 0;
float cs = 0; //initialize cosine component
float sn = 0; //initialize sine component
/* Determine the Impulse response of first order and second order system */
#include<stdio.h>
#define Order 2
#define Len 5
void main()
{
int j,k;
}
}