AIM OF EXPT:
Experiment 1
To generate and study Discrete Time Signals for ex. unit step, ramp, impulse using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
Common Sequences:
Unit Impulse, Unit Step, and Unit RampSince MATLAB is a programming language, an endless
variety of different signals is possible. Here are some statements that generate several commonly used sequences, including the unit impulse, unit step, and unit ramp functions.
Signal Processing Toolbox
functions generate waveforms. Most require you to begin with a vector representing a time base. Consider generating data with a 1000 Hz sample frequency, for example. An appropriate time vector is t = (0:0.001:1)'; where the MATLAB colon operator creates a 1001element row vector that represents time running from zero to one second in steps of one millisecond. The transpose operator (') changes the row vector into a column; the semicolon (;) tells MATLAB to compute but not display the result. Given t you can create a sample signal y consisting of two sinusoids, one at 50 Hz and one at 120 Hz with twice the amplitude. y = sin(2*pi*50*t) + 2*sin(2*pi*120*t); The new variable y, formed from vector t, is also 1001 elements long. You can add normally distributed white noise to the signal and graph the first fifty points using randn('state',0); yn = y + 0.5*randn(size(t));
plot(t(1:50),yn(1:50))
Waveform Generation: Time Vectors and SinusoidsA variety of toolbox
Common Sequences: Unit Impulse, Unit Step, and Unit RampSince MATLAB is a programming language, an endless variety of different signals is possible. Here are some statements that
generate several commonly used sequences, including the unit impulse, unit step, and unit ramp functions: t = (0:0.001:1)';
y 
= [1; zeros(99,1)]; % impulse 

y 
= ones(100,1); 
% step (filter assumes 0 initial cond.) 
y 
= t; 
% ramp 
y 
= t.^2; 

y 
= square(4*t); 
All of these sequences are column vectors. The last three inherit their shapes from t.
Representing Signals Common Sequences: Unit Impulse, Unit Step, and Unit
Procedure:
1. Double click on MATLAB icon on the desktop.
2. Click on File > New > MFile.
3. Type the program in the MFile Editor.
4. Save the file with a relavant name.
5. Run the program by clicking on the Run Icon in the toolbar and observe the output.
Program:[ It should be computer print ]
1) 

% 
generation of discrete time signals 
h 
= [1; zeros(99,1)]; 
xlabel('n');
ylabel('h(n)');
title('generation of impulse discrete time signals'); stem(h)
2) 

% 
generation of discrete time signals 
t 
= (0:0.001:1); 
r 
= t; 
xlabel('n'); ylabel('r(n)'); title('generation of ramp discrete time signals');
stem(r) 

3) 

% 
generation of discrete time signals 
u 
= ones(100,1); 
xlabel('n'); ylabel('u(n)'); title('generation of unit step discrete time signals'); stem(u)
Conclusion:
By using MATLAB DTS are generated and studied.
EXPT NO.2
AIM OF EXPT:  To Study the Sampling Theorem using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
Sampling theorem
According to sampling theorem, an analog signal can be exactly reconstructed from its samples if the sampling rate is at least twice the highest frequency component present in the signal. This means, if the signal contains the highest frequency component of 1 KHz, the sampling rate must be at least 2 Kilo
Samples/ Second. This sampling rate is also known as Nyquist rate.
satisfied
rate. This leads to unacceptable distortion in the signal. this distortion is known as aliasing. Due to aliasing,
the components present in the input signal whose frequency is higher Nyquist frequency will be sampled as a signal of lower frequency. And this aliased samples in turn corrupts the original signal which is lower than Nyquist frequency. Due to the presence of aliasing, a signal that contains frequency components higher than Nyquist frequency can not be reconstructed from it's samples. The effect of aliasing is shown in the figure below. The signal shown in black color is the original signal. While the signal shown in violate color is the aliased signal because of improper sampling. From the figure it is obvious that the aliased signal will be present in the sampled data as a lower frequency signal. And this will affect the original content at that frequency.
What if sampling theorem is not
?
violation of sampling theorem means, sampling the signal at a sample rate less than Nyquist
It should be noted that the information in between two consecutive samples is lost forever. But still the entire signal can be reconstructed from the samples as long as Sampling theorem is satisfied. Sampling and quantization
Sampling can be viewed theoretically as multiplying the original signal with a train of pulses with unit amplitude. This leaves the original signal with information at descrete points with magnitude of signal present in the original signal at that position. This is illustrated in the figure below.
After processing the samples has to be converted back to analog voltage. This is done by using a device known as DAC (Digital to Analog Converter). DAC does exactly opposite to what ADC has done. The DAC takes digital data as input and produces corresponding analog voltage. DACs are less expensive compared to ADCs.
Taking all these in account, we can now come to the idea of physical realization of a Digital Signal Processing system. As we know, in a DSP system, the signal has to be first converted in to digital format, process it and then convert back to analog format. All theses things can be achieved by using a system shown below.
Digital Signal Processor
Since the DSP system represents the signal as numbers, the digital signal processor must be capable of manipulating numbers. As we know, it is nothing but a computer. A general purpose computer or a dedicated digital signal processor can be used for signal processing. The dedicated signal processors are specially designed for DSP applications, and which outperforms the general purpose computers in processing efficiency. this is because the instructions, memory and other features of a dedicated Digital
Signal Processor is optimized for DSP applications. Many companies like Texas Instruments, Analog Devices,
and Motorola etc
has dedicated Signal Processors optimized for different applications.
Digital Signal Processing techniques
The applications of DSP are numerous, simple toys to satellites
DSP is well suited for any application
since it can do almost all processing that can be done using analog circuitry. The major drawbacks of DSP are comparatively high cost and distortion because of finite word length used in signal processors. Since in DSP applications, most of the hardware can be replaced with software, eventually DSP will become cost effective in most of the applications. The Digital Signal Processor mimics the behavior of analog circuitry using some DSP techniques and algorithms. The techniques that are commonly used in DSP are convolution, spectral analysis and manipulation, filtering etc
CONCLUSION: From above discussion and analysis using MATLAB the Sampling Theorem is studied.
EXPT NO.3
AIM OF EXPT:  To Study the Decimation of Signal using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
Decimation reduces the original sampling rate for a sequence to a lower rate, the opposite of interpolation. The decimation process filters the input data with a low pass filter and then resamples the resulting smoothed signal at a lower rate. y = decimate(x,r) reduces the sample rate of x by a factor r. The decimated vector y is r times shorter in length than the input vector x. By default, decimate employs an eighthorder low passes Chebyshev Type I filter. It filters the input sequence in both the forward and reverse directions to remove all phase distortion, effectively doubling the filter order. y = decimate(x,r,n) uses an order n Chebyshev filter. Orders above 13 are not recommended because of numerical instability. MATLAB displays a warning in this case. y = decimate(x,r,'fir') uses a 30 point FIR filter, instead of the Chebyshev IIR filter. Here decimate filters the input sequence in only one direction. This technique conserves memory and is useful for working with long sequences. y = decimate(x,r,n,'fir') uses a length n FIR filter.
decimate
Decimation — decrease sampling rate
Syntax
y 
= decimate(x,r) 
y 
= decimate(x,r,n) 
y 
= decimate(x,r,'fir') 
y 
= decimate(x,r,n,'fir') 
Description
Decimation reduces the original sampling rate for a sequence to a lower rate, the opposite of interpolation. The decimation process filters the input data with a lowpass filter and then resamples the resulting smoothed signal at a lower rate.
y = decimate(x,r) reduces the sample rate of x by a factor r. The decimated vector y is r times shorter in length than the input vector x. By default, decimate employs an eighthorder lowpass Chebyshev Type I filter with a cutoff frequency of 0.8*(Fs/2)/r. It
filters the input sequence in both the forward and reverse directions to remove all phase distortion, effectively doubling the filter order.
y = decimate(x,r,n) uses an order n Chebyshev filter. Orders above 13 are not recommended because of numerical instability. In this case, a warning is displayed.
Note
factors and call decimate several times.
For better results when r is greater than 13, you should break r into its
y = decimate(x,r,'fir') uses an order 30 FIR filter, instead of the Chebyshev IIR filter. Here decimate filters the input sequence in only one direction. This technique conserves memory and is useful for working with long sequences.
y = decimate(x,r,n,'fir') uses an order n FIR filter.
Examples
Decimate a signal by a factor of four:
t 
= 0:.00025:1; 
% Time vector 
x 
= sin(2*pi*30*t) + sin(2*pi*60*t); 

y 
= decimate(x,4); 
View the original and decimated signals:
stem(x(1:120)), axis([0 120 2 2]) title('Original Signal') 
% Original signal 
figure 

stem(y(1:30)) 
% Decimated signal 
title('Decimated Signal')
Algorithm
1. It designs a lowpass filter. By default, decimate uses a Chebyshev Type I filter with normalized cutoff frequency 0.8/r and 0.05 dB of passband ripple. For the fir option, decimate designs a lowpass FIR filter with cutoff frequency 1/r using fir1.
2. For the FIR filter, decimate applies the filter to the input vector in one direction. In the IIR case, decimate applies the filter in forward and reverse directions with
3. decimate resamples the filtered data by selecting every rth point.
Note
decimate function may use a lower filter order. If the specified filter order will produce passband distortion, caused by roundoff errors accumulated from the convolutions needed to create the transfer function, the filter order is
automatically reduced.
Depending on the CPU and operating system of your computer, the
Diagnostics
If r is not an integer, decimate gives the following error message:
Resampling rate R must be an integer.
If n specifies an IIR filter with order greater than 13, decimate gives the following warning:
Warning: IIR filters above order 13 may be unreliable.
References
[1] IEEE Programs for Digital Signal Processing, IEEE Press. New York: John Wiley & Sons, 1979. Chapter 8.
See Also
Conclusion:  As per above study and MATLAB analysis the Decimation of Signal is studied
EXPT NO.4
AIM OF EXPT:  To Study the Interpolation of Signal using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
Interpolation increases the original sampling rate for a sequence to a higher rate. interp performs low pass interpolation by inserting zeros into the original sequence and then applying a special low pass filter. y = interp(x,r) increases the sampling rate of x by a factor of r. The interpolated vector y is r times longer than the original input x. y = interp(x,r,l,alpha) specifies l (filter length) and alpha (cutoff frequency). The default value for l is 4 and the default value for alpha is 0.5. [y,b] = interp(x,r,l,alpha) returns vector b containing the filter coefficients used for the interpolation.
interp
Interpolation — increase sampling rate by integer factor
Syntax
y 
= interp(x,r) 
y 
= interp(x,r,l,alpha) 
[y,b] = interp(x,r,l,alpha)
Description
Interpolation increases the original sampling rate for a sequence to a higher rate. interp performs lowpass interpolation by inserting zeros into the original sequence and then applying a special lowpass filter. The filter returned by intfilt is identical to the filter used by interp.
y = interp(x,r) increases the sampling rate of x by a factor of r. The interpolated vector y is r times longer than the original input x.
y = interp(x,r,l,alpha) specifies l (filter length) and alpha (cutoff frequency). The default value for l is 4 and the default value for alpha is 0.5.
[y,b] = interp(x,r,l,alpha) returns vector b containing the filter coefficients used for the interpolation.
Examples
Interpolate a signal by a factor of four:
t 
= 0:0.001:1; 
% Time vector 
x 
= sin(2*pi*30*t) + sin(2*pi*60*t); 

y 
= interp(x,4); 
stem(x(1:30));
title('Original Signal');
figure
stem(y(1:120));
title('Interpolated Signal');
Algorithm
1. It expands the input vector to the correct length by inserting zeros between the original data values.
2. It designs a special symmetric FIR filter that allows the original data to pass through unchanged and interpolates between so that the meansquare errors between the interpolated points and their ideal values are minimized.
3. It applies the filter to the input vector to produce the interpolated output vector.
The length of the FIR lowpass interpolating filter is 2*l*r+1. The number of original sample values used for interpolation is 2*l. Ordinarily, l should be less than or equal to 10. The original signal is assumed to be band limited with normalized cutoff frequency 0≤alpha≤1, where 1 is half the original sampling frequency (the Nyquist frequency). The default value for l is 4 and the default value for alpha is 0.5.
Diagnostics
If r is not an integer, interp gives the following error message:
Resampling rate R must be an integer.
References
[1] Programs for Digital Signal Processing, IEEE Press, New York, 1979, Algorithm
8.1.
See Also
Conclusion:  As per above study and MATLAB analysis the Interpolation of Signal is studied
EXPT NO.5
AIM OF EXPT:  To Study the Speech processing: Dynamic range compression using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
Dynamic range compression Compresses the dynamic range of a signal by modifying the range of the magnitude at each frequency bin. This nonlinear spectral modification is followed by an overlapadd FFT algorithm for reconstruction. Compression maps the dynamic range of the magnitude at each frequency bin from the range 0 to 100 dB to the range ymin to ymax dB. ymin and ymax are vectors in the MATLAB workspace with one element for each frequency bin (256 long in this case). The phase is not altered. This is a nonlinear spectral modification This system might be used as a speech enhancement system for the hearing impaired. By compressing the dynamic range at certain frequencies, the listener should be able to perceive quieter sounds without being blasted out when they get loud, as in linear equalization. After repositioning the input and output figures so you can see them at the same time, change the Slider Gain from 1 to 1000 to 10000.Notice the relative heights of the output peaks change as you increase the magnitude. The algorithm in this simulation is derived from a patented system for adaptive processing of telephone voice signals for the hearing impaired. The system was developed by Alvin M. Terry and Thomas P. Krauss at US West Advanced Technologies Inc., US patent number 5,388,185. A reference for the OLA method is: Rabiner, L. R. and R. W. Schafer.Digital Processing of Speech Signals. Englewood Cliffs, NJ: Prentice Hall, 1978, pgs. 274277. This system decomposes the input signal into overlapping sections of length 256. The overlap is 192, so that every 64 samples, a new section is defined and a new FFT is computed. After the spectrum is modified and the inverse FFT is computed, the overlapping parts of the sections are added together. If no spectral modification is performed, the output is a scaled replica of the input. To use this system to demonstrate frequency dependent dynamic range compression, start the simulation. After repositioning the input and output figures so you can see them at the same time, change the Slider Gain from 1 to 1000 to 10000.Notice the relative heights of the output peaks change as you increase the magnitude.
Dynamic Range Compression Using OverlapAdd Reconstruction
This demo illustrates a method of compressing the dynamic range of a signal by modifying the range of the magnitude at each frequency bin. This nonlinear spectral modification is followed by an overlapadd FFT algorithm for reconstruction. This system might be used as a speech enhancement system for the hearing impaired. The algorithm in this simulation is derived from a patented system for adaptive processing of telephone voice signals for the hearing impaired originally developed by Alvin M. Terry and Thomas P. Krauss at US West Advanced Technologies Inc., US patent number
5,388,185.
This system decomposes the input signal into overlapping sections of length 256. The overlap is 192 so that every 64 samples, a new section is defined and a new FFT is computed. After the spectrum is modified and the inverse FFT is computed, the overlapping parts of the sections are added together. If no spectral modification is performed, the output is a scaled replica of the input. A reference for the overlapadd method used for the audio signal reconstruction is Rabiner, L. R. and R. W. Schafer. Digital Processing of Speech Signals. Englewood Cliffs, NJ: Prentice Hall, 1978, pgs.
274277.
Compression maps the dynamic range of the magnitude at each frequency bin from the range 0 to 100 dB to the range ymin to ymax dB. ymin and ymax are vectors in the MATLAB® workspace with one element for each frequency bin; in this case 256. The phase is not altered. This is a nonlinear spectral modification. By compressing the dynamic range at certain frequencies, the listener should be able to perceive quieter sounds without being blasted out when they get loud, as in linear equalization.
To use this system to demonstrate frequencydependent dynamic range compression, start the simulation. After repositioning the input and output figures so you can see them at the same time, change the Slider Gain from 1 to 1000 to 10000. Notice the relative heights of the output peaks change as you increase the magnitude.
Conclusion:  As per above study and MATLAB analysis the Speech processing:
Dynamic range compression is studied
AIM OF EXPT:
Experiment 6
To study convolution using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
conv
Convolution and polynomial multiplication
Syntax
w = conv(u,v)
Description
w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as multiplying the polynomials whose coefficients are the elements of u and v.
Definition
Let m = length(u) and n = length(v) . Then w is the vector of length m+n1 whose kth element is
The sum is over all the values of j which lead to legal subscripts for u(j) and v(k+1j), specifically j = max(1,k+1n): min(k,m). When m = n, this gives
w(1) = u(1)*v(1) w(2) = u(1)*v(2)+u(2)*v(1) w(3) = u(1)*v(3)+u(2)*v(2)+u(3)*v(1)
w(n) = u(1)*v(n)+u(2)*v(n1)+
w(2*n1) = u(n)*v(n)
Algorithm
+u(n)*v(1)
The convolution theorem says, roughly, that convolving two sequences is the same as multiplying their Fourier transforms. In order to make this precise, it is necessary to pad the two vectors with zeros and ignore roundoff error. Thus, if
X = fft([x zeros(1,length(y)1)])
and
Y = fft([y zeros(1,length(x)1)])
then conv(x,y) = ifft(X.*Y)
See Also
Procedure:
1. Double click on MATLAB icon on the desktop.
2. Click on File > New > MFile.
3. Type the program in the MFile Editor.
4. Save the file with a relavant name.
5. Run the program by clicking on the Run Icon in the toolbar and observe the output.
Program:[ It should be computer print ] %convolution of two sequences x=[1 1 1 ]; h=[1 1 1 ]; y=conv(x,h); xlabel('n'); ylabel('y(n)'); title('convolution of two sequences x(n) and y(n)'); stem(y);
Conclusion:
By using MATLAB CONVOLUTION of two sequence is studied.
AIM OF EXPT:
Experiment 7
To study fast fourier transform using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
fft
Discrete Fourier transform
Syntax
Y 
= fft(X) 
Y 
= fft(X,n) 
Y 
= fft(X,[],dim) 
Y 
= fft(X,n,dim) 
Definition
The functions Y=fft(x) and y=ifft(X) implement the transform and inverse transform pair
given for vectors of length
by:
where 

is an 
th root of unity. 
Description
Y = fft(X) returns the discrete Fourier transform (DFT) of vector X, computed with a fast Fourier transform (FFT) algorithm.
If X is a matrix, fft returns the Fourier transform of each column of the matrix.
If X is a multidimensional array, fft operates on the first nonsingleton dimension.
Y = fft(X,n) returns the npoint DFT. If the length of X is less than n, X is padded with trailing zeros to length n. If the length of X is greater than n, the sequence X is truncated. When X is a matrix, the length of the columns are adjusted in the same manner.
Y = fft(X,[],dim) and Y = fft(X,n,dim) applies the FFT operation across the dimension
dim.
Examples
A common use of Fourier transforms is to find the frequency components of a signal buried in a
noisy time domain signal. Consider data sampled at 1000 Hz. Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and 120 Hz sinusoid of amplitude 1 and corrupt it with some zero
mean random noise:
Fs = 1000; 
% Sampling frequency 

T 
= 1/Fs; 
% Sample time 
L 
= 1000; 
% Length of signal 
t 
= (0:L1)*T; 
% Time vector 
% 
Sum of a 50 Hz sinusoid and a 120 Hz sinusoid 

x 
= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); 

y 
= x + 2*randn(size(t)); 
% Sinusoids plus noise 
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with ZeroMean Random Noise') xlabel('time (milliseconds)')
It is difficult to identify the frequency components by looking at the original signal. Converting to the frequency domain, the discrete Fourier transform of the noisy signal y is found by taking the fast Fourier transform (FFT):
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y 
= fft(y,NFFT)/L; 
f 
= Fs/2*linspace(0,1,NFFT/2+1); 
% 
Plot singlesided amplitude spectrum. 
plot(f,2*abs(Y(1:NFFT/2+1)))
title('SingleSided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)') ylabel('Y(f)')
The main reason the amplitudes are not exactly at 0.7 and 1 is because of the noise. Several executions of this code (including recomputation of y) will produce different approximations to 0.7 and 1. The other reason is that you have a finite length signal. Increasing _{L} from 1000 to 10000 in the example above will produce much better approximations on average.
Algorithm
The FFT functions (fft, fft2, fftn, ifft, ifft2, ifftn) are based on a library called FFTW
computes
point DFT when
is composite (that is, when
), the
transforms of size
, and then computes
transforms of size
. The
decomposition is applied recursively to both the
be solved using one of several machinegenerated fixedsize "codelets." The codelets in turn use several algorithms in combination, including a variation of CooleyTukey [5], a prime factor
When
point problem into three (
 and
point DFTs until the problem can
is chosen
is a prime number, the FFTW library first decomposes an
decomposition described above to compute the (
For most
However, when
The execution time for fft depends on the length of the transform. It is fastest for powers of two. It is almost as fast for lengths that have only small prime factors. It is typically several times slower for lengths that are prime or which have large prime factors.
)point DFTs.
, realinput DFTs require roughly half the computation time of complexinput DFTs.
has large prime factors, there is little or no speed difference.
Data Type Support
fft supports inputs of data types double and single. If you call fft with the syntax y =
fft(X,
), the output y has the same data type as the input X.
See Also
References
[1] Cooley, J. W. and J. W. Tukey, "An Algorithm for the Machine Computation of the Complex Fourier Series,"Mathematics of Computation, Vol. 19, April 1965, pp. 297301.
[2] Duhamel, P. and M. Vetterli, "Fast Fourier Transforms: A Tutorial Review and a State of the Art," Signal Processing, Vol. 19, April 1990, pp. 259299.
[3] FFTW (http://www.fftw.org)
[4] Frigo, M. and S. G. Johnson, "FFTW: An Adaptive Software Architecture for the FFT,"Proceedings of the International Conference on Acoustics, Speech, and Signal Processing, Vol. 3, 1998, pp. 13811384.
[5] Oppenheim, A. V. and R. W. Schafer, DiscreteTime Signal Processing, PrenticeHall, 1989, p. 611.
[6] Oppenheim, A. V. and R. W. Schafer, DiscreteTime Signal Processing, PrenticeHall, 1989, p. 619.
[7] Rader, C. M., "Discrete Fourier Transforms when the Number of Data Samples Is Prime," Proceedings of the IEEE, Vol. 56, June 1968, pp. 11071108.
Procedure:
1. Double click on MATLAB icon on the desktop.
2. Click on File > New > MFile.
3. Type the program in the MFile Editor.
4. Save the file with a relavant name.
5. Run the program by clicking on the Run Icon in the toolbar and observe the output.
Program:[ It should be computer print ]
Fs = 1000; 
% Sampling frequency 

T 
= 1/Fs; 
% Sample time 
L 
= 1000; 
% Length of signal 
t 
= (0:L1)*T; 
% Time vector 
% 
Sum of a 50 Hz sinusoid and a 120 Hz sinusoid 

x 
= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); 

y 
= x + 2*randn(size(t)); 
% Sinusoids plus noise 
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with ZeroMean Random Noise') xlabel('time (milliseconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y 
= fft(y,NFFT)/L; 
f 
= Fs/2*linspace(0,1,NFFT/2+1); 
% 
Plot singlesided amplitude spectrum. 
plot(f,2*abs(Y(1:NFFT/2+1)))
title('SingleSided Amplitude Spectrum of y(t)') xlabel('Frequency (Hz)') ylabel('Y(f)')
Conclusion:
By using MATLAB FAST FOURIER TRANSFORM is studied.
AIM OF EXPT:
Experiment 8
To study FIR Filter design using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
fir1
Windowbased finite impulse response filter design
Syntax
b 
= fir1(n,Wn) 

b 
= fir1(n,Wn,'ftype') 

b 
= fir1(n,Wn,window) 

b 
= fir1(n,Wn,'ftype',window) 

b 
= fir1( 
,'normalization') 
Description
fir1 implements the classical method of windowed linearphase FIR digital filter design [1]. It designs filters in standard lowpass, highpass, bandpass, and bandstop configurations. By default the filter is normalized so that the magnitude response of the filter at the center frequency of the passband is 0 dB.
Note
Use fir2 for windowed filters with arbitrary frequency response.
b = fir1(n,Wn) returns row vector b containing the n+1 coefficients of an order n lowpass FIR filter. This is a Hammingwindow based, linearphase filter with normalized cutoff frequency Wn. The output filter coefficients, b, are ordered in descending powers of z.
Wn is a number between 0 and 1, where 1 corresponds to the Nyquist frequency.
If Wn is a twoelement vector, Wn = [w1 w2], fir1 returns a bandpass filter with passband w1 < ω< w2.
If Wn is a multielement vector, Wn = [w1 w2 w3 w4 w5
wn], fir1 returns an order n
multiband filter with bands 0 < ω< w1, w1 < ω< w2,
,
wn < ω< 1.
By default, the filter is scaled so that the center of the first passband has a magnitude of exactly 1 after windowing.
b = fir1(n,Wn,'ftype') specifies a filter type, where 'ftype' is:
• 'high' for a highpass filter with cutoff frequency Wn.
• 'stop' for a bandstop filter, if Wn = [w1 w2]. The stopband frequency range is specified by this interval.
• 'DC1' to make the first band of a multiband filter a passband.
• 'DC0' to make the first band of a multiband filter a stopband.
fir1 always uses an even filter order for the highpass and bandstop configurations. This is because for odd orders, the frequency response at the Nyquist frequency is 0, which is inappropriate for highpass and bandstop filters. If you specify an oddvalued n, _{f}_{i}_{r}_{1} increments it by 1.
b = fir1(n,Wn,window) uses the window specified in column vector window for the design. The vector window must be n+1 elements long. If no window is specified, fir1 uses a Hamming window (see hamming) of length n+1.
b 
= fir1(n,Wn,'ftype',window) accepts both 'ftype' and window parameters. 

b 
= 
fir1( 
,'normalization') 
specifies whether or not the filter magnitude is normalized. 
The string 'normalization' can be the following:
• 'scale' (default): Normalize the filter so that the magnitude response of the filter at the center frequency of the passband is 0 dB.
• 'noscale': Do not normalize the filter.
The group delay of the FIR filter designed by _{f}_{i}_{r}_{1} is n/2.
Algorithm
fir1 uses the window method of FIR filter design [1]. If w(n) denotes a window, where 1 ≤ n ≤ N, and the impulse response of the ideal filter is h(n), where h(n) is the inverse Fourier transform of the ideal frequency response, then the windowed digital filter coefficients are given by
Examples
Example 1
Design a 48thorder FIR bandpass filter with passband 0.35 ≤ ω ≤ 0.65:
b = fir1(48,[0.35 0.65]);
freqz(b,1,512)
Example 2
The chirp.mat file contains a signal, y, that has most of its power above fs/4, or half the Nyquist frequency. Design a 34thorder FIR highpass filter to attenuate the components of the signal below fs/4. Use a cutoff frequency of 0.48 and a Chebyshev window with 30 dB of ripple:
load chirp
% Load y and fs.
b = fir1(34,0.48,'high',chebwin(35,30));
freqz(b,1,512)
References
[1] Programs for Digital Signal Processing, IEEE Press, New York, 1979. Algorithm 5.2.
See Also
Procedure:
1. Double click on MATLAB icon on the desktop.
2. Click on File > New > MFile.
3. Type the program in the MFile Editor.
4.
Save the file with a relavant name.
5. Run the program by clicking on the Run Icon in the toolbar and observe the output.
Program:[ It should be computer print ]
As above.
Conclusion:
By using MATLAB fir filter window based desgin is studied.
AIM OF EXPT:
Experiment 9
To study IIR Filter design using MATLAB.
LIST OF EQIPMENTS/ APPARATUS :
1) 
MATLAB 
2) 
signal processing toolbox 
3) 
System with P4 and 1GB RAM etc. 
DISCRIPTION,CIRCUIT DIA, PROCEDURE ( ONLY GUIDELINES, IN BRIEF):
butter
Butterworth analog and digital filter design
Syntax
[z,p,k] = butter(n,Wn) [z,p,k] = butter(n,Wn,'ftype') [b,a] = butter(n,Wn) [b,a] = butter(n,Wn,'ftype') [A,B,C,D] = butter(n,Wn) [A,B,C,D] = butter(n,Wn,'ftype') [z,p,k] = butter(n,Wn,'s') [z,p,k] = butter(n,Wn,'ftype','s') [b,a] = butter(n,Wn,'s') [b,a] = butter(n,Wn,'ftype','s') [A,B,C,D] = butter(n,Wn,'s') [A,B,C,D] = butter(n,Wn,'ftype','s')
Description
butter designs lowpass, bandpass, highpass, and bandstop digital and analog Butterworth filters. Butterworth filters are characterized by a magnitude response that is maximally flat in the passband and monotonic overall.
Butterworth filters sacrifice rolloff steepness for monotonicity in the pass and stopbands. Unless the smoothness of the Butterworth filter is needed, an elliptic or Chebyshev filter can generally provide steeper rolloff characteristics with a lower filter order.
Digital Domain
[z,p,k] = butter(n,Wn) designs an order n lowpass digital Butterworth filter with normalized cutoff frequency Wn. It returns the zeros and poles in length n column vectors z and p, and the gain in the scalar k.
[z,p,k] = butter(n,Wn,'ftype') designs a highpass, lowpass, or bandstop filter, where the string 'ftype' is one of the following:
• 'high' for a highpass digital filter with normalized cutoff frequency Wn
• 'low' for a lowpass digital filter with normalized cutoff frequency Wn
• 'stop' for an order 2*n bandstop digital filter if Wn is a twoelement vector, Wn = [w1 w2]. The stopband is w1 < ω < w2.
Cutoff frequency is that frequency where the magnitude response of the filter is
butter, the normalized cutoff frequency Wn must be a number between 0 and 1, where 1 corresponds to the Nyquist frequency, π radians per sample.
If Wn is a twoelement vector, Wn = [w1 w2], butter returns an order 2*n digital bandpass filter with passband _{w}_{1} _{<} ω _{<} w2.
With different numbers of output arguments, butter directly obtains other realizations of the filter. To obtain the transfer function form, use two output arguments as shown below.
. For
Note
the transfer function.
See Limitations below for information about numerical issues that affect forming
[b,a] = butter(n,Wn) designs an order n lowpass digital Butterworth filter with normalized cutoff frequency Wn. It returns the filter coefficients in length n+1 row vectors b and a, with coefficients in descending powers of z.
[b,a] = butter(n,Wn,'ftype') designs a highpass, lowpass, or bandstop filter, where the string 'ftype' is 'high', 'low', or 'stop', as described above.
To obtain statespace form, use four output arguments as shown below:
[A,B,C,D] = butter(n,Wn) or
[A,B,C,D] = butter(n,Wn,'ftype') where A, B, C, and D are
and u is the input, x is the state vector, and y is the output.
Analog Domain
[z,p,k] = butter(n,Wn,'s') designs an order n lowpass analog Butterworth filter with angular cutoff frequency Wn rad/s. It returns the zeros and poles in length n or 2*n column vectors z and p and the gain in the scalar k. butter's angular cutoff frequency Wn must be greater than 0 rad/s.
If Wn is a twoelement vector with w1 < w2, butter(n,Wn,'s') returns an order 2*n bandpass analog filter with passband w1 < ω < w2.
[z,p,k] = butter(n,Wn,'ftype','s') designs a highpass, lowpass, or bandstop filter using the ftype values described above.
With different numbers of output arguments, butter directly obtains other realizations of the analog filter. To obtain the transfer function form, use two output arguments as shown below:
[b,a] = butter(n,Wn,'s') designs an order n lowpass analog Butterworth filter with angular cutoff frequency Wn rad/s. It returns the filter coefficients in the length n+1 row vectors b and a, in descending powers of s, derived from this transfer function:
[b,a] = butter(n,Wn,'ftype','s') designs a highpass, lowpass, or bandstop filter using the ftype values described above.
To obtain statespace form, use four output arguments as shown below:
[A,B,C,D] = butter(n,Wn,'s') or
[A,B,C,D] = butter(n,Wn,'ftype','s') where A, B, C, and D are
and u is the input, x is the state vector, and y is the output.
Examples
Highpass Filter
For data sampled at 1000 Hz, design a 9thorder highpass Butterworth filter with cutoff frequency of 300 Hz, which corresponds to a normalized value of 0.6:
[z,p,k] = butter(9,300/500,'high'); [sos,g] = zp2sos(z,p,k);
% Convert to SOS form
Hd = dfilt.df2tsos(sos,g); h = fvtool(Hd); set(h,'Analysis','freq')
% Create a dfilt object % Plot magnitude response % Display frequency response
Limitations
In general, you should use the [z,p,k] syntax to design IIR filters. To analyze or implement your filter, you can then use the [z,p,k] output with zp2sos and an sos dfilt structure. For higher order filters (possibly starting as low as order 8), numerical problems due to roundoff errors may occur when forming the transfer function using the [b,a] syntax. The following example illustrates this limitation:
n = 6; Wn = [2.5e6 29e6]/500e6; ftype = 'bandpass';
% Transfer Function design
[b,a] = butter(n,Wn,ftype);
h1=dfilt.df2(b,a);
% This is an unstable filter.
% ZeroPoleGain design
[z, p, k] = butter(n,Wn,ftype);
[sos,g]=zp2sos(z,p,k);
h2=dfilt.df2sos(sos,g);
% Plot and compare the results
hfvt=fvtool(h1,h2,'FrequencyScale','log');
legend(hfvt,'TF Design','ZPK Design')
Algorithm
butter uses a fivestep algorithm:
1. It finds the lowpass analog prototype poles, zeros, and gain using the buttap function.
2. It converts the poles, zeros, and gain into statespace form.
3. It transforms the lowpass filter into a bandpass, highpass, or bandstop filter with desired cutoff frequencies, using a statespace transformation.
4. For digital filter design, butter uses bilinear to convert the analog filter into a digital filter through a bilinear transformation with frequency prewarping. Careful frequency adjustment guarantees that the analog filters and the digital filters will have the same frequency response magnitude at Wn or w1 and w2.
5.
It converts the statespace filter back to transfer function or zeropolegain form, as required.
See Also
Procedure:
1. Double click on MATLAB icon on the desktop.
2. Click on File > New > MFile.
3. Type the program in the MFile Editor.
4. Save the file with a relavant name.
5. Run the program by clicking on the Run Icon in the toolbar and observe the output.
Program:[ It should be computer print ]
As above.
Conclusion:
By using MATLAB Iir filter desgin is studied.
ztrans
ztransform
Syntax
F 
= ztrans(f) 
F 
= ztrans(f, w) 
F 
= ztrans(f, k, w) 
Description
F = ztrans(f) is the ztransform of the scalar symbol f with default independent variable n. The default return is a function of z.
The ztransform of f is defined as
where n is f's symbolic variable as determined by symvar. If f = f(z), then ztrans(f) returns a function of w.
F = F(w)
F 
= ztrans(f, w) makes F a function of the symbol w instead of the default z. 
F 
= ztrans(f, k, w) takes f to be a function of the symbolic variable k. 
Examples
ZTransform 
MATLAB Operation 

f(n) = n ^{4} 
syms n; 

f 
= n^4; 

ztrans(f) ans = (z^4 + 11*z^3 + 11*z^2 + z)/(z  1)^5 

g(z) = a ^{z} 
syms a z; 

g 
= a^z; 

ztrans(g) ans = w/(a  w) 

f(n) = sin(an) 
syms a n w; 

f 
= sin(a*n); 

ztrans(f, w) ans = (w*sin(a))/(w^2  2*cos(a)*w + 1) 
Viel mehr als nur Dokumente.
Entdecken, was Scribd alles zu bieten hat, inklusive Bücher und Hörbücher von großen Verlagen.
Jederzeit kündbar.