Académique Documents
Professionnel Documents
Culture Documents
Experiment No: - 01
AIM: - To write a MATLAB program to find the sum of two sinusoidal signals.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
Clear all;
Close all;
t=0:0.001:0.1;
f1=50;
x1=2*pi*f1*t;
y1=sin(x1);
figure;
subplot (3,1,1);
plot (t,y1);
title('sin(x1');
f2=100;
x2=2*pi*f2*t;
y2=sin(x2);
subplot(3,1,2);
plot(t,y2);
title('sin(x2)');
y=y1+y2;
subplot(3,1,3);
plot(t,y);
title('sinx1=sinx2')
RESULTS:-
Thus the MATLAB program for sum of two sinusoidal signals was performed and the output
was verified.
Page No 1
OUTPUT:
Page No 2
ANALOG LOW PASS FILTER
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
close all;
clear all;
f=100:20:8000;
fh=900;
k=length(f);
for i=1:k;
m(i)=1/sqrt(1+(f(i)/fh)^2);
mag(i)=20*log10(m(i));
end;
figure;
semilogx(f,mag);
title('magnitude response of analog of low pass filter')
xlabel('frequency----->');
ylabel('magnitude in db');
grid on;
RESULTS:-
Thus the MATLAB program for analog Low pass filter was written and magnitude response
was plotted.
Page No 3
OUTPUT:-
Page No 4
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
close all;
clear all;
f=100:20:8000;
fl=400;
k=length(f);
for i=1:k;
m(i)=1/sqrt(1+(fl/f(i))^2);
mag(i)=20*log10(m(i));
end;
figure;
semilogx(f,mag);
title('magnitude response of analog of high pass filter');
xlabel('frequency----->');
ylabel('magnitude in db');
grid on;
RESULTS:-
Thus the MATLAB program for analog high pass filter was written and magnitude response
was plotted.
Page No 5
OUTPUT:
Page No 6
FIR LP\HP FILTER
USING
KAISER WINDOWING TECHNIQUES
AIM: - TO write a MATLAB program to design FIR LP\HP using Kaiser window
techniques.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
beta=input('enter the beta value');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=kaiser(n1,beta);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Kaiser window of LPF ----');
grid on; Page No 7
%Highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Kaiser window of HPF ----');
grid on;
RESULTS:- Thus the MATLAB program for FIR LP\HP using Kaiser Window
Techniques was executed.
INPUT:-
enter the pass band ripple 0.02
enter the stop band ripple 0.01
enter the pass band frequency 1000
enter the stop band frequency 1500
enter the sampling frequency 10000
enter the beta value 5.8
OUTPUT:
Page No 8
Page No 9
FIR LP\HP FILTER
USING
TRIANGULAR WINDOWING TECHNIQUES
AIM: - TO write a MATLAB program to design FIR LP\HP using Triangular window
Techniques.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=triang(n1);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Triangular window of LPF ----');
grid on;
Page No 10
%Highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Triangular window of HPF ----');
grid on ;
RESULTS:-
Thus the MATLAB program for FIR LP\HP using triangular window
Techniques was executed.
INPUT:-
Page No 11
OUTPUT:
Page No 12
FIR LP\HP FILTER
USING
RECTANGULAR WINDOWING TECHNIQUES
AIM: - TO write a MATLAB program to design FIR LP\HP using Rectangular window
Techniques.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=boxcar(n1);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Rectangular window of LPF ----');
grid on;
Page No 13
%Highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Rectangular window of HPF ----');
title('Magnitude response of high pass filter');
grid on;
RESULTS:-
Thus the MATLAB program for FIR LP\HP using rectangular window
Techniques was executed.
INPUT:-
Page No 14
OUTPUT:
Page No 15
LINEAR CONVOLUTION USING MATLAB
Experiment No: - 04
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
clear all;
close;
disp('enter the length of the first sequence m=');
m=input('');
disp('enter the length of first sequence x[m]=');
for i=1:m
x(i)=input('');
end
disp('enter the length of the second sequence n=');
n=input('');
disp('enter the length of second sequence h[n]=');
for j=1:n
h(j)=input('');
end
y=conv(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel ('amplitude---->');
xlabel('n---->');
title('x(n) Vs n');
subplot(3,1,2);
stem(h);
ylabel('amplitude---->');
xlabel('n---->');
title('h(n) Vs n');
subplot(3,1,3);
stem(y);
ylabel('amplitude---->');
xlabel('n---->');
title('y(n) Vs n');
disp('linear convolution of x[m] and h[n] is y');
Page No 16
INPUT:--
OUTPUT:-
Linear convolution of x[m] and h[n] is y=
1 4 10 20 35 56 70 76 73 60 36
RESULTS :- Thus the program for linear convolution is written using MATLAB and verified.
Page No 17
CIRCULAR CONVOLUTION USING MATLAB
Experiment No: - 05
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
RESULTS:-
Thus the program for circular convolution is written using MATLAB and verified.
INPUT:-
Page No 18
OUTPUT:-
59 62 59 50 35 50
Page No 19
BUTTERWORTH LOW PASS FILTER
AIM: - TO write a MATLAB program to Amplitude response and response of Butter worth Low pass filter
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]= butter(n,wn);
[b,a]=butter(n,wn,'s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db--------->');
xlabel('(a) normalized freq------>');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in db--------->');
xlabel('(b) normalized freq------>');
Page No 20
INPUT:-
enter the passband ripple.15
enter the stopband ripple60
enter the passband frequency1500
enter the stopband frequency3000
enter the sampling frequency7000
RESULTS:-
Thus the Amplitude response and phase response of Butter worth Low pass filter was verified.
OUTPUT:-
Page No 21
BUTTERWORTH HIGH PASS FILTER
AIM: - TO write a MATLAB program to Amplitude response and response of Butter worth high pass filter
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]= butter(n,wn);
[b,a]=butter(n,wn,'high','s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db--------->');
xlabel('(a) normalized freq------>');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in db--------->');
xlabel('(b) normalized freq------>');
Page No 22
INPUT:-
Enter the passband ripple.2
Enter the stopband ripple40
Enter the passband frequency2000
Enter the stopband frequency3500
Enter the sampling frequency8000
RESULTS:-
Thus the Amplitude response and phase response of Butter worth high pass filter was verified.
OUTPUT:
Page No 23
LINER CONVOLUTION
Experiment No: - 07
Compile:-
Page No 24
PROGRAM:-
#include<stdio.h>
int m=6;
int n=6;
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int y[20];
main()
{
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]);
}
OUTPUT:-
4
10
20
35
56
70
76
73
60
36
Page No 25
Page No 26
Page No 27
CIRCULAR CONVOLUTION
Experiment No: - 08
Compile:-
Page No 28
PROGRAM:-
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf("enter the length of the 1st sequence\n");
scanf("%d",&m);
printf("enter the length of the second sequence\n");
scanf("%d",&n);
printf("enter the 1st 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(m>n)
{
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++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
Page No 29
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf("the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}
INPUT:-
OUTPUT:-
Page No 32
8 – FFT
Experiment No: - 09
AIM: - TO write a C- program to compute 8 – FFT of given sequences using DIF – FFT algorithm
Compile:-
Page No 33
PROGRAM:-
#include<stdio.h>
#include<math.h>
#define N 8
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
main()
{
int i;
complex w[N];
complex x[8]={0,0.0,1,0.0,2,0.0,3,0.0,4,0.0,5,0.0,6,0.0,7,0.0};
complex temp1,temp2;
int j,k,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<3;i++)
{
index=0;
for(j=0;j<leg_diff;j++)
{
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff))
{
lower_leg=upper_leg+leg_diff;
temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
Page No 34
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
printf("the fft of the given input sequence is \n");
for(i=0;i<8;i++)
{
printf("%f %f \n",(x[i]).real,(x[i]).imag);
}
}
OUTPUT:-
Page No 35
FFT 1-D
Experiment No: - 10
AIM: - TO write a C- program to compute FFT of the given 1- D signal and plot
Algorithm:-
PROGRAM:-
#include<stdio.h>
#include<math.h>
#define N 32
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
float iobuffer[N];
float y[N];
main()
{
int i;
complex w[N];
complex x[N];
complex temp1,temp2;
int j,k,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
{
iobuffer[i]=sin((2*PI*2*i)/32.0);
}
for(i=0;i<N;i++)
{
Page No 36
x[i].real=iobuffer[i];
x[i].imag=0.0;
}
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<5;i++)
{
index=0;
for(j=0;j<leg_diff;j++)
{
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff))
{
lower_leg=upper_leg+leg_diff;
temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
Page No 37
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
for(i=0;i<N;i++)
{
y[i]=sqrt((x[i].real*x[i].real)+(x[i].imag*x[i].imag));
}
for(i=0;i<N;i++)
{
printf("%f\t",y[i]);
}
return(0);
}
OUTPUT:-
Page No 38
Page No 39
POWER DENSITY SPECTRUM
Experiment No: - 11
AIM: - TO write a C- program to compute power density spectrum of given one – dimensional signal and plot.
Algorithm:-
PROGRAM:-
#include<stdio.h>
#include<math.h>
#define N 16
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
complex x[N];
float iobuffer[N];
float x1[N],y[N];
int i;
main()
{
complex w[N];
complex temp1,temp2;
float sum=0.0;
int j,k,n,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
{
Page No 40
iobuffer[i]=sin((2*PI*2*i)/15.0);
}
for(n=0;n<N;n++)
{
sum=0;
for(k=0;k<N-n;k++)
{
sum=sum+(iobuffer[k]*iobuffer[n+k]);
}
x1[n]=sum;
}
for(i=0;i<N;i++)
{
x[i].real=x1[i];
x[i].imag=0.0;
}
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<4;i++)
{
index=0;
for(j=0;j<leg_diff;j++)
{
for(upper_leg=j;upper_leg<N;upper_leg+=(2*leg_diff))
{
lower_leg=upper_leg+leg_diff;
temp1.real=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
Page No 41
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
for(i=0;i<N;i++)
{
y[i]=sqrt((x[i].real*x[i].real)+(x[i].imag*x[i].imag));
}
for(i=0;i<N;i++)
{
printf("%f\t",y[i]);
}
return(0);
}
OUTPUT:-
Page No 42
Page No 43
Page No 44
Page No 45
Page No 46