Department of Electrical Engineering Communication Systems
Dr. Muhammad Mahboob Ur Rahman
21-09-2016 7th
Waseem Abbas Sanan Ahmad
LAB-2
Name
BSEE-13
Convolution, Correlation, Energy and Power of Signals
Reg. No.
Report Marks (5)
LAB Performance (5)
Viva Marks (5)
Total (15)
9|Page
Convolution, Correlation, Energy and Power of Signals 2.1
Objective To learn how we can compute the convolution, correlation, energy and power of the signals
2.2
Equipment/Apparatus 2.
2.3
Software: Matlab
Theory and Procedure
Following are the terms mostly used in Communication Systems
2.3.1
Convolution
Convolution describes the relationship between the input signal X[n], the impulse response H[n] of an LTI system, and the output o utput signal Y[n] (see Figure 2-1).
Linear System X[n]
Y[n]
H[n]
[] ⨂ [] = [ [] Figure 0-1 Convolution
In mathematical notation, convolution is described as:
[] = [] ⨂ [] The Matlab function used for Convolution is “ conv”. C = conv (A, B) convolves vectors A and B and saves the output in vector C. Example: a = [1 0 3 1]; b = [2 3 1 0] ; d=conv(a, b)
Result:
d = 2
2.3.2
3
7
11
6
1
0
Correlation
Correlation is a mathematical operation that is very similar to convolution. Just as with convolution, correlation uses two signals to produce a third signal. It shows how much similar or different are the two signals when compared with each other. The output signal is called the cross-correlation of the two input signals. If a signal is correlated with itself, the resulting output signal is instead called the autocorrelation.
Autocorrelation, also known as serial correlation, is the correlation of a signal with itself when second copy of the signal is delayed compared to the first one. In other words, auto-correlation is the measure of similarity between the two copies of the same signal as a function of the time lag between them.
10 | P a g e
The Matlab command used for correlation is “xcorr”.
Example: Find the autocorrelation and cross-correlation of x and y. x = [1 0 0 0 0]; y = [0 0 1 0 0]; [xcorr_a n] = xcorr(x, x) subplot(221) stem(n, xcorr_a) xlabel('tau' xlabel( 'tau') ) ylabel('auto-corelation ylabel( 'auto-corelation of x' ) [xcorr_a n] = xcorr(y, y) subplot(222) stem(n, xcorr_a) xlabel('tau' xlabel( 'tau') ) ylabel('auto-corelation ylabel( 'auto-corelation of y' ) [xcorr_a n] = xcorr(x, y) subplot(223) stem(n, xcorr_a) xlabel('tau' xlabel( 'tau') ) ylabel('cross-cor ylabel( 'cross-corelation elation of x and y' )
Figure 0-2 correlation
2.3.3
Energy and Power of the Signal Energy and power of the signal is calculated by the following formulae
=+∞
∑ | [] |2 =−∞
11 | P a g e
=+ 1 →∞ lim 2 1 ∑ | [] | 1 =− Here T = duration of the signal, and x[n] denotes discrete samples of the signal at regular intervals (The sampled signal contains N points stretching from 0 to N-1). “NORM” function in Matlab can be utilized for calculating the power or energy content of a signal.
=−
( (, ) ( ∑ |()| )/ =
=−
( () ( (, 2) ( ∑ |()| )/ =
Example %Syntax: (Extracted from Matlab help) %NORM(V, P) = sum(abs(V).^P)^(1/P). %sample to calculate Energy and Power T=10; Ts=0.001; Fs=1/Ts; t=[0:Ts:T];
%Total evaluation time %Sampling time => 1000 samples per second % Sampling period %define simulation time
%sample function to calculate Energy and Power x=cos(2*pi*100*t) + cos(2*pi*200*t) + sin(2*pi*300*t); energy = (norm(x)^2); power = (norm(x)^2)/length(x);
Results: energy = power =
2.3.4
1.5004e+04 1.5002
Orthogonality
In mathematics, In mathematics, orthogonality orthogonality is the relation of two lines at right at right angles to one another (perpendicularity), (perpendicularity), and the generalization of this relation into n dimensions; and to a variety of mathematical relations thought of as describing non-overlapping, non-overlapping, uncorrelated, or independent or independent objects of some kind. In communications, multiple-access schemes are orthogonal when an ideal receiver can completely reject arbitrarily strong unwanted signals from the desired signal using different basis different basis functions. The dot product of orthogonal signals is zero. If we have two orthogonal signals x and y, then following equation satisfies:
⃗.⃗ 0 Consider you are transmitting two signals using same frequency. There will be interference between these two signals if they are not orthogonal. Orthogonality means both signal is having phase difference of 90 degrees. Hence, it will not interfere each other. Just like CDMA, all the channels are orthogonal and hence we can use same frequency allocation for all users but signals are decoded based on PN sequence which is used for spreading the signal. Orthogonal signaling uses carriers which do not correlate with each other (inner product or mean of mutual multiplication is zero). In case of non-dispersive channel this signaling is 12 | P a g e
very efficient, since there is no interference between carriers. However, most of real-life channels are dispersive and inter-carrier interference is present. Moreover, orthogonal signaling is much more sensitive to synchronization errors than non-orthogonal one. 2.3.5
Shannon’s Formula
The Shannon –Hartley theorem states the channel the channel capacity C , meaning the theoretical tightest upper bound on the information the information rate of data that can be communicated at an arbitrarily low error low error rate using an average received signal power S through an analog communication channel subject to additive to additive white Gaussian noise of power N:
= ∗ log2 (1 + )
Where, second, a theoretical upper bound on the net bit C is C is the channel capacity in bits per second, rate (information rate, sometimes denoted I) excluding error-correction codes; the bandwidth of the channel in hertz in hertz (passband bandwidth in case of a bandpass signal); B is the bandwidth S is the average received signal power over the bandwidth (in case of a carrier-modulated passband transmission, often denoted C ), measured in watts (or volts squared); N is the average power of the noise and interference over the bandwidth, measured in watts (or volts squared); and S/N is is the signal-to-noise the signal-to-noise ratio (SNR) or the carrier-to-noise the carrier-to-noise ratio (CNR) of the communication signal to the noise and interference at the receiver (expressed as a linear power ratio, not as logarithmic decibels) logarithmic decibels).. Example:
Plot capacity of the channel: i)
As a function of SNR (vary SNR between -10 to 30 dB, but then convert it into linear scale)
ii)
As a function of BW (vary it between 10KHz to 20 MHz)
B=10^3:10^3:10^6 SNRdb=10 SNR=db2mag(SNRdb) C = B * log2(1+SNR); subplot(2,1,1) plot(B,C); xlabel('Bandwidth xlabel( 'Bandwidth (Hertz)') (Hertz)' ) ylabel('Channel ylabel( 'Channel Capacity (Bits per Second)') Second)' ) %================= B=10^3 SNRdb=-10:30 SNR=db2mag(SNRdb) C = B * log2(1+SNR); subplot(2,1,2) plot(SNR,C); xlabel('SNR' xlabel( 'SNR') ) ylabel('Channel ylabel( 'Channel Capacity (Bits per Second)' Second)') )
13 | P a g e
Figure 0-3 Channel Capacity
2.4
Exercise
Write the codes of following exercises. Print the codes and results with proper labeling. Attach it with the manual TASK-1:
One of the most immediate and impressive applications of convolution ca n be found in the techniques of digital audio processing. In the past 15 years, a variety of tools using convolution have been developed and popularized. The task is to convolution of audio files.
1.
https ps :/ :///go goo.g o.g l/h7wc G Z Go to the following link and download audios: htt
2.
Import the input wave file x[n]. clapstereo = wavread('/
/clap wavread('//clap.wav') .wav')
[Note: you have to add the t he Wavefile folder to the path. Select “Selected Folders”. See figure 2-6]
14 | P a g e
Figure 0-4 Add to Path instructions
3.
The audios will be shown in two columns. Each of these columns represents a column vector in the matrix, corresponding to an audio channel(L/R). This file is a stereo file (it contains left and right channel information) and so we will need to strip out the left channel. Type the following clapmono = clapstereo(:,1)
4.
Next, do the same procedure with the impulse response H(n) file hallstereo = wavread('/LongE wavread('/LongEchoHallIR.wav') choHallIR.wav') hallmono = hallstereo(:,1)
5.
Now convolute the X[n] and H[n] out1 = conv(clapmono, hallmono)
6.
Before we can write this to a new file, we must normalize this vector so that none of its entries is bigger than 1 in absolute value. This is because .wav files require the amplitude of all waveforms to be between -1 and 1. (Note: Waveforms which 'clip'(exceed the maximum level) are not useful, as they play back with ugly digital distortion. This is to be avoided, always, when working with digital audio). To normalize the vector, we write: % max(v) = absolute value of largest entry of v out1normalized = out1/max(out1)
7.
We now have a vector ve ctor which is suitable to be exported! Let's write this to a file: %The second parameter is the sample rate wavwrite(out1normalized, 44100, '/out1.wav')
8. 9.
Use Hands-free (ear-in or earbuds) to listen to the audio Now do the same for “clap” and “ drumloop” sound or some other combinations of your
liking. TASK-2:
Find auto-correlation and cross-correlation of PN_seq and show results in the form of graph (Like the Example given in correlation i.e. section 2.3.2). PN_seq_1 = randn(10,1)
15 | P a g e
PN_seq_2 = randn(10,1) TASK-3:
Execute the following code and explain the difference between convolution and correlation. x = [1 2 3 4]; y = [-1 2 1 -1]; conv(x,y) conv(fliplr(x),y) xcorr(x,y)
TASK-3:
Find whether or not Sin(x) and Cos(x) are orthogonal or not for period of 0 ≥ t ≥ 2π. And also find orthogonality of Sin(x) with Sin(2x) and Sin(3x) for period of 0 ≥ t ≥ 2π. Show results in the form of o f graphs. [Hint: Specify the argument x in radians, not in degrees. For example, use π to specify an angle of 180 o. Use dot (a, b) or sum(x.*y)] TASK-4:
Compute the effect of doubling the bandwidth BW and doubling the SNR on channel capacity (using Shannon’s formula) and see which parameter (among BW and SNR) has dominating effect. SNR: -10 dB, Bandwidth: 20KHz TASK-5:
Calculate RMS value of signal: Sin(2x) from 0 to 2 π.
2.5
Student Learning Outcomes What you have learnt in the lab? Describe.
16 | P a g e