DSP - Anna University
DSP - Anna University
DSP - Anna University
Date:
GENERATION
Program:
clc;
clear all;
close all;
t=-5:5;
for i=1:length(t)
if((t(i))==0)
y(i)=1;
else
y(i)=0;
end
end
subplot(3,2,1);
stem(t,y)
xlabel('time')
ylabel('amplitude')
title('impulse')
OUTPUT:
CONTINUOUS SIGNAL
GENERATION
Experiment No: 1(b)
Date:
PROGRAM:
clc;
clear all;
close all;
t=-5:5;
for i=1:length(t)
if((t(i))==0)
y(i)=1;
else
y(i)=0;
end
end
subplot(3,2,1);
plot(t,y)
xlabel('time')
ylabel('amplitude')
title('impulse')
OUTPUT:
Experiment No: 2(a)
Date:
LINEAR CONVOLUTION
PROGRAM:
clc;
clear all;
close all;
x=[1,5,9,8,4,2,3];
h=[1,0,1];
N=length(x);
M=length(h);
Z=N+M-1;
x=[x zeros(1,Z-N)];
h=[h zeros(1,Z-M)];
y=zeros(1,Z);
for k=1:Z
for n=1:Z
if(n-k+1>0)
y(n)=y(n)+(x(k)*h(n-k+1));
end
end
end
subplot(3,1,1)
stem(x);
xlabel('time');
ylabel('amplitude’);
title('linear convolution');
title('input sequence');
subplot(3,1,2)
stem(h);
xlabel('time’);
ylabel('amplitude');
title('impulse sequence');
subplot(3,1,3)
stem(y);
xlabel('time');
ylabel('amplitude’);
title('output sequence');
OUTPUT:
Experiment No: 2(b)
Date:
CIRCULAR CONVOLUTION
PROGRAM:
clc;
clear all;
close all;
x=[1,5,9,8,4,2,3];
h=[1,0,1];
N=length(x);
M=length(h);
Z=max(N,M);
x=[x zeros(1,Z-N)];
h=[h zeros(1,Z-M)];
y=zeros(1,Z);
for k=1:Z
for n=1:Z
j=n-k+1;
if(j<=0)
j=j+Z
y(n)=y(n)+(x(k)*h(j));
end
end
end
subplot(3,1,1)
stem(x);
xlabel('time');
ylabel('amplitude');
title('input sequence');
subplot(3,1,2)
stem(h);
xlabel('time');
ylabel('amplitude');
title('impulse sequence');
subplot(3,1,3)
stem(y);
xlabel('time');
ylabel('amplitude');
title('output sequence');
OUTPUT:
Experiment No: 3(a) AUTOCORRELATION
Date:
PROGRAM:
clc;
clear all;
close all;
x=[1:100]
[f l b]=autocorr(x)
subplot(3,2,1)
stem(x)
subplot(3,2,2)
stem(f)
xlabel('time')
ylabel('samples')
x1=rand(1,30)
[h l b]=autocorr(x1)
subplot(3,2,3)
stem(x1)
subplot(3,2,4)
stem(h)
xlabel('time')
ylabel('samples')
t=-5:0.01:5;
x2=5*sin(2*pi*t)
[g l b]=autocorr(x2)
subplot(3,2,5)
stem(x2)
subplot(3,2,6)
stem(g)
xlabel('time')
ylabel('samples')
OUTPUT:
Experiment No: 3(b) CROSS CORRELATION
Date:
PROGRAM:
clear all;
close all;
clc;
x=[1:100]
y=[1:200]
f=xcorr(x,y)
subplot(3,3,1)
stem(x)
subplot(3,3,2)
stem(y)
subplot(3,3,3)
stem(f)
xlabel('time')
ylabel('samples')
x1=rand(1,30)
y1=rand(1,50)
h=xcorr(x1,y1)
subplot(3,3,4)
stem(x1)
subplot(3,3,5)
stem(y1)
subplot(3,3,6)
stem(h)
xlabel('time')
ylabel('samples')
t=-5:0.01:5;
x2=5*sin(2*pi*t)
y2=7*sin(2*pi*t)
g=xcorr(x2,y2)
subplot(3,3,7)
stem(x2)
subplot(3,3,8)
stem(y2)
subplot(3,3,9)
stem(g)
xlabel('time')
ylabel('samples')
OUTPUT:
Experiment No: 4 FREQUENCY ANALYSIS
Date:
USING FFT
PROGRAM:
clc;
clear all;
close all;
fs=700;
t=0:1/fs:1-(1/fs);
x=sin(2*pi*20*t)+sin(2*pi*40*t)+sin(2*pi*100*t);
m=length(x);
nfft=2.^nextpow2(m);
y=fft(x,nfft);
magy=abs(y);
yph=angle(y);
f=(0:1/nfft:1-(1/nfft))*fs;
F=f(1:m/2);
ymag1=magy(1:m/2);
phy1=yph(1:m/2)
figure;plot(F,ymag1)
figure;plot(F,phy1)
OUTPUT:
PHASE SPECTRUM
MAGNITUDE SPECTRUM
Experiment No: 5 IIR FILTERS:
Date:
BUTTERWORTH
PROGRAM:
BUTTERWORTH HIGHPASS
clear all;
close all;
clc;
fs=750;
fp=250;
fsamp=5000;
wp=(2*pi*(fp/fsamp))
ws=(2*pi*(fs/fsamp))
ap=5
as=20
a=log(ws/wp);
b=sqrt((10^(0.1*as))-1);
c=sqrt((10^(0.1*ap))-1);
N=((log(b/c))/a);
N=ceil(N);
wc=(1/2)*((wp/(c^(1/N)))+((ws/(c^(1/N)))));
BUTTERWORTH LOWPASS
fp=250;
fs=750;
fsam=5000;
as=20;
ap=5;
wp=2*pi*(fp/fsam);
ws=2*pi*(fs/fsam);
a=sqrt((10^(0.1*as))-1);
b=sqrt((10^(0.1*ap))-1);
x=log(a/b);
y=log(ws/wp);
N= x/y;
N=ceil(N);
wc=(0.5)*((wp/a^(1/N))+(ws/b^(1/N)));
w=0:0.1:pi
hz=freqz(n1,d1,w);
hzmag=abs(hz);
plot(w/pi, hzmag);
grid on
BUTTERWORTH BANDPASS
fp=250;
fs=750;
fsam=5000;
as=20;
ap=5;
wp=2*pi*(fp/fsam);
ws=2*pi*(fs/fsam);
w=0:0.1:pi
hz=freqz(n1,d1,w);
hzmag=abs(hz);
plot(w/pi, hzmag);
grid on
BUTTERWORTH BANDSTOP
fp=250;
fs=750;
fsam=5000;
as=20;
ap=5;
wp=2*pi*(fp/fsam);
ws=2*pi*(fs/fsam);
w=0:0.1:pi
hz=freqz(n1,d1,w);
hzmag=abs(hz);
plot(w/pi, hzmag);
grid on
OUTPUT:
HIGHPASS FILTER
BANDSTOP FILTER
BANDPASS FILTER
LOWPASS FILTER
CHEBYSHEV BANDSTOP
clear all;
close all;
clc;
fs=750;
fp=250;
fsamp=5000;
wp=(2*pi*(fp/fsamp))
ws=(2*pi*(fs/fsamp))
ap=5
as=20
a=acosh(ws/wp);
b=sqrt((10^(0.1*as))-1);
c=sqrt((10^(0.1*ap))-1);
N=acosh(b/c);
N=ceil(N);
CHEBYSHEV BANDPASS
clear all;
close all;
clc;
fs=750;
fp=250;
fsamp=5000;
wp=(2*pi*(fp/fsamp))
ws=(2*pi*(fs/fsamp))
ap=5
as=20
a=acosh(ws/wp);
b=sqrt((10^(0.1*as))-1);
c=sqrt((10^(0.1*ap))-1);
N=acosh(b/c);
N=ceil(N);
CHEBYSHEV LOWPASS
clear all;
close all;
clc;
fs=750;
fp=250;
fsamp=5000;
wp=(2*pi*(fp/fsamp))
ws=(2*pi*(fs/fsamp))
ap=5
as=20
a=acosh(ws/wp);
b=sqrt((10^(0.1*as))-1);
c=sqrt((10^(0.1*ap))-1);
N=acosh(b/c);
N=ceil(N);
OUTPUT:
BANDPASS FILTER
BANDSTOP FILTER
LOWPASS FILTER
HIGHPASS FILTER
Experiment No: 7
Date:
FIR FILTERS
PROGRAM:
LOWPASS USING RECTANGULAR
clc;
clear all;
close all;
N=input('enter the order');
wc=input('enter the cutt off frequency');
a=(N-1)/2;
for n=1:N
if(n-1==a)
hd(n)=(wc/pi);
else
hd(n)=(sin(wc*(n-1-a)))/(%pi*(n-1-a));
end
w(n)=1;
h(n)=hd(n).*w(n);
end
w1=0:0.01:pi;
[m,ph]=freqz(h,1,w1);
mag=abs(m);
magdb=20*log(mag);
subplot(2,1,1);
plot(ph/pi,magdb);
title(' low pass filter')
[m,ph]=freqz(h,1,256);
mag=abs(m)
magdb=20*log10(mag);
plot(ph/pi,magdb);
title('band pass filter')
a=(N-1)/2;
for n=1:N
if(n-1==a)
hd(n)=1-(wc/pi);
else
hd(n)=((sin(pi*(n-1-a)))-sin(wc*(n-1-a)))/(pi*(n-1-a));
end
w(n)=1;
%w(n)=0.42+0.5*cos((2*pi*(n-1))/(N-1))+0.08*cos((4*pi*(n-1))/(N-1));
h(n)=hd(n).*w(n);
end
w1=0:0.01:%pi;
[m,ph]=freqz(h,1,w1);
mag=abs(m);
magdb=20*log(mag);
subplot(2,1,1);
plot(ph/pi,magdb);
title('band pass filter')
a=(N-1)/2;
for n=1:N
if(n-1==a)
hd(n)=1-(wc2-wc1)/pi;
else
hd(n)=((sin(wc1*(n-1-a)))-sin(wc2*(n-1-a))+sin(%pi*(n-1-a)))/(pi*(n-1-a));
end
w(n)=0.5+0.5*cos((2*pi*(n-1))/(N-1));
h(n)=hd(n).*w(n);
end
w1=0:0.01:pi;
[m,ph]=freqz(h,1,w1);
mag=abs(m);
magdb=20*log(mag);
subplot(2,1,1);
plot(ph/pi,magdb);
title('band stop filter')
OUTPUT:
LOWPASS USING RECTANGULAR
Experiment No: 8
Date:
Generation of Signals
Using TMS 320c 6713
Kit
PROGRAM:
Experiment No: 9
Date:
Implementation of FIR
Filter using TMS320C6713
PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
intn,N,c;
float wr[64],wt[64];
void main()
{
printf("\n enter no. of samples,N= :");
scanf("%d",&N);
}
}
Output
Implementation of IIR Filter
using TMS3206713 Kit
Experiment No: 10
Date:
PROGRAM:
//iirfilters
#include<stdio.h>
#include<math.h>
inti,w,wc,c,N;
float H[100];
floatmul(float, int);
void main()
{
printf("\n enter order of filter ");
scanf("%d",&N);
printf("\n enter the cutoff freq ");
scanf("%d",&wc);
printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");
scanf("%d",&c);
switch(c)
{
case 1:
for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
case 2:
for(w=0;w<=100;w++)
{
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
}
}
floatmul(float a,int x)
{
for(i=0;i<x-1;i++)
a*=a;
return(a);
}
Experiment No: 11 Implementation of Basic
Date:
Arithmetic and Logical
Operations Using TMS 5416 Kit
PROGRAM:
ADDITION
;starting address: 1000
;input address: 1500
;output address
.include "5416_iv.asm"
.def start
.data
.word 0003h,0006h
.text
start STM #1500h,AR1 ;FIRST INPUT ADDRESS
STM #1501h,AR2 ;SECOND INPUT ADDRESS
STM #1600h,AR3 ;OUTPUT ADDRESS
LD *AR1,A
LD *AR2,B
ADD A,0,B
STL B,*AR3 ;STORING THE OUTPUT AT THE ADDRESS POINTED BY AR3, WHICH IS
1600 HERE.
WAIT B WAIT
SUBTRACTION
.include "5416_iv.asm"
.def start
.data
.word 0008h,0004h
.text
start STM #1500h,AR1
STM #1501h,AR2
STM #1600h,AR3
LD *AR1,A
LD *AR2,B
SUB A,0,B
STL B,*AR3
wait nop
nop
b wait
MULTIPLICATION
.include "5416_IV.asm"
.def start
.data
.word 0010h,0002h
.text
start
STM #1500h,AR3
STM #1501h,AR5
STM #2000h,AR2
MPY *AR3,*AR5,B
STL B,*AR2
WAIT B WAIT
SHIFTING
.include "5416_IV.asm"
.def start
.data
.word 0004h,0002h
.text
start STM #1500h,AR3
STM #1501h,AR5
STM #3000h,AR4
STM #3001h,AR6
LD *AR3,0,A
SFTA A,-1
STL A,*AR4
LD *AR5,0,B
SFTA B,1
STL B,*AR6
WAIT B WAIT
CIRCULAR BUFFER
.include "5416_IV.asm"
.def start
.data
.word 1,2,3,4,5
.text
start STM #1500h,AR5
STM #2000h,AR6
STM #4h,BK
STM #20h,BRC
RPTB L1
LD *AR5+%,A
STL A,*AR6+
L1 NOP
WAIT B WAIT
BIT REVERSAL
.include "5416_iv.asm"
.def start
.data
.word 0,1,2,3,4,5,6,7
.text
start LD #0004h,A
STLM A,AR0
STM #1500h,AR1
NOP
NOP
RPT #07h
MVDK *AR1+0B,#3000h
NOP
wait b wait
OUTPUT:
Arithmetic Operations:
Addition:
Address Data
Subtraction:
Address Data
Multiplication:
Address Data
Logical Operations:
Bit Reversal:
Input: 0 1 2 3 4 5 6 7
0000 0001 0010 0011 0100 0101 0110 0111
Output:
Circular Buffer:
1500: 0001 0002 0003 0004 0005
2000:0001 0002 0003 0004 0001 0002 0003 0004
Shifting:
UPSAMPLING
#include<stdio.h>
#include<math.h>
float out1[100], out2[256];
float amp=56,freq=50;
float fs=1200, t=0.0;
inti,j,k,L;
void main()
{
L=100;
k=2;
for(i=0;i<=L;i++)
{
out1[i]=amp*sin(2*3.14*freq*t);
t=t+(1/fs);
}
for(i=0;i<=(k*L);i++)
{
out2[i]=0;
}
i=0;
for(j=0;j<=(k*L);j=k+j)
{
out2[j]=out1[i];
i++;
}
}
DOWN SAMPLING
#include<stdio.h>
#include<math.h>
float s1[100],s2[50];
float amp=50,freq=50;
floatfs=1200;
float t=0.0;
inti,j,L,k=2;
void main()
{
L=100;
for(i=0;i<=100;i++)
{
s1[i]=amp*sin(2*3.14*freq*t);
t=t+(1/fs);
}
for(i=0;i<=(L/k);i++)
{
s2[i]=0;
}
i=0;
for(j=0;j<=(L/k);j=j+k)
{
s2[i]=s1[j];
i++;
printf("down Sampled Length: %f\n",s2[i]);
}
}
UPSAMPLING
DOWNSAMPLING
ADDITIONAL EXPERIMENTS
Experiment No: 13 1-D Signal Analysis –
Date:
Speech and ECG Signal
PROGRAM
clc;
clear all;
close all;
a=load('ecg.dat');
figure(1),plot(a)
h=[1 1 1 1 1];
z=conv(a,h,'same');
figure(2),plot(z);
h1=[1 2 4 2 1];
z1=conv(a,h1,'same');
figure(3),plot(z1);