Sei sulla pagina 1di 63

PROGRAM FOR LOW PASS FILTER

%Program Hamming Window


%Low Pass Filter
clear all;
Fcut = 1000;
Fsamp = 7500;
N = 60; % Order of the filter
d=fdesign.lowpass('N,fc',N,Fcut,Fsamp);
Hd=window(d,'window',@hamming);
fvtool(Hd);

OUTPUT:
Magnitude Response (dB)
0
-10

Magnitude (dB)

-20
-30
-40
-50
-60
-70
-80
0

0.5

1.5

2
Frequency (kHz)

2.5

3.5

PROGRAM FOR HIGH PASS FILTER:


%Program Hamming Window
%High Pass Filter
clear all;
Fcut = 1000;
Fsamp = 7500;
N = 60; % Order of the filter
d= fdesign.highpass('N,fc',N,Fcut,Fsamp)
Hd=window(d,'window',@hamming);
fvtool(Hd);

OUTPUT:
Magnitude Response (dB)
0

Magnitude (dB)

-10
-20
-30
-40
-50
-60
0

0.5

1.5

2
Frequency (kHz)

2.5

3.5

PROGRAM FOR LOW PASS FILTER:


%Program - Butterworth Filter
%Low Pass Filter
rp = 3; % passband ripple
rs = 60; % stopband attenuation
fs = 20000; % sampling frequency
wp = 4200 / 10000;
ws = 5000 / 10000;
[n, wn] = buttord(wp, ws, rp, rs);
[b, a] = butter(n, wn,'low'); % Calculate filter coefficients
fvtool(b, a);

OUTPUT:
Magnitude Response (dB)
0
-50

Magnitude (dB)

-100
-150
-200
-250
-300
-350
-400
0

0.1

0.2

0.3

0.4
0.5
0.6
Normalized Frequency ( rad/sample)

0.7

0.8

0.9

PROGRAM FOR HIGH PASS FILTER:


%Program - Butterworth Filter
%High Pass Filter
rp = 3; % passband ripple
rs = 60; % stopband attenuation
fs = 20000; % sampling frequency
wp = 4200 / 10000;
ws = 5000 / 10000;
[n, wn] = buttord(wp, ws, rp, rs);
[b, a] = butter(n, wn, 'high'); % Calculate filter coefficients
fvtool(b, a);

OUTPUT:
Magnitude Response (dB)
0

Magnitude (dB)

-50

-100

-150

-200

-250
0

0.1

0.2

0.3

0.4
0.5
0.6
Normalized Frequency ( rad/sample)

0.7

0.8

0.9

PROGRAM:
Decimation using TMS320C6745 DSP
Generate sine wave
Initial Command (Closing and Clearing)
clc;
% clears the command window
close all;
% closes all the previously open window
clear all;
% clears previously stored values
Generating Input Sequence
fm = 10;
% input signal frequency
Fs = 140;
% sampling frequency
t = 0:1/Fs:0.5;
% time range for the input sequence
x = sin(2*pi*fm*t); % input sinusoidal signal
figure(1)
subplot(4,1,1)
stem(x);
% Discrete plot of the input sequence,...
... where x-axis corresponds to the number of
samples
xlabel('No. of samples'); % labelling x-axis
ylabel('Amplitude');
% labelling y-axis
title('input discrete sinusoidal sequence'); % giving title to the plot

Decimation of the Input Sequence


M = 2;
% factor by which the input sequence is decimated
xd = decimate(x,M); % resamples the sample in x with a rate (1/M)
times the original rate
subplot(4,1,2)
stem(xd)
% Discrete plot of the input sequence,...
... where x-axis corresponds to the number of samples
xlabel('No. of samples'); % labelling x-axis
ylabel('Amplitude');
% labelling y-axis
title('Decimated Sinusoidal Sequence'); % giving title to the plot

Interolation of the Input Sequence


L = 2;
% factor by which the input sequence is interpolated
xI = interp(x,L); % resamples the sample in x with a rate L times the

original rate
subplot(4,1,3);
stem(xI);
% Discrete plot of the input sequence,...
... where x-axis corresponds to the number of samples
xlabel('No. of samples'); % laeblling x-axis
ylabel('Amplitude');
% labelling y-axis
title('Interpolated Sinuoidal Sequence') % giving title to the plot

Interpolation of the Decimated Signal

L = 2;
% coefficient by which the singal is interpolated
xI = interp(xd,L); % resamples the sample in x with a rate L times the
original rate
subplot(4,1,4)
stem(xI);
% Discrete plot of the input sequence,...
... where x-axis corresponds to the number of samples
xlabel('No. of samples'); % labelling x-axis
ylabel('Amplitude');
% labelling y-axis
title('Original Signal Obtained After Interpolating the Decimated
Signal'); % giving title to the graph

Ex.No.8

Study and comparison of different non-parametric spectral


estimation techniques

AIM:
To study and compare the different non-parametrical spectral estimation
techniques.
TOOL REQUIRED:
PC, MATLAB software
THEORY:
POWER SPECTRUM ESTIMATION (PSE)
There are two purposes for this paper. One purpose is to analyze several
common non-parametric power spectrum estimation (PSE) methods.
Another purpose is to analyze how power spectrum can be used for feature
extraction to detect cancer in an ultrasound image of a prostate. This paper
first analyzes five non-parametric PSE methods. They are: Periodogram
Method, Modified Periodogram Method, Bartletts Method, Welchs
Method, and Blackman-Tukey Method.
The methods are evaluated and compared by four characteristics: spectral
resolution, asymptotic bias, variance, and complexity. The five PSE methods
were implemented in Matlab and were applied to a test ultrasound image.
The resulting estimated power spectrum was linearized. The slope and the yintercept of the linearized power spectrum were used as two feature values.
The mean-squared-error was calculated in order to evaluate the performance
of the five methods for this feature extraction. It was found that this
particular feature extraction does not depend much on the spectral resolution
and the variance of the power spectrum. Consequently, the Periodogram
Method, which has the lowest complexity, is best for this feature extraction.
Lastly, the texture and the overall brightness of the image are reflected on
the slope and the yinterceptof the linearized power spectrum. This paper
proposes a simple but effective approach which uses these two features
jointly to detect the cancerous part of the prostate. There are mainly two
types of power spectrum estimation (PSE) methods: parametric and
nonparametric. In contrast to parametric methods, non-parametric methods
do not make any assumptions on the data-generating process or model (e.g.
autoregressive model). This paper analyzes five common non-parametric

PSE methods. They are: Periodogram Method, Modified Periodogram


Method, Bartletts Method, Welchs Method, and Blackman-Tukey Method.
All these are estimation methods.
This is an average computed over the infinite interval (,) . However, in
image processing, the signal is often of finite length because the size of any
image is finite. Even with a large image, in order to make the assumption of
stationarity, often only a small window of the image is considered at a time.
In this paper, it is assumed that the window is small enough so that the
assumption of
stationary holds, allowing the autocorrelation and the power spectrum to be a
Fourier Transform pair.
1.1 Periodogram
A simple-minded method of estimating the autocorrelation of a signal of
finite length is called the Periodogram Method. This estimation method
assumes the observed signal x (n) N is a truncated version of the originally
intended signal x(n).
The spectral resolution can be defined by the frequency at which the power
of the low pass filter drops to half of the total power. Since 20 log( 0.5) 3 ,
the spectral resolution is equivalent to the 3dB bandwidth of low pass filter.
The spectral resolution measures the amount of blurring effect on the ideal
power spectrum. In general, the larger the bandwidth of the main lobe, the
higher spectra resolution is, and the more blurring effect the low pass filter
has.
3dB Res P(e jw ) w

.
(Note this definition of spectral resolution might be counter-intuitive since
one would normally expect the higher the spectral resolution, the sharper the
spectrum would be.) the exact derivation of this spectral resolution is not
important since the spectral resolutions of all other methods are derived from
this for comparison.

1.2 Modified Periodogram


The Periodogram Method described above assumes that the observed signal
x (n) N is a truncated version of the original intended signal x(n) , with a
rectangular truncation window: The Modified Periodogram generalizes the
truncation window. By choosing a different truncation window, the width of
the main lobe and the amplitudes of the side lobes of the low pass filtered
can
be varied. On one hand, the width of main lobe determines the spectral
resolution. The larger the width of the main lobe, the more blurring effect
the low pass filter has on the power spectrum. On the other hand, the

amplitudes of the side lobes determine the spectral masking effect. The
higher
the amplitudes of the side lobes, the more masking effect of the power
spectrum at a given frequency has on the nearby frequencies.
Table 1 shows several common truncation windows which are defined over
the finite interval
0 n
N
1, there is a trade-off between the width of the main lobe and the
amplitudes of the side lobe. Although the Rectangular Window provides the
best spectral resolution with the narrowest 3dB bandwidth for the main lobe,
it also gives the worst spectral masking effect.
By changing the truncation window, the spectral resolution is sacrificed for a
smaller spectral masking effect. The spectral resolution of the Modified
Periodogram Method depends of the truncation window.
The resolutions for the five windows are shown in Table 1. The spectral
resolution is in the form:
pW e j converges to an
impulse as N , the desirable condition
lim ( jw )( jw )
N Modified
1.3 Bartletts Method
Both the Periodogram Method and Modified Periodogram Method do not
give zero variances as the data length approaches infinity. One way to
enforce zero variance is by averaging. The Bartletts Method divides the
signal of length N into K segments, with each segment having length
L N
/K . The Periodogram Method is then applied to each of the K
segments. The average of the resulting estimated power spectra is taken as
the estimated power spectrum of the Bartletts Thus, as K , the variance
( jw )
Bartlett Var P e approaches zero. In summary, the value of K can be used to
design the trade-off between spectral resolution and
variance. With a larger number of segments, the variance is reduced but at
the expense of spectral resolution. Conversely, with a smaller number of
segments, the spectral resolution (i.e. the
bandwidth of the main lobe) is reduced at expense of larger variance.
The complexity can be analyzed by inspecting the loop structure of the
implementation. The Bartletts Method can be implemented as follows:
3) Estimate the power spectra of the K segments using the Periodogram
Method. Since the Periodogram Method is an O(n2 ) operation (as described
in Section 1.1.4) and is repeated K times, the complexity of this step is n
O(n2 ) O(n3

).

4) Compute the average of the estimates of all the segments which is an O(n)
operation.Thus, the overall complexity of the Bartletts Method is O(n3 )
O(n) O(n3

).
1.4 Welchs Method
The Welchs Method eliminates the trade off between spectral resolution and
variance in the Bartletts Method by allowing the segments to overlap.
Furthermore, the truncation window can also vary. Essentially, the Modified
Periodogram Method (instead of the Periodogram Method) is
applied to each of the overlapping segments. Mathematically, the estimated
power spectrum K is the number of segments, L is the length of each
segment, n
Each of the K segments is simply the Modified Periodogram estimate which
is asymptotically unbiased. Consequently, the estimated power spectrum (
jw )
Welch P e , which is the average of the Periodogram estimates of the K
segments, is also asymptotically unbiased. The variance of the estimated
power spectrum ( jw ) Welch P e is more difficult to compute since there is
correlation between overlapping segments. However, it is shown in [1] that
with 50% overlap
( D L 2 1 ), the variance of the estimated power spectrum ( jw )
Welch P e is about Thus, as N , the variance ( jw )
Bartlett Var P e approaches zero.
In summary, the length of each segment, L N
D(K 1) , can be used to
improve both the spectral resolution and the variance. By allowing more
overlapping (larger D), more segments (larger K) or longer segments (larger
L ) can be obtained to improve both the spectral resolution and the variance.
However, overlapping introduces correlations between segments. In practice,
the
amount of overlapping is typically between 50% to 75% [1].
The complexity can be analyzed by inspecting the loop structure of the
implementation. The
Welchs Method can be implemented as follows:
1) Estimate the power spectra of the K segments using the Modified
Periodogram Method. Since the Modified Periodogram Method is an O(n2 )
operation (as described in Section 1.2) and is repeated K times, the
complexity of this step is n O(n2 ) O(n3

).
2) Compute the average of the estimates of all the segments which is an O(n)
operation. Thus, the overall complexity of the Welchs Method is O(n3 )
O(n) O(n3

).

Comparison of PSE Methods


There were 73 cancerous ROIs and 520 benign ROIs in the test image. Each
ROI was onedimensional and was 19 pixels long. The 73+520=593 ROIs
were mapped to 593 feature values using the Periodogram Method. The
feature values were normalized to the interval (0,1). The median feature
value of the feature values of each class of each feature was used as the
expected feature value for the class.
With the expected feature values, the mean-squared-error (MSE) can be
calculated for the different PSE methods. The MSE of each method for each
feature was calculated as a weighted average of the MSE of the two classes,
so that the MSE of cancerous class (i.e. undetected cancer) and the MSE of
the benign class (i.e. false alarm) contribute to the overall MSE equally. In
other words,
although the cancerous part is normally only a small part of the prostate, the
error of undetected cancer and the error of false alarm have the same impact
to the overall MSE.

RESULT
Thus we have studied and compared the different non-parametric spectral
estimation techniques using MATLAB.

EX.NO:1

STUDY OF ALISING EFFECTS AND

QUANTISATION EFFECTS

AIM:
To study the effects of aliasing and quantization.
THEORY:
Aliasing arises when a signal is discretely sampled at a rate that is
insufficient to capture the changes in the signal. Consider the following
contexts in which signals are discretely sampled:
Retinal images are sampled in space by photoreceptors.
Film and video are sampled in time by discrete frames.
Sound is commonly digitally sampled for recording and
communications.Aliasing may arise in all of these situations if sampling is
done improperly. Because the e_ects of aliasing can be rather disastrous, it is
important to understand why aliasing occurs, what its consequences are, and
how it may be avoided.
Nyquist sampling theoremThe Nyquist sampling theorem provides a
prescription for the nominal sampling in-terval required to avoid aliasing. It
may be stated simply as follows:
That this is so is really quite intuitive. Consider for example a signal
composed of a single sinewave at a frequency of 1 Hz:
If we sample this waveform at 2 Hz (as dictated by the Nyquist theorem),
that is su_cient to capture each peak and trough of the signal:If we sample at
a frequency higher than this, for example 3 Hz, then there are more than
enough samples to capture the variations in the signal:If however we sample
at a frequency lower than 2 Hz, for example at 1.5 Hz, then there are now
not enough samples to capture all the peaks and troughs in the signal:
Note here that we are not only losing information, but we are getting the
wrong infor-mation about the signal. The person receiving these samples,
without any previous knowledge of the original signal, may well be mislead
into thinking that the signal has quite a different form:
2 Effects of aliasing
2.1The wagon wheel effect
One common situation in which aliasing occurs is in _lm. This is because
continuously varying images are being discretely sampled at a rate of 24
frames/sec. The Nyquist sampling theorem tells us that aliasing will occur if

at any point in the image plane there are frequency components, or lightdark transitions, that occur faster than fs=2, which in this case is 12
frames/sec. But in many situations the light-dark transitions may be
occurring faster than this such as a wagon wheel or propeller rotating at high
speed.
Quantization
First, a bit of trivia. As you know, it is a digital computer, not a digit
computer. The information processed is called digital data, not digit data.
Why then, is analog-to-digital conversion generally called: digitize and
digitization, rather than digitalize and digitalization? The answer is nothing
you would expect. When electronics got around to inventing digital
techniques, the preferred names had already been snatched up by the medical
community nearly a century before. Digitalize and digitalization mean to
administer the heart stimulant digitalis.Notice that we carefully avoid
comparing (a) and (c), as this would lump the sampling and quantization
together. It is important that we analyze them separately because they
degrade the signal in different ways, as well as being controlled by different
parameters in the electronics. There are also cases where one is used without
the other. For instance, sampling without quantization is used in switched
capacitor filters.

RESULT:

Thus we have studied the effects of aliasing and quantization.


EX.NO:2 STUDY OF ADDRESSING MODES USING TMS320C6745

Aim
To Study the various addressing mode of TMS320C6745 DSP
processor.
Addressing Modes
The addressing modes in TMS320C6745
1.
2.
3.
4.

Register addressing mode


Memory mapped addressing mode
Linear addressing mode
Circular addressing mode
Register Addressing Mode:
The register addressing mode uses operands in CPU
register either explicity, such as with a direct reference to a
specific

register,

or

implicity,

with

instruction

that

intrinsically refers certain registers. That is in this addressing


mode the address comes from one of two special purpose
memory mapped register in CPU. The block move address
register (BMAR) and the dynamic bit manipulation register
(DBMR). In either case, operand reference is simplified
because 16 bit value can be used without specifying a full 16
bit operand address or immediate value.

Memory mapped register addressing mode:


Memory mapped register addressing is used to access
efficiently the CPU and on chip peripheral registers. It
operates like the direct addressing except that the upper 9bits of the address that is accessed are assumed to be
0s.This allows us to address the memory mapped registers of
data page 0 directly without the overhead of changing the
DSP or auxiliary register. Only the seven lower bits of the
complete code, including opcode can be represented using a
single 16-bit word.

Linear Addressing Mode


LD and ST Instructions
For load and store instructions, linear mode simply
shifts the offset/cst operand to the left by 3, 2, 1, or 0 for
double word, word, halfword, or byte access, respectively;
and then performs an add or a subtract to baseR (depending
on the operation specified). The LDNDW and STNDW
instructions also support nonscaled offsets. In nonscaled

mode, the offsetR/cst is not shifted before adding or


subtracting from the baseR.
For the preincrement, predecrement, positive offset,
and negative offset address generation options, the result of
the calculation is the address to be accessed in memory. For
postincrement or postdecrement addressing, the value of
baseR before
the addition or subtraction is the address to be
accessed from memory.
ADDA and SUBA Instructions
For integer addition and subtraction instructions, linear
mode simply shifts the src1/cst operand to the left by 3, 2, 1,
or 0 for doubleword, word, halfword, or byte data sizes,
respectively,

and

then

performs

the

add

or

subtract

specified.

Circular Addressing Mode:


The BK0 and BK1 fields in AMR specify the block sizes
for circular addressing
LD and ST Instructions

As with linear address arithmetic, offsetR/cst is shifted


left by 3, 2, 1, or 0 according to the data size, and is then
added to or subtracted from baseR to produce the final
address. Circular addressing modifies this slightly by only
allowing bits N through 0 of the result to be updated, leaving
bits 31 through N + 1 unchanged after address arithmetic.
The resulting address is bounded to 2(N + 1) range,
regardless of the size of the offsetR/cst.The circular buffer
size in AMR is not scaled; for example, a block-size of 8 is 8
bytes, not 8 times the data size (byte, halfword, word). So, to
perform circular addressing on an array of 8 words, a size of
32 should be specified, or N = 4. Example shows an LDW
performed with register A4 in circular mode and BK0 = 4, so
the buffer size is 32 bytes, 16 halfwords, or 8 words. The
value in AMR for this example is 0004 0001h.
ADDA and SUBA Instructions
As with linear address arithmetic, offsetR/cst is shifted
left by 3, 2, 1, or 0 according to the data size, and is then
added to or subtracted from baseR to produce the final
address. Circular addressing modifies this slightly by only
allowing bits N through 0 of the result to be updated, leaving

bits 31 through N + 1 unchanged after address arithmetic.


The resulting address is bounded to 2(N + 1) range,
regardless of the size of the offsetR/cst.
The circular buffer size in AMR is not scaled; for example, a
block size of 8 is 8 bytes, not 8 times the data size (byte,
halfword, word). So, to perform circular addressing on an
array of 8 words, a size of 32 should be specified, or N = 4.
Example shows an ADDAH performed with register A4 in
circular mode and BK0 = 4, so the buffer size is 32 bytes, 16
halfwords, or 8 words. The value in AMR for this example is
0004 0001h.
ASM General Procedure to work C6745:
1. Open Code Composer Studio v4 .
2. In WorkSpace Launcher.
a. BROWSE Select the project location and make one new
folder, MAKE NEW FOLDER Type the Workspace name,
OK OK.
3. FILE NEW CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location.
c. Project type: C6000.

NEXT

d. Tick Debug And Release.

NEXT NEXT.

e. Output type: Executable.


f. Device Variant : generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Tick Treat as an Assembly-only project.
k. Target content: none.

FINISH

4. FILE NEW SOURCE FILE


a. Source file: Type your add.asm( .asm extension is must ).
b. Type the program.
c. FILE SAVE.
5. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder(contains library files)
6. Paste the asm linker file and vectors.asm in the project
location.(asm linker file and vectors.asm is available in cd)
Note: Those folders and linker file are availble at cd.
7. PROJECT PROPERTIES C/C++ BUILD BASIC
OPTION

a. Target processor version(--silicon version, -mv) : 6400+


b. IN C/C++ BUILD, INCLUDE OPTIONS (Add dir to #include
search path(--include_path,-I)) select this add icon

and add

the following three path by indivdually


"${Diag}../../common/header"
"${XDAIS_CG_ROOT}/packages/ti/xdais"
"${C6000_CSL_CG_ROOT}/include"
8. FILE NEW TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745. SAVE TARTGET
CONFIGURATION C674X_0 BROWSE,

browse the

workspace location, open the gel folder and select the GEL
file. OPEN SAVE.
9. In C/C++ Project window, Right click the project REBUILD
PROJECT.
10.

Connections :

a. Connect the usb cable, in between PC to KIT.


b. Connect the 5v adapter and Power on the kit.
11.

TARGET DEBUG ACTIVE PROJECT.(Then see out at

corresponding place after run)

12.

VIEW MEMORY

13.

In right side, memory window will open. Type the output

adrress

0xC0001000

14.

TARGET RUN.

15.

TARGET HALT.
See the Output at Particular location:
0xC0000000 99CE4C0B........

Result:
The study of various addressing modes of TMS320C6745 DSP
processor was verified.
LINEAR CONVOLUTION USING TMS320C6745 DSP
Program
#include<stdio.h>
#definexn 4
#definehn 4
void main()
{
int *x,*h,*y,i,n,k;
x = (int *)0xc0001000;
h = (int *)0xc0001030;
y = (int *)0xc0001050;
for(i=0;i<(xn+hn-1);i++)
{
y[i]=0;
x[xn+i]=0;
h[hn+i]=0;
}
for(n=0;n<(xn+hn-1);n++)
{
for(k=0;k<=n;k++)
y[n] = (y[n]) + ((x[k])*(h[n-k]));
}
while(1);
}

CIRCULAR CONVOLUTION USING TMS320C6745 DSP


Program
#include<stdio.h>
int rot(int *x);
void main()
{
int *in1,*in2,*out,*temp,i,sum=0,j;
in1 = (int *)0xc0001000;
in2 = (int *)0xc0001030;
out = (int *)0xc0001050;
temp = (int *)0xc0002000;
for(i=0;i<4;i++)
{
if(i == 1)
temp[i+2] = in1[i];
elseif(i == 3)
temp[i-2] = in1[i];
else
temp[i] = in1[i];
}
for(i=0;i<4;i++)
{
sum = 0;
for(j=0;j<4;j++)
{
sum+=(in2[j] * temp[j]);
}
out[i] = sum;
rot(temp);
}
while(1);
}
rot(int *x)
{
int t;
t = x[0];
x[0] = x[3];
x[3] = x[2];
x[2] = x[1];
x[1] = t;
}

FFT 8 POINT DIT USING TMW320C6745 DSP

Program
#include <math.h>
#define PI
3.14159
float x[8],t[8],s1[8],s2r[8],s2i[8],Xr[8],Xi[8],Yr[8],Yi[8];
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;
void main()
{
int *Input,*Real_out,*Imag_out;
int i=0,j=0;
Input = (int *)0xC0001000;
Real_out = (int *)0xC0001030;
Imag_out = (int *)0xC0001050;
for(i=0;i<8;i++)
{
t[i] = 0;
t[i] = *(Input + i);
}
// Bit reversal process
x[0] = t[0];
x[1] = t[4];
x[2] = t[2];
x[3] = t[6];
x[4] = t[1];
x[5] = t[5];
x[6] = t[3];
x[7] = t[7];
// stage one process

s1[0] = (int)(x[0] + (x[1] * W0r));


s1[1] = (int)(x[0] - (x[1] * W0r));
s1[2] = (int)(x[2] + (x[3] * W0r));
s1[3] = (int)(x[2] - (x[3] * W0r));
s1[4] = (int)(x[4] + (x[5] * W0r));
s1[5] = (int)(x[4] - (x[5] * W0r));
s1[6] = (int)(x[6] + (x[7] * W0r));
s1[7] = (int)(x[6] - (x[7] * W0r));
// stage two process
s2r[0] = (s1[0] + (s1[2] * W0r));
s2i[0] = 0;
s2r[1] = s1[1];
s2i[1] = (s1[3] * W2i);
s2r[2] = (s1[0] - (s1[2] * W0r));
s2i[2] = 0;
s2r[3] = s1[1];
s2i[3] = - (s1[3] * W2i);
s2r[4] = (s1[4] + (s1[6] * W0r));
s2i[4] = 0;
s2r[5] = s1[5];
s2i[5] = (s1[7] * W2i);
s2r[6] = (s1[4] - (s1[6] * W0r));
s2i[6] = 0;
s2r[7] = s1[5];
s2i[7] = -(s1[7] * W2i);
// output
// complex multiplication for B * Wn
Yr[0] = (s2r[4] * W0r) - (s2i[4] * W0i);
Yi[0] = (s2r[4] * W0i) + (s2i[4] * W0r);
Yr[1] = (s2r[5] * W1r) - (s2i[5] * W1i);
Yi[1] = (s2r[5] * W1i) + (s2i[5] * W1r);

Yr[2] = (s2r[6] * W2r) - (s2i[6] * W2i);


Yi[2] = (s2r[6] * W2i) + (s2i[6] * W2r);
Yr[3] = (s2r[7] * W3r) - (s2i[7] * W3i);
Yi[3] = (s2r[7] * W3i) + (s2i[7] * W3r);
Yr[4] = (s2r[4] * W0r) - (s2i[4] * W0i);
Yi[4] = (s2r[4] * W0i) + (s2i[4] * W0r);
Yr[5] = (s2r[5] * W1r) - (s2i[5] * W1i);
Yi[5] = (s2r[5] * W1i) + (s2i[5] * W1r);
Yr[6] = (s2r[6] * W2r) - (s2i[6] * W2i);
Yi[6] = (s2r[6] * W2i) + (s2i[6] * W2r);
Yr[7] = (s2r[7] * W3r) - (s2i[7] * W3i);
Yi[7] = (s2r[7] * W3i) + (s2i[7] * W3r);
// complex addition for A + BWn
j=0;
for(i=0;i<4;i++)
{
Xr[i] = s2r[j] + Yr[i];
Xi[i] = s2i[j] + Yi[i];
j++;
}
// complex subtraction for A - BWn
j=0;
for(i=4;i<8;i++)
{
Xr[i] = s2r[j] - Yr[i];
Xi[i] = s2i[j] - Yi[i];
j++;
}
// sending output array to memory location
for(i=0;i<8;i++)
{

*Real_out ++= Xr[i];


*Imag_out ++= Xi[i];
}
for(;;);
}

FFT 8 POINT DIF USING TMS320C6745 DSP

Program
#include <math.h>
#define PI
3.14159
float
x[8],tr[8],ti[8],s1r[8],s1i[8],s2r[8],s2i[8],Xr[8],Xi[8],Yr[8],Yi[8]
;
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;

void main()
{
int *Input,*Real_out,*Imag_out;
int i=0;
Input = (int *)0xC0001000;
Real_out = (int *)0xC0001030;
Imag_out = (int *)0xC0001050;
for(i=0;i<8;i++)
{
x[i] = 0;
x[i] = *(Input + i);
}
// stage one process
s1r[0] = (int)(x[0] + x[4]);
s1i[0] = 0;
s1r[1] = (int)(x[1] + x[5]);
s1i[1] = 0;
s1r[2] = (int)(x[2] + x[6]);
s1i[2] = 0;
s1r[3] = (int)(x[3] + x[7]);
s1i[3] = 0;
s1r[4] = (int)(x[0] - x[4]) * W0r;
s1i[4] = 0;
s1r[5] = (int)(x[1] - x[5]) * W1r;
s1i[5] = (int)(x[1] - x[5]) * W1i;
s1r[6] = 0;
s1i[6] = (int)(x[2] - x[6]) * W2i;
s1r[7] = (int)(x[3] - x[7]) * W3r;
s1i[7] = (int)(x[3] - x[7]) * W3i;
// stage two process
s2r[0] = (s1r[0] + s1r[2]);
s2i[0] = (s1i[0] + s1i[2]);
s2r[1] = (s1r[1] + s1r[3]);
s2i[1] = (s1i[1] + s1i[3]);
s2r[2] = (s1r[0] - s1r[2]) * W0r;
s2i[2] = 0; // (s1i[0] - s1i[2]) * W0i;
s2r[3] = 0; // (s1r[1] - s1r[3]) * W2r;
s2i[3] = (s1r[1] - s1r[3]) * W2i;
s2r[4] = (s1r[4] + s1r[6]);

s2i[4] = (s1i[4] + s1i[6]);


s2r[5] = (s1r[5] + s1r[7]);
s2i[5] = (s1i[5] + s1i[7]);
s2r[6] = (s1r[4] - s1r[6]) * 1;
s2i[6] = (s1i[4] - s1i[6]) * 1;
Yr[0] = s1r[5] - s1r[7];
Yi[0] = s1i[5] - s1i[7];
Yr[1] = ((Yr[0] * W2r) - (Yi[0] * W2i));
Yi[1] = ((Yr[0] * W2i) + (Yi[0] * W2r));
s2r[7] = Yr[1];
s2i[7] = Yi[1];
// output
Xr[0] = (s2r[0] + s2r[1]);
Xi[0] = (s2i[0] + s2i[1]);
Xr[1] = (s2r[0] - s2r[1]);
Xi[1] = (s2i[0] - s2i[1]);
Xr[2] = (s2r[2] + s2r[3]);
Xi[2] = (s2i[2] + s2i[3]);
Xr[3] = (s2r[2] - s2r[3]);
Xi[3] = (s2i[2] - s2i[3]);
Xr[4] = (s2r[4] + s2r[5]);
Xi[4] = (s2i[4] + s2i[5]);
Xr[5] = (s2r[4] - s2r[5]);
Xi[5] = (s2i[4] - s2i[5]);
Xr[6] = (s2r[6] + s2r[7]);
Xi[6] = (s2i[6] + s2i[7]);
Xr[7] = (s2r[6] - s2r[7]);
Xi[7] = (s2i[6] - s2i[7]);
// bit reversal
tr[0] = Xr[0];
ti[0] = Xi[0];
tr[1] = Xr[4];
ti[1] = Xi[4];
tr[2] = Xr[2];
ti[2] = Xi[2];
tr[3] = Xr[6];
ti[3] = Xi[6];
tr[4] = Xr[1];
ti[4] = Xi[1];

tr[5] = Xr[5];
ti[5] = Xi[5];
tr[6] = Xr[3];
ti[6] = Xi[3];
tr[7] = Xr[7];
ti[7] = Xi[7];
// sending output array to memory location
for(i=0;i<8;i++)
{
*Real_out ++= tr[i];
*Imag_out ++= ti[i];
}
for(;;);
}
SINE WAVE GENERATION USING TMS320C6745 DSP

Program
#include<stdio.h>
#include<math.h>
#define PI 3.14
void main()
{
const float sampf = 1024000.0;// Sampling frquency is
fixed
const int inpf = 4000; // change the input frquency
from 1khz to
//8khz(1000 to 8000)
float sampt;
double teta;
short value,*sinout;
int i,count,nsamp,value1;
sinout = (short *)0xc0000000;
sampt = 1/sampf;
nsamp = sampf/inpf;
printf("\n
printf("\n
printf("\n
printf("\n

Sampling Frequency is : %f",sampf);


Sampling Time is :%f",sampt);
Input Frequency is : %d",inpf);
The number of Sample is : %d",nsamp);

for(i=0;i<400;i++)

*(sinout+i)=0;
for(count=0;count<nsamp;count++)
{
teta = (2 * PI * inpf * sampt * count);
printf("\nteta = %lf",teta);
sin(t

value=sin(teta)*1024;//Set amplitude by
varying the value //0 to 1024
printf("\t sin %lf Value is : %d",teta,value);
value1 = value&0x0000FFFF;
*sinout++ = value1;
}}
SQUARE WAVE GENERATION USING TMS320C6745 DSP

Program
#include <stdio.h>
#include <math.h>
void main()
{
int *Square;
int i;
Square = (int *)0xC0000000;
while(1)
{
for(i=0;i<50;i++)
{
*Square++ = 0x0000FFFF;
}
for(i=0;i<50;i++)
{
*Square++ = 0x0;
}
}
}

TRIANGLE WAVE GENERATION USING TMS320C6745 DSP KIT

Program
#include <stdio.h>
#include <math.h>
void main()
{
int *Triangle;
int i=0,j=0;
Triangle = (int *)0xC0000000;
while(1)
{
for(i=0;i<50;i++)
{
j=j+1;
*Triangle++ =
}
for(i=50;i>0;i--)
{
j=j-1;
*Triangle++ =
}
}
}

//set frequency value


//set amplitude value
j;

j;

SAWTOOTH GENERATION USING TMS320C6745 DSP KIT

Program
#include <stdio.h>
#include <math.h>
void main()
{
int *Sawtooth;
int i=0,j=0;
Sawtooth = (int *)0xC0000000;
while(1)
{
for(i=0;i<100;i++) //set the frequency value
{
j=j+1;
//set the amplitude value
*Sawtooth++ = j;
}
j=0;
i=0;
*Sawtooth++ = j;
}
}

IIR LOW PASS FILTER USING TMS320C6745 DSP KIT

Program
#include
#include
#include
#include
#include

<stdio.h>
<math.h>
"c6745.h"
"spiadc.h"
"spidac.h"

#define DAC_CS_LOW();
0x0;
//(CS=Low:Enable)
#define DAC_CS_HIGH();
0x1;
//(CS=High:Disable)
#define GAIN 0.03882011771

SPI0_SPIPC3 =
SPI0_SPIPC3 =

void SPI_Write(unsigned short Data);


static float xv[3], yv[3];
int Chebyshev(int input);
//LP co-efficient samp fr=6khz passband fr=400hz
float a0=1,a1=-1.481033206,a2= 0.6363137364;
float b0=1,b1=2,b2=1;

void main( void )


{
static Uint8 spiadcbuf[3];
int adc_value,vout=0;
C6745_init();
spiadc_init();
spidac_init();
while(1)
{
spiadcbuf[0] = 0x01;
command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

// setup

spiadc_cycle(spiadcbuf, 3);
// Execute
spiadc read cycle
adc_value = ((spiadcbuf[1]&0x0f) << 8)|
spiadcbuf[2];
vout = Chebyshev(adc_value);
SPI_Write(vout);
}
}

/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive,j;
DAC_CS_LOW();
Data = ( 0x3000 | Data );
/* Clear any old data */
receive = SPI0_SPIBUF;
// Wait for transmit ready
while( SPI0_SPIBUF & 0x10000000 );
/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);
/* Read 1 byte */
receive = SPI0_SPIBUF;
for(j=0;j<10;j++);
DAC_CS_HIGH();
}
int Chebyshev(int input)
{
int vout=0;
xv[0] = xv[1];

xv[1] = xv[2];
xv[2] = input;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (b0*xv[0] + b2*xv[2]) + b1 * xv[1] - (
a2 * yv[0]) - ( a1 * yv[1]);
vout = yv[2]*GAIN;
return vout;
}

Input:

Output:

IIR HIGH PASS FILTER USING TMS320C6745 DSP

Program:
#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"
#define DAC_CS_LOW();
0x0;
//(CS=Low:Enable)
#define DAC_CS_HIGH();
0x1;
//(CS=High:Disable)
#define DCOFFSET 2711

SPI0_SPIPC3 =
SPI0_SPIPC3 =
//HP

#define GAIN 0.7045881152


void SPI_Write(unsigned short Data);
static float xv[3], yv[3];
int Chebyshev(int input);
//HP co-efficient samp fr=6khz passband fr=600hz
float a0=1,a1=-1.27423811,a2= 0.5441143513;
float b0= 1,b1=-2,b2=1;
void main( void )
{
static Uint8 spiadcbuf[3];
int adc_value,vout=0;
C6745_init();
spiadc_init();
spidac_init();
while(1)
{
spiadcbuf[0] = 0x01;
// setup command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;
spiadc_cycle(spiadcbuf, 3);
// Execute spiadc read cycle
adc_value = ((spiadcbuf[1]&0x0f) << 8)|
spiadcbuf[2];
vout = Chebyshev(adc_value);
vout = vout + DCOFFSET;
if(vout>4095) vout=4095;
SPI_Write(vout);
}
}

/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive,j;
DAC_CS_LOW();
Data = ( 0x3000 | Data );
/* Clear any old data */
receive = SPI0_SPIBUF;
// Wait for transmit ready
while( SPI0_SPIBUF & 0x10000000 );
/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);
/* Read 1 byte */
receive = SPI0_SPIBUF;
for(j=0;j<10;j++);
DAC_CS_HIGH();
}
int Chebyshev(int input)
{
int vout=0;
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = input;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (b0*xv[0] + b2*xv[2]) + b1 *
xv[1] - ( a2 * yv[0]) - ( a1 * yv[1]);
vout = yv[2]*GAIN;
return vout;}

Input

output

FIR LOW PASS FILTER USING TMS320C6745 DSP KIT

Program
#include
#include
#include
#include
#include
#define
0x0;
#define
0x1;

<stdio.h>
<math.h>
"c6745.h"
"spiadc.h"
"spidac.h"
DAC_CS_LOW();
//(CS=Low:Enable)
DAC_CS_HIGH();
//(CS=High:Disable)

SPI0_SPIPC3 =
SPI0_SPIPC3 =

void SPI_Write(unsigned short Data);


unsigned short i,j=0,High,Value=0;
signed int adc_value;
//Low Pass samp fr=6khz sbf=200 pbf=400
float h[51] = {
0.01060591545,
0.004117832519,
0.004079894163,
0.003353076056,
0.001853102469,
-0.0004065925605,-0.003321184311,0.006660183426,
-0.01010407601,
-0.01322921738,
-0.01557052694,
-0.01663137041,
-0.01597031951,
-0.01320868172,0.008123514242,
-0.000646590197,
0.0090885479,
0.02072319016,
0.03375224397,
0.04746999219,
0.06107512116,
0.07372291386,
0.08458722383,
0.09293565154,
0.09818658978,
0.09997936338,
0.09818658978,
0.09293565154,
0.08458722383,
0.07372291386,

0.06107512116,
0.04746999219,
0.03375224397,
0.02072319016,
0.0090885479,
-0.000646590197,-0.008123514242,
-0.01320868172,
-0.01597031951,
-0.01663137041,
-0.01557052694,
-0.01322921738,
-0.01010407601,-0.006660183426,0.003321184311,
-0.0004065925605,
0.001853102469,
0.003353076056,
0.004079894163,
0.004117832519,
0.01060591545
};
void main( void )
{
Uint8 spiadcbuf[3];
int i,xval[120],k;
float temp,sum;
C6745_init();
spiadc_init();
spidac_init();
for(i=0;i<52;i++)
{
xval[i]=0;
}
while(1)
{
spiadcbuf[0] = 0x01;
command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

//

setup

spiadc_cycle(spiadcbuf, 3); // Execute


spiadc read cycle
adc_value = ((spiadcbuf[1]&0x0f) << 8)|
spiadcbuf[2];
xval[0] = adc_value;

sum = 0;
for(k=0;k<51;k++)
{
temp = (xval[k])*(h[k]);
sum = sum + temp;
}
SPI_Write(sum);
for(i=50;i>=0;i--)
{
xval[i+1] = xval[i];
}
}
}
/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive;
DAC_CS_LOW();
Data = ( 0x3000 | Data );
/* Clear any old data */
receive = SPI0_SPIBUF;
// Wait for transmit ready
while( SPI0_SPIBUF & 0x10000000 );
/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);
/* Read 1 byte */
receive = SPI0_SPIBUF;
for(i=0;i<10;i++);
DAC_CS_HIGH();
}

Input:

output

FIR HIGH PASS FILTER USING TMS320C6745 DSP KIT

Program

#include
#include
#include
#include
#include
#define
0x0;
#define
0x1;

<stdio.h>
<math.h>
"c6745.h"
"spiadc.h"
"spidac.h"
DAC_CS_LOW();
//(CS=Low:Enable)
DAC_CS_HIGH();
//(CS=High:Disable)

SPI0_SPIPC3 =
SPI0_SPIPC3 =

void SPI_Write(unsigned short Data);


unsigned short i,j=0,High,Value=0;
signed int adc_value;
//High Pass sf=6khz sbf=200 pbf=400
float h[51] ={
-0.01060591545,-0.004117832519,0.004079894163,-0.003353076056,0.001853102469,
0.0004065925605, 0.003321184311,
0.006660183426, 0.01010407601,
0.01322921738,
0.01557052694, 0.01663137041,
0.01597031951, 0.01320868172,
0.008123514242,
0.000646590197, -0.0090885479,
-0.02072319016, -0.03375224397,
-0.04746999219,
-0.06107512116, -0.07372291386,
-0.08458722383, -0.09293565154,
-0.09818658978,
0.900020659, -0.09818658978,
-0.09293565154, -0.08458722383,
-0.07372291386,
-0.06107512116, -0.04746999219,
-0.03375224397, -0.02072319016,
-0.0090885479,

0.000646590197, 0.008123514242,
0.01320868172, 0.01597031951,
0.01663137041,
0.01557052694, 0.01322921738,
0.01010407601, 0.006660183426,
0.003321184311,
0.0004065925605,-0.001853102469,0.003353076056,-0.004079894163,0.004117832519,
-0.01060591545
};
void main( void )
{
Uint8 spiadcbuf[3];
int i,xval[120],k;
float temp,sum;
C6745_init();
spiadc_init();
spidac_init();
for(i=0;i<52;i++)
{
xval[i]=0;
}
while(1)
{
spiadcbuf[0] = 0x01;
command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

// setup

spiadc_cycle(spiadcbuf, 3); // Execute


spiadc read cycle
adc_value = ((spiadcbuf[1]&0x0f) << 8)|
spiadcbuf[2];
xval[0] = adc_value;
sum = 0;
for(k=0;k<51;k++)
{

temp = (xval[k])*(h[k]);
sum = sum + temp;
}
SPI_Write(sum+1625);
for(i=50;i>=0;i--)
{
xval[i+1] = xval[i];
}
}
}
/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive;
DAC_CS_LOW();
Data = ( 0x3000 | Data );
/* Clear any old data */
receive = SPI0_SPIBUF;
// Wait for transmit ready
while( SPI0_SPIBUF & 0x10000000 );
/* Write 1 byte */
SPI0_SPIDAT0 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);
/* Read 1 byte */
receive = SPI0_SPIBUF;
for(i=0;i<10;i++);
DAC_CS_HIGH();
}
Input

Output

Potrebbero piacerti anche