# Connexions

You are here: Home » Content » From MATLAB and Simulink to Real-Time with TI DSP's » Spectrum Estimation

### Lenses

What is a lens?

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

#### Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
• TI DSP

This module and collection are included inLens: Texas Instruments DSP Lens
By: Texas Instruments

Click the "TI DSP" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

#### Also in these lenses

• Lens for Engineering

This module and collection are included inLens: Lens for Engineering
By: Sidney Burrus

Click the "Lens for Engineering" link to see all content selected in this lens.

### Recently Viewed

This feature requires Javascript to be enabled.

### Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Inside Collection (Report):

Report by: Jacob Fainguelernt. E-mail the author

# Spectrum Estimation

Module by: Jacob Fainguelernt. E-mail the author

Summary: This module describe the use of the DSK6713 for Spectrum Estimation. Simulink simulation models for different spectrum estimation methods. Those models are used afterwards to generated the DSP code. The user interfaces with the DSK6713 operation through a Graphic User Interface (GUI) running in a PC.

## Introduction

In this module the DSK6713 will be used for spectrum estimation. Three estimation methods will be implemented:

1. Periodogram
2. Burg
3. M-Cov

### Periodogram

The Periodogram block computes a nonparametric estimate of the spectrum. The block averages the squared magnitude of the FFT computed over windowed sections of the input and normalizes the spectral average by the square of the sum of the window samples.

### The Modified Covariance Method

The Modified Covariance Method block estimates the power spectral density (PSD) of the input using the modified covariance method. This method fits an autoregressive (AR) model to the signal by minimizing the forward and backward prediction errors in the least squares sense. The order of the all-pole model is the value specified by the Estimation order parameter. To guarantee a valid output, you must set the Estimation order parameter to be less than or equal to two thirds the input vector length. The spectrum is computed from the FFT of the estimated AR model parameters.

### Burg Method

The Burg Method block estimates the power spectral density (PSD) of the input frame using the Burg method. This method fits an autoregressive (AR) model to the signal by minimizing (least squares) the forward and backward prediction errors while constraining the AR parameters to satisfy the Levinson-Durbin recursion.

## Simulation

### The Environment

Figure 4 shows the data flow for the Estimation simulation. The input signal for the estimator is an AR process generated by feeding an all-poles filter with white noise. The AR coefficients generate the reference spectrum to be compared against the estimated one.

### The Procedure

1. Create a new model in Simulink® and name it: “SpectrumEstimation.mdl”
2. Open the Simulink library browser and add a random source object:
3. Double click on the random source object, and configure its parameters to fit the white noise characteristics we want to achieve:
4. Add a new digital filter to the model:
5. Double-click on the filter and fill in the following parameters1
6. Add the 3 estimators: Periodogram, Burg and Modified-Covariance to your model:
7. Configure the FFT length of the three models to 1282:
9. This constant will have the AR coefficients values:
10. Add a magnitude FFT block in order to get the spectrum from the AR coefficients:
11. Set the FFT length to 128:
12. Add a new math function object:
13. The “Math Function” block should be configured to calculate the reciprocal:
14. Add a new gain to your model (to represent the white noise variance in the reference spectrum generation) and set its value to 0.1:
15. In order to display the Real and Estimated spectra simultaneously, you need to add a new concatenate object:
16. Set the number of inputs of the concatenation object to 4:
17. The various spectra will be displayed in a vector scope:
18. Select frequency as its input domain
19. Connect the blocks as shown:
20. When running the model3, you should see the get the following display:

## Real Time Implementation

### The Environment

Figure 21 shows the block-diagram for the real time implementation. The DSP will deliver two outputs. The first is the reference spectrum; the second is an estimated spectrum of the output of the all-pole filter. Three real-time models will be created, each one corresponding to an estimator. The user will be able to select the desired estimator through a Graphic User Interface (GUI).

The real-time implementation model will be created from the simulation model, after the following changes:

• The noise generator block will be replaced by the CODEC of the DSK6713
• The virtual scope will be replaced also by the CODEC
• A target definition block (DSK6713) will be added.

Equipment Used:

• DSK6713
• Dual Channel Oscilloscope
• Signal Generator

### Creating the Models

1. Open the simulation model “SpectrumEstimation.mdl”.
2. Remove the “Burg” and “MCov AR” estimators.
3. Add the C6713DSK target to the model
4. Replace the vector scope by the “Digital to Analog” converter (DAC)
5. Configure the DAC block to a sampling rate to 8 KHZ and 16-bit samples.
6. Double- click on the concatenation object and change the number of inputs from 4 to 2.
7. Replace the white noise generator by the “Analog to Digital” converter (ADC).
8. Configure the ADC blocks to a sampling rate to 8 KHZ and 16-bit samples.
9. The final model should look as follows:
10. Set the AR-coefficients data type to single.
11. Configure the Model to generate and build (without executing) the CCS code as shown:
12. Save the model as “Periodogram.mdl”
13. Build the model (CTRL-B)
14. Replace the Periodogram estimator block by the Burg estimator
15. The final model should look as follows:
16. Save the model as “Burg.mdl”
17. Build the model (CTRL-B)
18. Replace the Burg estimator block by the MCov AR estimator
19. The final model should look as follows:
20. Save the model as “MCcov_AR.mdl”
21. Build the model (CTRL-B)At this step you’ll have three .out files to be loaded to the DSK. Each one corresponding to an estimator.

### The Graphic User Interface (GUI)

The GUI shown in Figure 32 will be used to select the model. Upon selecting a model, its correspondent load file will be loaded to the DSP.

1. Enter GUIDE in the MATLAB® command line.
2. Choose a new GUI, and name it Spectrum

Periodogram
Burg
M-Cov

4. A script file “spectrum.m” will open, when you press the “play” button. Name the script “spectrum.m”
5. The GUI will perform the following tasks:
• Upon activating the GUI, the default model is loaded to the DSP.
• When the user selects a new model, it is loaded to the DSP.
6. The initialization routine “Spectrum_OpeningFcn” will be:

function Spectrum_OpeningFcn(hObject, eventdata, handles, varargin)
modelName = gcs;
%connect to target:
CCS_Obj = connectToCCS(modelName);
% Identify RTDX channel names/modes
CodegenDir = fullfile(pwd, ['Periodogram' '_c6000_rtw']);
OutFile = fullfile(CodegenDir, ['Periodogram' '.out']);
%load the model to the DSK:
handles.CCS_Obj=CCS_Obj;
handles.output = hObject;
%remember the current model:
handles.last_model=1;
CCS_Obj.run;
% Update handles structure
guidata(hObject, handles);

7. Selecting a new model:

%1. halts the current model
%inputs:
%m - 3 levels flag that tells which model to load.
%CCS_Obj - the target object
function ChangeModel(m,CCS_Obj)
CCS_Obj.halt;
switch m
case 1
model='Periodogram';
case 2
model='Burg';
case 3
model= 'MCov_AR';
end
CodegenDir = fullfile(pwd, [model '_c6000_rtw']);
OutFile = fullfile(CodegenDir, [model '.out']);
CCS_Obj.run;
if last_y~=15000
r.writemsg(chan_struct(2).name,1/last_y);

end

8. When the user changes the model, the list-box handler function is invoked:

function listbox1_Callback(hObject, eventdata, handles)
handles.last_model=get(hObject,'Value') ;
ChangeModel(handles.last_model,handles.CCS_Obj);
guidata(hObject, handles);


The handler saves the new model as the current model and invokes the change model function we described above.

Now you can run the model, and observe the results in the oscilloscope for the various estimators.

## Footnotes

1. The Auto-Regressive process is represented by an all-pole IIR filter. The AR coefficients are the ones in the “Denominator coefficients” label.
2. The same configuration parameters apply for the three models.
3. You should select a different color for each channel

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

#### Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

#### Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks