## digital signal processing

digital signal processing

Sampling and signal reconstruction

Quantization errors

Z-transform-poles&zeros

FFT 05-10-2018

Digital Filters-Simulink

FIR Filters-Simulink

fir-bonus

Lab1

Lab2

Lab3

Lab4

Lab5

Lab6

Lab7

Lab8

Lab9

Lecture notes:

intro

Sampling

Interpolation and more...

Z transform

z

ebook

matlab introduction (basics)

0501

This page contains mfile and pfile downloads used in class examples. Mfiles are simply text (ascii) files. They can be copied and pasted into the Matlab editor or workspace, or downloaded to you computer from the links below. Pfiles are similar to Mfiles in that they can be executed in the Matlab workspace; however the code cannot be viewed or edited.

kfourier.m – The script presents graphic examples summing up a series of odd harmonic sine waves to form a square wave.

aliasex1.m – The script presents graphic examples of aliasing and shows how the time axis vector in Matlab is effectively used to sample continuous functions.

sincex1.m - The script illustrates how sinc function weighting (corresponding to the ideal low-pass reconstruction filter) nulls out all other samples in the interpolation/filtering process when increments equal to the sampling interval are used.

sincex2.m - Similar to script sincex1.m, except step smaller than the sampling interval are taken to illustrate how it weights surrounding samples to reconstruct points between the samples.

sincinterp_Lab1.m - % The scripts performs sinc function interpolation as an example of ideal low-pass filtering and reconstructing a signal from its samples. Continuous waveforms are simulated with sampling rates orders of magnitude higher and linear interpolation schemes on square/rampe-like pulses. Sinc function interpolation is applied to various pulses (not bandlimited) and a sine wave (bandlimited) through interpolation. Plots are produce comparing the original continuous-time signal to the one reconstructed from its samples.

quant_lab1.m – This script simulates the distortion from an R-bit quantizer and computes the SNR for the signal to quantization noise. The signal to be quantized is either a sine wave generated in the script or a signal read in from a wave file. The script also plots the average spectra for both the original and quantized signals. The resulting SNR is printed in the plot title. This script is useful for Lab 1.

sigclip.m – This function inputs signal vector and clips all values exceeding an upper value UC to UC and all values below a lower value LC to LC. Values of X between UC and LC are passed to the output vector unchanged. This function is used in Lab 2.

psdex.m – The script demonstrates the Power Spectral Density with an example using the *pwelch* function on a sinusoid in white Gaussian noise (WGN). The script generates a sinusoid, normalizes its power, adds to it WGN at a specified SNR level, and then computes the power spectral density (PSD) using PWELCH. Plots of the original time domain signal and PDS are provided. Parameters a well-commented so changes can be made to examine effects of window size, number of FFT points, tapering window, signal frequency, and SNR levels. This script is useful as an example of for experiments in Lab 2.

winlook.m –This script illustrates basic processing plotting functions for examining window functions. This script uses the Tukey window as an example. Different windows have different parameters, so adjustments must be made when inserting other window function into this script.

firlook.m – This script illustrates basic processing and plotting functions for examining filter properties. This script uses the FIR filters FIR1 (windowing method) and FIRPM (the Parks-McClellan) filter design program to create high-pass filters, FREQZ to compute the filter transfer functions, FILTER to compute the impulse response, and ROOTS to compute zero locations of the filters.

iirlook.m – This script illustrates basic processing and plotting functions for examining and specifying filter properties for the IIR filters. This script uses the IIR filters BUTTER (Butterworth maximally flat), CHEBY1 (Chebyshev Type 1 filter, ripple in passband), CHEBY2 (Chebyshev Type 2 filter, ripple in stopband) and ELLIP (Elliptical filter, ripple in both pass and stop bands). FREQZ is used to compute the filter transfer functions, FILTER is used to compute the impulse response, and ROOTS to compute zero and pole locations of the filters. All examples will show the filter design and analysis for a 6th order band pass filter with a sampling rate of 8000Hz and a passband between 1000 and 2500 Hz, or in the case where the stopband edge frequencies are required, they will be taken at 850 and 2900 Hz.

modulb.m – This function generates a sample line codes signals from an input binary sequence, a source data rate in bits per second and a sampling rate of output waveform in samples per second. The types of line codes can be selected from the following options: unipolar_nrz, bipolar_nrz, 4level_nrz, bipolar_rz, unipolar_rz, ami, manchester, miller, unipolar_nyquist, and bipolar_nyquist.

bittrans.m – % This script demonstrates encoding a binary sequence to a baseband line signal, and the effects of adding noise and distortion. Plots are generated to help understand the impact of noise and bandwidth limits on the received waveform and potential for bit errors in the decoded sequence. The script uses the function MODULB (must be downloaded from EE422G web site as well) to generate various line codes. The script initializes with critical parameters such as data rate, bit sequence, line code, channel bandwidth and signal to noise level. It then plots the line coded sequence (Figure 1), the distorted sequence (Figure 2) and the noise plus distortion sequence (Figure 3).

biterr.m – % This script simulates a digital communication system where noise and limited bandwidth are the primary sources of corruption resulting in bit errors. Binary sequences are randomly generated and encoded into baseband line signals. A matched filter is derived and implemented for decoding the bit from the noisy and distorted signals. The resulting bit error rate is computed along with a graphic showing where in the sequence bit errors actually occurred. The bit error rate is printed in the title of the figure. This script uses the function MODULB (must be downloaded from EE422G web site as well) to generate various line codes and to extract templates for the match filter design and implementation.

simpmod.m – % This script demonstrates the modulation properties of the real and complex sinusoid. A simple sinusoid is used as a test signal to allow for easy observation of the frequency shifts involved in the modulation process. The sampling rate should be set sufficiently high to account for the shift of the modulation frequency plus the frequency range of the original signal. The PSD is estimated with the PWELCH function. The 'twosided' option is selected for PWLECH and the FFTSHIFT is used to see both the positive and negative frequencies on an axis symmetric about zero. This is important to observe the shifting of both the positive and negative frequency component as well as handling the complex valued waveforms, whose spectra are not symmetric about 0 (DC). Plots of the spectra magnitudes for test signal, modulating (carrier) frequency, and the modulated signal are generated for the real (symmetric spectra) and complex-valued signals.

bbchan.p – % This hidden function written to simulate transmission over a band-pass channel, of which the band=pass parameters are unknown. The function adds noise after band-pass filtering to result in a a 20 dB SNR. Let Y be a vector containing the signal to be transmitted with sampling rate FS. The channel simulation is implemented with the following syntax:

yout = bbchan(y,fs)

