DSP - Anna University

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

Experiment No: 1(a) DISCRETE SIGNAL

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')

t1=-5:0.01:5; %SINE WAVE


a=5
b=a*sin(2*pi*t1);
subplot(3,2,2);
stem(t1,b)
xlabel('time')
ylabel('amplitude')
title('sinewave')

b1=a*cos(2*pi*t1); %COSINE WAVE


subplot(3,2,3);
stem(t1,b1)
xlabel('time')
ylabel('amplitude')
title('cosinewave')

expos1=exp(t1) %EXPONENTIAL SIGNAL


subplot(3,2,4);
stem(t1,expos1);
xlabel('time')
ylabel('amplitude')
title('exponential')
t=-5:5; %RAMP SIGNAL
t2=t>=0
d=t.*t2
subplot(3,2,5);
stem(t,d)
xlabel('time')
ylabel('amplitude')
title('ramp')

t=-5:5; %STEP SIGNAL


e=[zeros(1,5),ones(1,6)]
subplot(3,2,6);
stem(t,e)
xlabel('time')
ylabel('amplitude')
title('step')

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')

t1=-5:0.01:5; %SINE WAVE


a=5
b=a*sin(2*pi*t1);
subplot(3,2,2);
plot(t1,b)
xlabel('time')
ylabel('amplitude')
title('sinewave')

b1=a*cos(2*pi*t1); %COSINE WAVE


subplot(3,2,3);
plot(t1,b1)
xlabel('time')
ylabel('amplitude')
title('cosinewave')

expos1=exp(t1) %EXPONENTIAL SIGNAL


subplot(3,2,4);
plot(t1,expos1);
xlabel('time')
ylabel('amplitude')
title('exponential')
t=-5:5; %RAMP SIGNAL
t2=t>=0
d=t.*t2
subplot(3,2,5);
plot(t,d)
xlabel('time')
ylabel('amplitude')
title('ramp')

t=-5:5; %STEP SIGNAL


e=[zeros(1,5),ones(1,6)]
subplot(3,2,6);
plot(t,e)
xlabel('time')
ylabel('amplitude')
title('step')

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)))));

% Transfer function H(S)


[num den]=butter(N,wc,'high');
hs=tf(num,den);
% Spectrum plot
w=0:.01:pi
hz=freqz(num,den,w);
hzmag=abs(hz);
plot(w/pi,hzmag)
grid on

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)));

[n1 d1]= butter(N, wc, 'low');


hs=tf(n1,d1);

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);

[n1 d1]= butter(N, ws, wp, 'bandpass');


hs=tf(n1,d1);

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);

[n1 d1]= butter(N, ws, wp, 'stop');


hs=tf(n1,d1);

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

Experiment No: 6 IIR FILTERS:


Date:
CHEBYSHEV
PROGRAM:

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);

% Transfer function H(S)


[num den]=cheby2(N,as,[ws,wp],'stop');
hs=tf(num,den);
% Spectrum plot
w=0:.01:pi
hz=freqz(num,den,w);
hzmag=abs(hz);
hzmagdb=20*log(hzmag)
plot(w/pi,hzmagdb)
grid on

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);

% Transfer function H(S)


[num den]=cheby2(N,as,[ws,wp],'bandpass');
hs=tf(num,den);
% Spectrum plot
w=0:.01:pi
hz=freqz(num,den,w);
hzmag=abs(hz);
hzmagdb=20*log(hzmag)
plot(w/pi,hzmagdb)
grid on

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);

% Transfer function H(S)


[num den]=cheby2(N,ap, wp, 'low');
hs=tf(num,den);
% Spectrum plot
w=0:.01:pi
hz=freqz(num,den,w);
hzmag=abs(hz);
hzmagdb=20*log(hzmag)
plot(w/pi,hzmagdb)
grid on
CHEBYSHEV 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=acosh(ws/wp);
b=sqrt((10^(0.1*as))-1);
c=sqrt((10^(0.1*ap))-1);
N=acosh(b/c);
N=ceil(N);

% Transfer function H(S)


[num den]=cheby2(N,ap, wp, 'high');
hs=tf(num,den);
% Spectrum plot
w=0:.01:pi
hz=freqz(num,den,w);
hzmag=abs(hz);
hzmagdb=20*log(hzmag)
plot(w/pi,hzmagdb)
grid on

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')

HIGH PASS FILTER USING BLACKMANN WINDOW


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)=1-(wc/pi);
else
hd(n)=((sin(pi*(n-1-a)))-sin(wc*(n-1-a)))/(pi*(n-1-a));
end
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

[m,ph]=freqz(h,1,256);
mag=abs(m)
magdb=20*log10(mag);

plot(ph/pi,magdb);
title('band pass filter')

BAND PASS FILTER USING HAMMING WINDOW


clear all;
close all;
N=input('enter the order');
wc1=input('enter the cutt off frequency 1');
wc2=input('enter the cutt off frequency 2');

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')

BANDSTOP USING HANNING WINDOW


clear all;
close all;
N=input('enter the order');
wc1=input('enter the cutt off frequency 1');
wc2=input('enter the cutt off frequency 2');

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

HIGH PASS FILTER USING BLACKMANN WINDOW

BAND PASS FILTER USING HAMMING WINDOW


BANDSTOP USING HANNING WINDOW
DSP PROCESSOR
TMS 320C6713
EXPERIMENTS

Experiment No: 8
Date:
Generation of Signals
Using TMS 320c 6713
Kit
PROGRAM:

SINE WAVE GENERATION


#include <stdio.h>
#include <math.h>
int t;
float pi=3.14;
floatf,x[256];
void main()
{
f=8000;
for(t=0; t<=256; t++)
{
x[t]=sin(2*pi*f*t);
printf("%f \n",x[t]);
}
}

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);

printf("\n enter choice of window function\n 1.rect \n 2. triang\nc= :");


scanf("%d",&c);
printf("\n elements of window function are:");
switch(c)
{
case 1:
for(n=0;n<=N-1;n++)
{
wr[n]=1;
printf(" \n wr[%d]=%f",n,wr[n]);
}
break;
case 2:
for(n=0;n<=N-1;n++)
{
wt[n]=1-(2*(float)n/(N-1));
printf("\n wt[%d]=%f",n,wt[n]);
}
break;

}
}
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

Input: 1500 0003


Input: 1501 0006
Output: 1600 0009

Subtraction:
Address Data

Input: 1500 0004


Input: 1501 0008
Output: 1600 0004

Multiplication:
Address Data

Input: 1500 0010


Input: 1501 0002
Output: 1600 0020

Logical Operations:

Bit Reversal:

Input: 0 1 2 3 4 5 6 7
0000 0001 0010 0011 0100 0101 0110 0111
Output:

15000: 0000 0100 0010 0110 0001 0101 0011 0111


0 4 2 6 1 5 3 7

Circular Buffer:
1500: 0001 0002 0003 0004 0005
2000:0001 0002 0003 0004 0001 0002 0003 0004

Shifting:

Input: 1500 0004


Input: 1501 0002
Output: 3000 0002
Experiment No: 12 Implementation of Up-Sampling
Date:
and Down-Sampling

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

ECG signal (Noise Removal)

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);

Speech signal Amplification


clc;
clear all;
close all;
[a,fs]=wavread('female_speech.wav');
subplot(2,1,1)
plot(a);
b=3*a;
subplot(2,1,2)
plot(b);
Noisy ECG Signal

ECG signal filtering using low pass filter

ECG signal filtering using Gaussian function

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy