DSP Lab Manual
DSP Lab Manual
DSP Lab Manual
1
2
X (e
)e j n d , Which
h[n]
X(n)
y[ n ]
y(n)
h [ n ]x [ n k ]
Therefore
MLRIT/ ECE
h(n)e
j n
j
j
e e
(2 cos )e j
the magnitude and phase functions of this filter are
H (e j ) 2 cos ,
( ) .
In order to stop the low-frequency component from appearing at the output of the filter, the
magnitude function at 0.1 should be equal to zero .similarly ,to pass the high-frequency
component without any attenuation, we need to ensure that the magnitude function at 0.4 is
equal to 1. Thus, the two conditions that must be satisfied are
2 cos(0.1) 0 ,
2 cos(0.4) 1
Solving the above equations, we arrive at
6.76195, 13.456335
There fore we can get the input-output relation of the desired FIR filter as
2|Page
MLRIT/ ECE
PROGRAM:
% Set up the filter coefficients
b = [-6.76195 13.456335 -6.76195];
% Set initial conditions to zero values
zi = [0 0];
% Generate the two sinusoidal sequences
n = 0:99;
x1=cos(0.1*n);
x2=cos(0.4*n);
% Generate the filter output sequence
y=filter(b, 1, x1+x2, zi);
% Plot the input and output sequences
subplot(1,1,1);
plot(n,y,r,n,x2,b,n,x1,g);
grid;
axis ([0 100 -1.2 4]);
ylabel(Amplitude); xlabel(Time index, n);
legend(r-,y[n],b,x2[n],g-.,x1[n])
OUTPUT WAVEFORM:
3|Page
MLRIT/ ECE
MLRIT/ ECE
OUTPUT WAVEFORMS:
%MATLAB program to determine IDFT of the sequence and plot magnitude and phase response
clf;
xk=input('enter the input sequence:');
N=length(xk);
%Computation of TWIDDLE FACTORS
for n=0:1:N-1;
for k=0:1:N-1
p=exp(1i*2*pi*n*k/N);
x(k+1,n+1)=p;
end
end
xn=(xk*x)/N;
5|Page
MLRIT/ ECE
magxn=abs(xn);
n=0:N-1;
subplot(2,1,1);
stem(n,magxn);
grid;
title('MAGNITUDE RESPONSE');
xlabel('time index, k');
ylabel('Magnitude in dB');
angxn=angle(xn);
subplot(2,1,2);
stem(n,angxn);
grid;
title('PHASE RESPONSE');
xlabel('time index, k');
ylabel('Phase angle in radians');
disp(xn);
INPUTS:
enter the input sequence:[4 1+i 0 1-i 0 1+i 0 1-i]
OUTPUT WAVEFORMS:
6|Page
MLRIT/ ECE
Q1.Would the result is affected if an arbitrary number of zeros were appended to the original
sequence prior to convolution?
7|Page
MLRIT/ ECE
Exp.No:3
Frequency Response
AIM:
To Write a Matlab program to plot the frequency response (magnitude and phase
1
1
response) of a given difference equation as a below y (n) y (n 1) y (n 2) x(n) .
6
6
.
TOOL:
MATLAB Software 9.0
PROGRAM:
%MATLAB program to plot the frequency response (magnitude and phase response)
%of a given difference equation.
clf;
clear all;
b=input('Enter the numerator coefficients:');
a=input('Enter the denominator coefficients:');
[h,ph]=freqz(b,a);
subplot(2,1,1);
plot(ph/pi,abs(h));
grid;
xlabel('Normalised Frequency');
ylabel('Magnitude in dB');
title('Magnitude Response');
subplot(2,1,2);
plot(ph/pi,angle(h));
grid;
xlabel('Normalised Frequency');
ylabel('phase in radians');
title('Phase Response');
INPUTS:
Enter the numerator coefficients: [1]
Enter the denominator coefficients: [1 -1/6 -1/6]
8|Page
MLRIT/ ECE
OUTPUT WAVEFORMS:
Q1.Determine the dc gain and half-power bandwidth from the magnitude plot.
Q2. Determine the frequency response of an LTI system?
9|Page
MLRIT/ ECE
INPUT:
Enter the input sequence:[1 1 1 1 0 0 0 0]
10 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORMS:
11 | P a g e
MLRIT/ ECE
Power Spectrum
AIM:
To obtain power spectrum of given signal using MATLAB.
TOOL:
MATLAB Software 9.0
PROGRAM:
%Power spectral density
t = 0:0.001:0.6;
x =sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
subplot(2,1,1);
plot(1000*t(1:50),y(1:50));
grid;
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
ylabel('amplitude')
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various frequencies, is:
Pyy = Y.* conj(Y) / 512; f = 1000*(0:256)/512;
subplot(2,1,2);
plot(f,Pyy(1:257));
grid;
title('Frequency content of y');
xlabel('frequency (Hz)');
ylabel('amplitude')
12 | P a g e
MLRIT/ ECE
OUTPUT WAVFORMS:
13 | P a g e
MLRIT/ ECE
PROGRAM:
%MATLAB program of FIR Low pass filter using Hanning
%Hamming, Blackman and Kaiser window
clf;
wc=.5*pi;
N=25;
w=0:0.1:pi;
b=fir1(N,wc/pi,blackman(N+1));
h=freqz(b,1,w);
subplot(3,2,1)
plot(w/pi,abs(h))
grid;xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING BLACKMAN WINDOW')
b=fir1(N,wc/pi,hamming(N+1));
h=freqz(b,1,w);
subplot(3,2,2)
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING HAMMING WINDOW')
b=fir1(N,wc/pi,hanning(N+1));
h=freqz(b,1,w);
subplot(3,2,3)
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING HANNING WINDOW')
b=fir1(N,wc/pi,kaiser(N+1,3.5));
h=freqz(b,1,w);
subplot(3,2,4)
14 | P a g e
MLRIT/ ECE
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING KAISER WINDOW')
OUTPUT WAVEFORMS:
Q1.Indicate what frequencies you would consider as low frequencies. Does this system
approximate a low pass or band pass etc. filter?
Q2.What is the 3db bandwidth?
15 | P a g e
MLRIT/ ECE
PROGRAM:
%FIR Filter design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
beta=input('enter 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
c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');
if(c==1) y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2) y=triang(n1);
disp('Triangular window filter response');
end
if(c==3) y=kaiser(n1,beta);
disp('kaiser window filter response');
end
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
16 | P a g e
MLRIT/ ECE
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
INPUT:
enter passband ripple:0.02
enter the stopband ripple:0.01
enter passband freq:1000
enter stopband freq:1500
enter sampling freq: 10000
enter beta value:5
OUTPUT WAVEFORM:
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
2
Triangular window filter response
17 | P a g e
MLRIT/ ECE
18 | P a g e
MLRIT/ ECE
Q1.What is meant by Gibbs phenomenon? Where we found such type of effects in FIR filters?
Q2. Compare the window techniques from above figure?
19 | P a g e
MLRIT/ ECE
EXP.NO:8
PROGRAM:
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
fp=input('enter passband frequency in hz='); % passband frequency in hz
fs=input('enter stopband frequency in hz='); % stopband frequency in hz
F=input('enter sampling frequency in hz='); % sampling frequency in hz
omp=2*fp/F; %frequency in radians
oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');
disp(b);
disp(a);
20 | P a g e
MLRIT/ ECE
INPUTS:
enter pass attenuation in db=.4
enter stopband attenuation in db=30
enter passband frequency in hz=400
enter stopband frequency in hz=800
enter sampling frequency in hz=2000
OUTPUT WAVEFORM:
21 | P a g e
MLRIT/ ECE
(b) To Design a Butterworth Band stop filter for the given specifications using Matlab.
%To design a Butterworth Band stop filter for the given specifications
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
wp=[.1*pi .5*pi]; % passband frequency in rad
ws=[.2*pi .4*pi]; % stopband frequency in rad
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn,'stop');
w=0.1:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
enter pass attenuation in db=2
enter stopband attenuation in db=20
22 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORMS:
Q. On an approximate basis verify if the output amplitudes of the 2 and 75Hz components agree
with the gain figures.
23 | P a g e
MLRIT/ ECE
(c) To Design a Chebyshev-I low pass filter for the given specifications using Matlab.
% To design a chebyshev-1 Lowpass filter for the given specifications
clf;
aphap=input('passband attenuation in db='); %passband attenuation in db
alphas=input('stopband attenuation in db=');% stopband attenuation in db
wp=.2*pi;% passband frequency in rad
ws=.3*pi;% stopband frequency in rad
%order and cutoff frequency of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=cheby1(n,alphap,wn);
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
% [b,a]=cheby1(n,alphap,wn)
disp(b);
disp(a);
INPUTS:
passband attenuation in db=1
stopband attenuation in db=15
24 | P a g e
MLRIT/ ECE
25 | P a g e
MLRIT/ ECE
TOOL:
MATLAB Software 9.0
PROGRAM:
a) To Design a Butterworth High pass filter for the given specifications using Matlab.
%To design a Butterworth Highpass filter for the given specifications
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
fp=input('enter passband frequency in hz='); % passband frequency in hz
fs=input('enter stopband frequency in hz='); % stopband frequency in hz
F=input('enter sampling frequency in hz='); % sampling frequency in hz
omp=2*fp/F; %frequency in radians
oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');
disp(b);
26 | P a g e
MLRIT/ ECE
disp(a);
INPUTS:
enter pass attenuation in db=.4
enter stopband attenuation in db=30
enter passband frequency in hz=800
enter stopband frequency in hz=400
enter sampling frequency in hz=2000
OUTPUT WAVEFORMS:
Q1.indicate what frequencies you would consider as low frequencies. Does this system
approximate a low or band pass etc. filter?
Q2. Indicate if the phase is linear or nonlinear?
27 | P a g e
MLRIT/ ECE
b) To Design a Butterworth Band pass filter for the given specifications using Matlab.
%To design a Butterworth Band pass filter for the given specifications
clf;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
wp=[.2*pi .4*pi]; % passband frequency in rad
ws=[.1*pi .5*pi]; % stopband frequency in rad
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn);
w=0.1:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
enter pass attenuation in db=2
enter stopband attenuation in db=20
28 | P a g e
MLRIT/ ECE
B=0.0060
0 -0.0240
0 0.0359
0 -0.0240
0 0.0060
A=1.0000 -3.8710 7.9699 -10.6417 10.0781 -6.8167 3.2579 -1.0044 0.1670
Q1.indicate what frequencies you would consider as low frequencies. Does this system
approximate a low or band pass etc. filter?
Q2. Indicate if the phase is linear or nonlinear?
29 | P a g e
MLRIT/ ECE
(c) To Design a Chebyshev-I High pass filter for the given specifications using Matlab.
% To design a chebyshev-1 Hihpass filter for the given specifications
clf;
aphap=input('passband attenuation in db='); %passband attenuation in db
alphas=input('stopband attenuation in db=')% stopband attenuation in db
wp=.3*pi;% passband frequency in rad
ws=.2*pi;% stopband frequency in rad
%order and cutoff frequency of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=cheby1(n,alphap,wn,'high');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
passband attenuation in db=1
stopband attenuation in db=15
30 | P a g e
MLRIT/ ECE
31 | P a g e
MLRIT/ ECE
TOOL:
MATLAB Software 9.0
PROGRAM:
% Write a MATLAB program of signal through by filter
R=50;
d=rand(R,1)-0.5;
m=0:1:R-1;
s=10*sin(2*50*m);
x=s+d';
subplot(1,2,1);
plot(m,d,'r-',m,s,'b--',m,x,'g:');
xlabel('time ');
ylabel('amplitude');
title('input signal with radom noise')
legend('r-','d[n]','b--','s[n]','g:','x[n]');
pause
M=input('number of samples=');
b=ones(M,1)/M;
y=filter(b,1,x);
subplot(1,2,2);
plot(m,s,'r-',m,y,'b--');
legend('r-','s[n]','b--','y[n]');
pause
xlabel('time ');
ylabel('amplitude');
title('input signal through filtering')
INPUT:
No.of.samples:3
32 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORMS:
33 | P a g e
MLRIT/ ECE
About DTMF:
PROGRAM:
close all;clear all
% DTMF tone generator
fs=8000;
t=[0:1:204]/fs;
x=zeros(1,length(t));
x(1)=1;
y852=filter([0 sin(2*pi*852/fs) ],[1 -2*cos(2*pi*852/fs) 1],x);
y1209=filter([0 sin(2*pi*1209/fs) ],[1 -2*cos(2*pi*1209/fs) 1],x);
y7=y852+y1209;
subplot(2,1,1);plot(t,y7);grid
ylabel('y(n) DTMF: number 7');
xlabel('time (second)');
title('signal tone number 7')
Ak=2*abs(fft(y7))/length(y7);Ak(1)=Ak(1)/2;
f=[0:1:(length(y7)-1)/2]*fs/length(y7);
subplot(2,1,2);plot(f,Ak(1:(length(y7)+1)/2));grid
ylabel('Spectrum for y7(n)');
xlabel('frequency (Hz)');
title('absolute value of signal tone number 7')
34 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORM:
35 | P a g e
MLRIT/ ECE
DECIMATION PROCESS
AIM:
To Write a Matlab program for Down-sampling of a sinusoidal input sequence.
TOOL:
MATLAB Software 9.0
The function decimate can be employed to reduce the sampling rate of an input signal vector X
by an integer factor M generating the output signal vector Y and is available with four options:
(i)Y=decimate(X,M) : This function employs an eight-order Type 1 Chebyshev IIR Lowpass
filter by default and filters the input sequence in both directions to ensure zero-phase filtering.
(ii)Y=decimate(X,M,n) : This function utilizes an order-n Type 1 Chebyshev IIR Lowpass filter
where n should be less than 13 to avoid numerical stability.
(iii)Y=decimate(X,M,fir) : This function employs a 30- tap FIR lowpass filter which filters
the input only in the forward direction. The FIR filter is designed with stop edge at /M using the
function fir1 of MATLAB.
(iv)Y=decimate(X,M,N,fir) : This function design and employs a length-N FIR lowpass filter.
PROGRAM:
%MATLAB program of Down-Sampling by an integer factor
clf;
N=input('Enter the length of output sequence=');
M=input('Enter the Down-Sampling factor=');
fo=input('Enter the input signal frequency=');
%Generate the input sinusoidal sequence
n=0:N-1;
m=0:N*M-1;
X=sin(2*pi*fo*m);
%Generate the Down-Sampled sequence
Y=X(1:M:length(X));
%Plot input and Down-Sampled sequences
subplot(2,1,1);
36 | P a g e
MLRIT/ ECE
stem(n,X(1:N));
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
stem(n,Y);
title(' Down-Sampled sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
INPUTS:
Enter the length of output sequence=50
Enter the Down-Sampling factor=3
Enter the input signal frequency=0.042
OUTPUT WAVEFORM:
MLRIT/ ECE
INPUTS:
Enter the length of input sequence=100
Enter the Down-Sampling factor=2
Enter the input signal frequency of first sinusiod=0.043
Enter the input signal frequency of second sinusiod=0.031
38 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORM:
39 | P a g e
MLRIT/ ECE
INTERPOLATION PROCESS
AIM:
To Write a Matlab program for Up-sampling of a sinusoidal input sequence.
TOOL:
MATLAB Software 9.0
MLRIT/ ECE
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
stem(n,Y(1:length(X)));
title(' Up-Sampled sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
INPUTS:
Enter the length of input sequence=50
Enter the Up-Sampling factor=10
Enter the input signal frequency100
OUTPUT WAVEFORMS:
41 | P a g e
MLRIT/ ECE
INPUT:
Enter the length of input sequence=50
Enter the Down-Sampling factor=2
Enter the input signal frequency of first sinusiod=0.043
Enter the input signal frequency of second sinusiod=0.031
42 | P a g e
MLRIT/ ECE
OUTPUTWAVEFORMS:
43 | P a g e
MLRIT/ ECE
TOOL:
MATLAB Software 9.0
PROGRAM:
%MATLAB program of sampling rate alteration by a ratio of two integers
clf;
N=input('Enter the length of input sequence=');
L=input('Enter the Up-Sampling factor=');
M=input('Enter the Down-Sampling factor=');
f1=input('Enter the input signal frequency of first sinusiod');
f2=input('Enter the input signal frequency of second sinusiod');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*f1*n)+sin(2*pi*f2*n);
%Generate the Resampled output sequence
Y = resample(X,L,M);
44 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORMS:
MLRIT/ ECE
46 | P a g e
MLRIT/ ECE
OUTPUT WAVEFORMS:
47 | P a g e
MLRIT/ ECE
(b) . To find the impulse response of second order system by using Matlab.
close all;
clear all;
n=0:10;
b=[1 0 0];
a=[1 -0.6 0.08];
y=dimpulse(b,a,length(n));
subplot(2,2,1);
stem(n,y);
xlabel('t');
ylabel('a');
title('impulse response of second order system');
w=abs(y);
subplot(2,2,2);
stem(n,w);
xlabel('t');
ylabel('a');
title('magnitude response');
x=angle(y);
subplot(2,2,3);
stem(n,x);
xlabel('t');
ylabel('a');
title ('phase response');
OUTPUT WAVEFORMS:
MLRIT/ ECE
LINEAR CONVOLUTION
AIM:
TO write a C- program to find linear convolution of given two sequences.
EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
Procedure to work on code composer studio:
To create the New Project
Project New (File Name. pjt, Eg: Vectors.pjt)
To create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib file & Hello.cmd:
Project Add files to Project rts6700.lib
Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)
Note: Select Object& Library in (*.o,*.l) in Type of files
Project Add files to Projecthello.cmd
CMD file- Which is common for all non real time programs.
(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)
49 | P a g e
MLRIT/ ECE
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]);
}
50 | P a g e
MLRIT/ ECE
RESULTS: Thus the C- Program for Linear convolution was written and the output was
verified.
OUTPUT:
4
10
20
35
56
70
76
73
60
36
51 | P a g e
MLRIT/ ECE
52 | P a g e
MLRIT/ ECE
VIVA QUESTIONS:
1. What is the requirement for the convolution?
2. What is the difference between convolution & Correction?
3. What is meant by Impulse response?
4. Is it possible to represent any discreet time signal in terms of impulses? If yes represent by
using Example?
5. What is the difference between continues & Discrete convolution?
6. Write the expression for LIF System convolution formula & causal LIF system Conv.
Formula?
7. What is the length of linear convolution if lengths of Input & Impulse responses are N1 &
N2 respectively?
53 | P a g e
MLRIT/ ECE
CIRCULAR CONVOLUTION
AIM:
TO write a C- program to find Circular convolution of given two sequences
EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
Procedure to Work on Code Composer Studio:
To create the New Project
Project New (File Name. pjt, Eg: Vectors.pjt)
To create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib file & Hello.cmd:
Project Add files to Project rts6700.lib
Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)
Note: Select Object& Library in (*.o,*.l) in Type of files
Project Add files to Projecthello.cmd
CMD file- Which is common for all non real time programs.
(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)
54 | P a g e
MLRIT/ ECE
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;
55 | P a g e
MLRIT/ ECE
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++)
{
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:
enter the length of the 1st sequence
5
enter the length of the second sequence
5
enter the 1st sequence
1
2
3
4
5
enter the second sequence
56 | P a g e
MLRIT/ ECE
1
2
3
4
5
OUTPUT:
the circular convolution is
45
50
50
45
35
57 | P a g e
MLRIT/ ECE
RESULTS: Thus the C- Program for Circular convolution was written and the output was
verified.
58 | P a g e
MLRIT/ ECE
VIVA QUESTIONS
1. Why we need circular convolution
2. What is the difference between Circular and Linear Convolution
3. What is the length of output Sequence after circular convolution if the lengths of input
impulse responses are M1 and M2 respectively
4. State the circular convolution property of discrete Fourier transformer
5. Where we require convolution property
6. What is zero padding, where we require zero padding concept
7. What is the difference between linear shifting and circular shifting of a signal, show with
example?
8. What is the difference between linear and circular folding of signal show with example.
59 | P a g e
MLRIT/ ECE
EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
Procedure to Work on Code Composer Studio
To create the New Project
Project New (File Name. pjt, Eg: Vectors.pjt)
To create a Source file
File New Type the code (Save & give file name, Eg: sum.c).
To Add Source files to Project
Project Add files to Project sum.c
To Add rts.lib file & Hello.cmd:
Project Add files to Project rts6700.lib
Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib)
Note: Select Object& Library in (*.o,*.l) in Type of files
Project Add files to Projecthello.cmd
CMD file- Which is common for all non real time programs.
(Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd)
Note: Select Linker Command file (*.cmd) in Type of files
60 | P a g e
MLRIT/ ECE
Compile:
To Compile: Project Compile
To Rebuild: project rebuild,
Which will create the final .out executable file. (Eg.Vectors.out).
Procedure to Lode and Run program:
Load the Program to DSK: File Load program Vectors.out
To Execute project: Debug Run
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++)
61 | P a g e
MLRIT/ ECE
{
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;
}
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;
62 | P a g e
MLRIT/ ECE
}
}
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:
the fft of the given input sequence is:
28.000000 0.000000
-4.000012 9.656858
-4.000005 4.000000
-4.000010 1.656851
-4.000000 0.000000
-3.999998 -1.656858
-3.999995 -4.000000
-3.999980 -9.656851
63 | P a g e
MLRIT/ ECE
AIM:
TO write a C- program to compute FFT of the given 1- D signal and plot.
EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
ALGORITHM:
1.
2.
3.
4.
5.
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++)
64 | P a g e
MLRIT/ ECE
{
iobuffer[i]=sin((2*PI*2*i)/32.0);
}
for(i=0;i<N;i++)
{
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]).realtemp2.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++)
65 | P a g e
MLRIT/ ECE
{
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:
66 | P a g e
MLRIT/ ECE
67 | P a g e
MLRIT/ ECE
VIVA QUESTIONS:
1.What is ment by y=[zeros(1,2),ones(1,1) , zeros(1,2) ;?
2.What is meant by subplot(m,n,p)?
3.What do you mean by stem(x,r)?
4.What do you mean by butter(n,wn,'s');
5.What do you mean by grid on?
6.What do you mean by fft?
7.What is difference between dft and fft?
68 | P a g e
MLRIT/ ECE
EQUIPMENT REQUIRED:
System
Power supply
Windows XP
Core 2 Dua l Processor
MATLAB 7.8 VERSION
ALGORITHM:
1.
2.
3.
4.
5.
6.
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;
69 | P a g e
MLRIT/ ECE
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++)
{
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;
70 | P a g e
MLRIT/ ECE
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;
}
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++)
71 | P a g e
MLRIT/ ECE
{
printf("%f\t",y[i]);
}
return(0);
}
OUTPUT:
72 | P a g e
MLRIT/ ECE
73 | P a g e
MLRIT/ ECE
VIVA QUESTIONS:
1. What is the difference between correlation and auto correlation function
2. What is the difference between power spectrum density and energy spectrum density
3. What is the unit for energy density spectrum
4. What is the formula for Power Spectrum Density of a function
5. Same power density spectrum signals always have same magnitude and Phase
spectrum Is this statement is true or False, justify your answer
6. If we know the impulse response of the system how can you find out signal power
density from the input signal
7. What is the unit for power density spectrum
8. What is the relation between auto correlation and Power spectrum density of function
74 | P a g e
MLRIT/ ECE
75 | P a g e