where output vector YOUT is the same size as input signal Y with channel noise and distortion. (this function can’t be viewed, only downloaded and execute in the Matlab workspace.

**Data Files **

** **

This page contains downloads for data files to be used in class examples and laboratory experiments.

mozart-1.wav – This wave file is a 5 second excerpt of lively classical music by Mozart, 1 channel, sampled at 44.1 kHz with 16 bits per sample.

oldwoman.wav – This wave file is a 2.5 second sample of speech from an adult female, 1 channel, sampled at 8 kHz with 16 bits per sample.

lab5nde.mat – This mat-file contains sampled ultrasonic A-scans. The A-scans were obtained from three 2-in diameter stainless steel rods that were heat treated to obtain various grain sizes. A flaw was simulated in each specimen by drilling a flat-bottom hole of 4.22-mm diameter. The samples were placed in a water bath and scanned with a U2-H KB-Aerotech Alpha transducer with a center frequency of 5 MHz and a Gaussian-shaped spectrum with a 4 MHz bandwidth. The received echoes were digitized at a sampling rate of 100 MHz, and each measurement was then averaged 200 times in a LeCroy 9400 digital oscilloscope to reduce time varying noise. Average grain sizes for the difference samples were 86, 106, and 160 pm. This data can be loaded into your Matlab workspace with the *load *command (i.e. if labtnde is in current directory, simply type *load lab5nde.mat*). Once loaded, type *whos* and the workspace should contain the following vectors and parameters:

**Name Size Bytes Class Attributes**

a1 2000x1 16000 double

a1_posmm 1x1 8 double

a2 2000x1 16000 double

a2_posmm 1x1 8 double

c 1x1 8 double

fs 1x1 8 double

nfa1 2000x1 16000 double

nfa1_posmm 1x1 8 double

nfa2 2000x1 16000 double

nfa2_posmm 1x1 8 double

nfa3 2000x1 16000 double

nfa3_posmm 1x1 8 double

The vectors a1 and a2 are the sample A-scans that really do not need filtering to make the flaw echo stronger than the grain. The vectors nfa1, nfa2 and nfa3 are A-scans that need filtering in order for the flaw to be detectable (i.e. be stronger than the grain echoes). The parameters are as follows:

c => is the speed of sound in stainless steel.

fs => is the sampling rate.

a1_posmm => is position of the flaw in millimeters for a1

a2_posmm => is position of the flaw in millimeters for a2

nfa1_posmm => is position of the flaw in millimeters for naf1

nfa2_posmm => is position of the flaw in millimeters for naf2

nfa3_posmm => is position of the flaw in millimeters for naf3

lab5test.mat – This mat-file contains 3 sampled ultrasonic A-scans. The A-scans were obtained from three 2-in diameter stainless steel rods that were heat treated to obtain various grain sizes. A flaw was simulated in each specimen by drilling a flat-bottom hole of 4.22-mm diameter. The samples were placed in a water bath and scanned with a U2-H KB-Aerotech Alpha transducer with a center frequency of 5 MHz and a Gaussian-shaped spectrum with a 4 MHz bandwidth. The received echoes were digitized at a sampling rate of 100 MHz, and each measurement was then averaged 200 times in a LeCroy 9400 digital oscilloscope to reduce time varying noise. Average grain sizes for the difference samples were 86, 106, and 160 pm. This data can be loaded into your Matlab workspace with the *load *command (i.e. if lab5test.mat is in current directory, simply type *load lab5test.mat*). Once loaded, type *whos* and the workspace should contain the following vectors and parameters:

**Name Size Bytes Class Attributes**

c 1x1 8 double

fs 1x1 8 double

ta1 2000x1 16000 double

ta2 2000x1 16000 double

ta3 2000x1 16000 double

The vectors ta1, ta2, and ta3 are the sample A-scans that contain flaws. The other scalars are as follows:

c => is the speed of sound in stainless steel.

fs => is the sampling rate.

sqwaveINnoise.mat – This mat-file contains simulated signals of 3 second durations. Each signal contains a single period square wave corrupted with increasing levels of AWGN. The signals were sampled at 10kHz. The square wave (positive values precede negative) was generated with period 0.01 seconds, and occurred at various places within the 3 second received signals. Once loaded into the workspace, the “whos” command displays the following information:

**Name Size Bytes Class Attributes**

fs 1x1 8 double

sigmat 12x30000 2880000 double

snra 1x12 96 double

tax 1x30000 240000 double

The scalar variable *fs* is the sampling rate of the received signals stored in rows of matrix *sigmat*, in which each row has a square wave signal located in it. The SNR values corresponding to each row is stored in the vector *snra*, and the vector *tax* is the time axis in seconds associated with each row of the signal matrix *sigmat*.

mfopt.wav – This wave file contains a mono speech signal recorded with good quality and sampled at 48 kHz. The speech consists of an adult male speaking, “The matched filter is the optimal filter for detecting a deterministic signal in uncorrelated random noise.”

twNspec.wav – This wave file contains a mono speech signal recorded with good quality and sampled at 48 kHz. The speech consists of an adult male speaking, “The amplitudes of the time waveform show its energy distribution over time. The spectral magnitude (derived from the Fourier transform) shows its energy distribution over frequency.”

impNtrans.wav – This wave file contains a mono speech signal recorded with good quality and sampled at 48 kHz. The speech consists of an adult male speaking, “The Laplace transform of a system’s impulse response is its transfer function.”