Matlab Practical
Matlab Practical
Roll No. : 09
University of Allahabad
Index
Sl. Experiment Name Date Page No. Teacher’s signature
No.
01 (i) Generate and plot sine wave
consisting of one frequency
only. Take 100 uniform
intervals in one cycle.
(ii) Generate and plot sine wave
consisting of one frequency
only. Take separation between
two points 0.05.
02 (i) Write a program for linear
convolution
03 (i) Write a program for
Autocorrelation
04 (i) Generate signals (Combination
of sine waves), add noise to
the generated signal. Plot it.
(ii) Plot the FFT of signal with and
without noise.
(i) Generate and plot sine wave consisting of one frequency only. Take 100
uniform intervals in one cycle.
(ii) Generate and plot sine wave consisting of one frequency only. Take
separation between two points 0.05.
Theory:
Let us consider the sinusoidal signal has fixed frequency (f) of 1Hz.
Time period = 1 Second
Since we have to take separation between two points = 0.05, thus sampling frequency
should be equal to 20 Hz.
>> fs = 10000;
>>ts = 1/fs;
>>t = 0:ts:0.01;
>>x=sin(2*pi*100*t);
>>subplot(2,1,1);
>>plot(t,x);
>>xlabel('Time');
>>ylabel('Amplitude');
>>title('Sinewave');
>>grid
Figure: 2
Experiment Number - 02
Object:
Theory:
k=∞
y[ n ] = ∑ x [ k ] h [n−k ]
k=−∞
MATLAB has a built in function conv to perform convolution of finite length sequences of
values. This function assumes that the two sequences have been defined as vectors and it
generates an output sequence that is also a vector. Convolving a sequence x[n] of length
N with sequence h[n] with length M results in a sequence of length L = M+N+1. The extent
of x [ n ]∗h[n] is equal to the extent of x[n] plus the h[n].
Syntax:
>>y=conv(x,h)
Where x and h are finite sequences written in vector form
Program:
>>x = [1 2 2 1 2]; nx = [-2:2];
>>h = [2 2 -1 1 2 2 1]; nh = [-3:3];
>>nmin = min(nx) + min(nh);
>>nmax = max(nx) + max(nh);
>>y = conv(x,h); n = [nmin:nmax];
>>stem(n,y, 'filled')
>>title('Convolution of two sequence')
>>xlabel('Index[n]')
>>ylabel('y[n]=x[n]*h[n]')
>>grid
Results:
The Convolution of two sequences is plotted in figure 1.
Theory:
Syntax:
>>y= xcorr(x)
Program:
>> %Program for sequence generation
>>%7 bit feedback register, feedback from [7,4]
>>%initial condition [1000000]
>>%length = 2^N-1 = 127
>>% initial condition
>>k=1;
>>length = 127;
>>s1(k) = 1;
>>s2(k) = 0;
>>s3(k) = 0;
>>s4(k) = 0;
>>s5(k) = 0;
>>s6(k) = 0;
>>s7(k) = 0;
>>for k=2:length
>>s1(k) = xor(s4(k-1),s7(k-1));
>>s2(k) = s1(k-1);
>>s3(k) = s2(k-1);
>>s4(k) = s3(k-1);
>>s5(k) = s4(k-1);
>>s6(k) = s5(k-1);
>>s7(k) = s6(k-1);
>>end
>>%change s7 to +1 and -1 volt
>>seq=2*s7-1;
>>n=1:length;
>>stairs(n,seq)
>>figure
>>m=7;
>>lag=2^m+2; %time shift limit
>>c=xcorr(seq,lag);
>>l=-lag:lag;
>>plot(l,c)
Results:
The maximal length sequence and its autocorrelation are plotted in figure 1 and
figure2.
Figure: 1 Maximal length sequence
Figure: 1 Autocorrelation
Experiment Number - 04
Object:
(i) Generate signal (Combinations of sine waves). Plot their FFT
(ii) Add AWGN noise and determine the spectrum of corrupted signal
Theory:
The signal is generated with frequency of 40 Hz and 150Hz. The sampling frequency was
selected more than highest signal frequency. Here I have selected the sampling frequency
of 1000Hz.
FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT
operation is applied to each column. For N-D arrays, the FFT operation operates on the
first non-singleton dimension.
FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated
if it has more.
Results:
(i) Signal generated and their FFT magnitude spectrum is shown in figure 1.
(ii) The corrupted signal by AWGN with their spectrum is shown in figure 2.
Figure 1: Signal with their spectrum
Theory:
1 n=0
δ [n] =
0 n≠0
Results: