DSP Experiments: Linear and Circular Convolution in MATLAB?

 Before performing the experiment, first learn about the basic terms related to the experiments.

Frequency: Frequency can be described the number of waves that pass a fixed place in a given amount of time. You can understand it by a simple example if the time taken for a wave to pass is 1/2 second, the frequency is 2 per second. If it takes 1/100 of an hour, the frequency is 100 per hour.

Harmonics: Harmonics are unwanted higher frequencies which superimposed on the fundamental waveform creating a distorted wave pattern.

What is Fundamental Frequency?

Fundamental Waveform (or first harmonic frequency) is the sinusoidal waveform that has the supply frequency. The fundamental is the lowest or base frequency, ƒ on which the complex waveform is built and as such the periodic time, Τ of the resulting complex waveform will be equal to the periodic time of the fundamental frequency.

Harmonics are higher frequency waveforms superimposed onto the fundamental frequency, that is the frequency of the circuit, and which are sufficient to distort its wave shape. The amount of distortion applied to the fundamental wave will depend entirely on the type, quantity and shape of the harmonics present.

Sinusoidal Components:

if two sinusoidal signals of differing frequencies are mixed, the resultant complex signal consists of a number of sinusoidal components. One component has a frequency which is equal to the difference between the two frequencies that were mixed and which is known as the beat frequency. Other sinusoidal components generated include the sum of the mixed frequencies, twice the higher frequency and twice the lower frequency, and numerous even higher frequency components of higher order

Convolution:

Convolution is a mathematical way of combining two signals to form a third signal. It is the single most important technique in Digital Signal Processing. Using the strategy of impulse decomposition, systems are described by a signal called the impulse response. Convolution is important because it relates the three signals of interest: the input signal, the output signal, and the impulse response.

Linear Convolution is a mathematical operation done to calculate the output of any Linear-Time Invariant (LTI) system given its input and impulse response. It is applicable for both continuous and discrete-time signals.

Circular convolution is essentially the same process as linear convolution except, it involves the operation of folding a sequence, shifting it, multiplying it with another sequence, and summing the resulting products. However, in circular convolution, the signals are all periodic. Thus, the shifting can be thought of as actually being a rotation. Since the values keep repeating because of the periodicity. Hence, it is known as circular convolution. It is applicable for both continuous and discrete-time signals.

 

For the better understanding of the MATLAB program, I have explained the meaning of the functions in the source code using comment.

 

Experiment -1A

Aim: Generate square wave of frequency (input from keyboard) from its harmonics of sinusoidal components.

%Source Code

clc;              % clear command window

clear all;     % clear workspace

close all;    % delete all previous figures

freq=input('Enter the frequency_');

n=input('Enter the number of harmonics_');

t=0:0.001:1;         %time

sq_wave=0;

for k=1:1:n

    harmonic=(4/pi)*(1/(2*k-1))*sin(2*pi*freq*(2*k-1)*t);

    sq_wave=sq_wave+harmonic;

end

plot(t,sq_wave);

title('Generation of Square wave by addition of its harmonics');

xlabel('time');

ylabel('Amplitude');


 Output:

 Enter the frequency_ 4

Enter the number of harmonics_10


                                           Fig. 1

  Enter the frequency_ 4

Enter the number of harmonics_50




                                                 Fig. 2

 

Experiment – 1B

Aim: Use PAUSE function for MATLAB to demonstrate the effect of addition of harmonics to its fundamentals.

%Source Code

clc;

close all;

freq=input('Enter the frequency');

n=input('Enter the number of harmonics');

t=0:0.001:1;

sq_wave=0;

title('Generation of Square wave by addition of its harmonics with pause function ');

for k=1:1:n

    harmonic=(4/pi)*(1/(2*k-1))*sin(2*pi*freq*(2*k-1)*t);

    sq_wave=sq_wave+harmonic;

    plot(t,sq_wave);

    pause(0.5);          % pause time is 0.5 seconds

end

 Output:

  Enter the frequency 4

Enter the number of harmonics 10

Fig. 3

 Enter the frequency 4

Enter the number of harmonics 50


                                                 Fig. 4


 

Experiment:02 (a)

Aim: Compute linear convolution of x[n]={1,2,1,0,2,1} for n>=0 and y[n]={2,4,0,1,1,0} n>=0;

 

clc;              % clear the command window

clear all;      % clear the workspace

first=input('Enter first sequence: ');

second=input('Enter second sequence: ');

len_first=length(first);

len_second=length(second);

N= len_first + len_second -1;

% appending zeroes to first sequence

x=[first zeros(1,N-len_first)];            

% appending zeroes to second sequence

y=[second zeros(1,N- len_second)]; 

lin_conv=ifft ( fft (x, N).*fft (y, N) ,N) ;

disp('The resultant convolution is');

 

Output of the Linear Convolution is:

Enter first sequence: [1 2 1 0 2 1]

Enter second sequence: [2 4 0 1 1 0]

% The resultant convolution is

2.00000000000000 8      10    5      7      13    5        2      3      1      6.45947941600091e-16

 

 

 

 

Experiment: 02(b)

Aim: Compute circular convolution of x[n]={1,2,1,0,2,1} for n>=0 and y[n]={2,4,0,1,1,0} n>=0;

%Source Code

clc;

clear all;

first=input('Enter first sequence: ');

second=input('Enter second sequence: ');

len_first=length(first);

len_second=length(second);

N=max(len_first,len_second);

x=[first zeros(1,N-len_first)];

y=[second zeros(1,N-len_second)];

cir_conv=ifft ( fft(x,N).* fft(y,N) ,N);

disp('The resultant of convolution is');

 

Output of the Circular Convolution is:

Enter first sequence:      [1 2 1 0 2 1]

Enter second sequence:  [2 4 0 1 1 0]

The resultant of convolution is

cir_conv =   7    10    13     6     7    13

 

 

 

 

Experiment: 02(c)

Aim: Signal sequence x[n]={1,1,1} is applied to a system with unknown impulse response h[n] with output y[n]={1,4,8,10,8,4,1}. Write a program to find h[n].

%Source Code

clc;

close all;

clear all;

signal=input('Enter signal sequence: ');

output=input('Enter output sequence: ');

len_signal=length(signal);

len_output=length(output);

N=max(len_signal,len_output);

x=[signal zeros(1,N-len_signal)];

y=[output zeros(1,N-len_output)];

impulse_response=  ifft( fft(y,N) ./ fft(x,N) ,N);

impulse_response

xlabel('Samples');

ylabel('Amplitude');

title('Impulse response');

 

Output:

Enter signal sequence: [1 2 1 0 2 1]

Enter output sequence: [7 10 13 6 7 13]

impulse_response =

    2.0000    4.0000    0.0000    1.0000    1.0000    0.0000

 

 

Post a Comment

1 Comments