Blog of my final project, which is about End-to-End Voice Transmission, simulated in MATLAB for Mobile Phone Tech. & Comp.

Sunday, December 3, 2006

Pulse Amplitude Modulation & Demodulation - Application in MATLAB

pamdemod

Pulse amplitude demodulation [1]

Syntax

z = pamdemod(y,M)
z = pamdemod(y,M,ini_phase)
z = pamdemod(y,M,ini_phase,symbol_order)

Description

z = pamdemod(y,M) demodulates the complex envelope y of a pulse amplitude modulated signal. M is the alphabet size. The ideal modulated signal should have a minimum Euclidean distance of 2.

z = pamdemod(y,M,ini_phase) specifies the initial phase of the modulated signal in radians.

z = pamdemod(y,M,ini_phase,symbol_order) specifies how the function assigns binary words to corresponding integers. If symbol_order is set to 'bin' (default), the function uses a natural binary-coded ordering. If symbol_order is set to 'gray', it uses a Gray-coded ordering.

Examples

The example in Comparing Theoretical and Empirical Error Rates uses this function.

pammod

Pulse amplitude modulation [2]

Syntax

y = pammod(x,M)
y = pammod(x,M,ini_phase)
y = pammod(x,M,ini_phase,symbol_order)

Description

y = pammod(x,M) outputs the complex envelope y of the modulation of the message signal x using pulse amplitude modulation. M is the alphabet size. The message signal must consist of integers between 0 and M-1. The modulated signal has a minimum Euclidean distance of 2. If x is a matrix with multiple rows, the function processes the columns independently.

y = pammod(x,M,ini_phase) specifies the initial phase of the modulated signal in radians.

y = pammod(x,M,ini_phase,symbol_order) specifies how the function assigns binary words to corresponding integers. If symbol_order is set to 'bin' (default), the function uses a natural binary-coded ordering. If symbol_order is set to 'gray', it uses a Gray constellation ordering.

Examples

The example in Comparing Theoretical and Empirical Error Rates uses this function.

plot (channel)

Plot channel characteristics with channel visualization tool [3]

Syntax

plot(h)

Description

plot(h), where h is a channel object, launches the channel visualization tool. This GUI tool allows you to plot channel characteristics in various ways. See Using the Channel Visualization Tool for details.

Examples

Examples using this plotting tool are found in Examples of Using the Channel Visualization Tool.

From Wave File

Read audio data from Microsoft Wave (.wav) file

Library

Signal Processing Sources

dspsrcs4

Description

The From Wave File block reads audio data from a Microsoft Wave (.wav) file and generates a signal with one of the data types and amplitude ranges in the following table.

Output Data Type Output Amplitude Range

double

±1

single

±1

int16

-32768 to 32767 (-215 to 215 - 1)

uint8

0 to 255

The audio data must be in uncompressed pulse code modulation (PCM) format.

y = wavread('filename')       % Equivalent MATLAB code

The block supports 8-, 16-, 24-, and 32-bit Microsoft Wave (.wav) files.

The File name parameter can specify an absolute or relative path to the file. When the file is on the MATLAB path or in the current directory (the directory returned by typing pwd at the MATLAB command line), you need only specify the file's name. You do not need to specify the.wav extension.

For an audio file containing C channels, the block's output is an M-by-C matrix containing one frame (M consecutive samples) of audio data from each channel. The frame size, M, is specified by the Samples per output frame parameter. For M=1, the output is sample based; otherwise, the output is frame based.

The output frame period, Tfo, is

where Fs is the data sample rate in Hz.

To reduce the required number of file accesses, the block acquires L consecutive samples from the file during each access, where L is specified by the Minimum number of samples for each read from file parameter ( ). For , the block instead acquires M consecutive samples during each access. Larger values of L result in fewer file accesses, which reduces run-time overhead.

Use the Data type parameter to specify the data type of the block's output. Your choices are double, single, uint8, or int16.

Select the Loop check box if you want to play the file more than once. Then, enter the number of times to play the file. The number you enter must be a positive integer or inf.

Use the Number of times to play file parameter to enter the number of times to play the file. The number you enter must be a positive integer or inf, to play the file until you stop the simulation.

The Samples restart parameter determines whether the samples from the audio file repeat immediately or repeat at the beginning of the next frame output from the output port. When you select immediately after last sample, the samples repeat immediately. When you select at beginning of next frame, the frame containing the last sample value from the audio file is zero padded until the frame is filled. The block then places the first sample of the audio file in the first position of the next output frame.

Use the Output start-of-file indicator parameter to determine when the first audio sample in the file is output from the block. When you select this check box, a Boolean output port labeled SOF appears on the block. The output from the SOF port is 1 when the first audio sample in the file is output from the block. Otherwise, the output from the SOF port is 0.

Use the Output end-of-file indicator parameter to determine when the last audio sample in the file is output from the block. When you select this check box, a Boolean output port labeled EOF appears on the block. The output from the EOF port is 1 when the last audio sample in the file is output from the block. Otherwise, the output from the EOF port is 0.

The block icon shows the name, sample rate (in Hz), number of channels (1 or 2), and sample width (in bits) of the data in the specified audio file. All sample rates are supported; the sample width must be either 8, 16, 24, or 32 bits.

Dialog Box

File name

Enter the path and name of the file to read. Paths can be relative or absolute.

Samples per output frame

Enter the number of samples in each output frame, M.

Minimum number of samples for each read from file

Enter the number of consecutive samples to acquire from the file with each file access, L.

Data type

Select the output data type: double, single, uint8, or int16. The data type setting determines the output's amplitude range, as shown in the preceding table.

Loop

Select this check box if you want to play the file more than once.

Number of times to play file

Enter the number of times you want to play the file.

Samples restart

Select immediately after last sample to repeat the audio file immediately. Select at beginning of next frame to place the first sample of the audio file in the first position of the next output frame.

Output start-of-file indicator

Use this check box to determine whether the output contains the first audio sample in the file.

Output end-of-file indicator

Use this check box to determine whether the output contains the last audio sample in the file.

Supported Data Types

  • Double-precision floating point

  • Single-precision floating point

  • 16-bit signed integer

  • 8-bit unsigned integer

To learn how to convert your data types to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.

See Also

From Wave Device Signal Processing Blockset
Signal From Workspace Signal Processing Blockset
To Wave File Signal Processing Blockset
wavread MATLAB

G711 Codec

Quantize narrowband speech input signals

Library

Quantizers

dspquant2

Description

The G711 Codec block is a logarithmic scalar quantizer designed for narrowband speech. Narrowband speech is defined as a voice signal with an analog bandwidth of 4 kHz and a Nyquist sampling frequency of 8 kHz. The block quantizes a narrowband speech input signal so that it can be transmitted using only 8-bits. The G711 Codec block has three modes of operation: encoding, decoding, and conversion. You can choose the block's mode of operation by setting the Mode parameter.

If, for the Mode parameter, you choose Encode PCM to A-law, the block assumes that the linear PCM input signal has a dynamic range of 13 bits. Because the block always operates in saturation mode, it assigns any input value above to and any input value below to . The block implements an A-law quantizer on the input signal and outputs A-law index values. When you choose Encode PCM to mu-law, the block assumes that the linear PCM input signal has a dynamic range of 14 bits. Because the block always operates in saturation mode, it assigns any input value above to and any input value below to . The block implements a mu-law quantizer on the input signal and outputs mu-law index values.

If, for the Mode parameter, you choose Decode A-law to PCM, the block decodes the input A-law index values into quantized output values using an A-law lookup table. When you choose Decode mu-law to PCM, the block decodes the input mu-law index values into quantized output values using a mu-law lookup table.

If, for the Mode parameter, you choose Convert A-law to mu-law, the block converts the input A-law index values to mu-law index values. When you choose Convert mu-law to A-law, the block converts the input mu-law index values to A-law index values.

    Note Set the Mode parameter to Convert A-law to mu-law or Convert mu-law to A-law only when the input to the block is A-law or mu-law index values.

If, for the Mode parameter, you choose Encode PCM to A-law or Encode PCM to mu-law, the Overflow diagnostic parameter appears on the block parameters dialog box. Use this parameter to determine the behavior of the block when overflow occurs. The following options are available:

  • Ignore — Proceed with the computation and do not issue a warning message.

  • Warning -— Display a warning message in the MATLAB Command Window, and continue the simulation.

  • Error — Display an error dialog box and terminate the simulation.

    Note Like all diagnostic parameters on the Configuration Parameters dialog box, Overflow diagnostic parameter is set to Ignore in the Real-Time Workshop code generated for this block.

Dialog Box

Mode
  • When you choose Encode PCM to A-law, the block implements an A-law encoder.

  • When you choose Encode PCM to mu-law, the block implements a mu-law encoder.

  • When you choose Decode A-law to PCM, the block decodes the input index values into quantized output values using an A-law lookup table.

  • When you choose Decode mu-law to PCM, the block decodes the input index values into quantized output values using a mu-law lookup table.

  • When you choose Convert A-law to mu-law, the block converts the input A-law index values to mu-law index values.

  • When you choose Convert mu-law to A-law, the block converts the input mu-law index values to A-law index values.

Overflow diagnostic

Use this parameter to determine the behavior of the block when overflow occurs.

  • Select Ignore to proceed with the computation without a warning message.

  • Select Warning to display a warning message in the MATLAB Command Window and continue the simulation.

  • Select Error to display an error dialog box and terminate the simulation.

This parameter is only visible if, for the Mode parameter, you select Encode PCM to A-law or Encode PCM to mu-law.

References

ITU-T Recommendation G.711, "Pulse Code Modulation (PCM) of Voice Frequencies," General Aspects of Digital Transmission Systems; Terminal Equipments, International Telecommunication Union (ITU), 1993.

Supported Data Types

Port Supported Data Types

PCM

  • 16-bit signed integers

A

  • 8-bit unsigned integers

mu

  • 8-bit unsigned integers

To learn how to convert your data types to the above data types in MATLAB and Simulink, see Supported Data Types and How to Convert to Them.

See Also

Quantizer Simulink
Scalar Quantizer Decoder Signal Processing Blockset
Scalar Quantizer Design Signal Processing Blockset
Uniform Decoder Signal Processing Blockset
Uniform Encoder Signal Processing Blockset
Vector Quantizer Decoder Signal Processing Blockset
Vector Quantizer Design Signal Processing Blockset
Vector Quantizer Encoder Signal Processing Blockset


[1] Pulse Amplitude Demodulation

http://www.mathworks.com/access/helpdesk/help/toolbox/comm/ug/pamdemod.html

[2] Pulse Amplitude Modulation

http://www.mathworks.com/access/helpdesk/help/toolbox/comm/ug/pammod.html

[3] Plot (channel)

http://www.mathworks.com/access/helpdesk/help/toolbox/comm/ug/plotchannel.html

No comments: