Open In App

Circular Convolution using C and MATLAB

Last Updated : 02 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Involvement in preparing for and utilizing the modulator of the flag can be explained using the term circular convolution. It is a convolution technique that assumes signals to repeat themselves throughout, which makes it quite effective in cyclic data applications or signal systems that are folding back from end to start. This fact is important in various real-life situations like periodic signal analysis, digital filter design, and efficient implementation of convolution through Fast Fourier Transform (FFT).

In this article, we will look at what circular convolution means and discuss about its definition, types, working principle as well as components involved among others. The article will also show how C and MATLAB languages have been used to implement the concept of circular convolution with relevant examples and diagrams provided for easy understanding. By the time readers finish going through this piece of writing they will have got comprehensive knowledge on circular convolution’s applications and importance with respect to signal processing field.

What is Circular Convolution?

Another name for circular convolution is cyclic convolution; it happens when input signals are treated as if they are cyclical. On the other hand, linear convolution assumes that the signals persist into infinity with zero padding whereas circular convolution assumes that the signals continue from the start again when they reach at the end. For two periodic discrete-time signals x[n] and h[n]with period N, numerically, y[n] is defined as:

y[n] = (x ∗ h)[n] = m=0n=1 x[m] h [(n−m) mod N]

Types of Circular Convolution

Several types of circular convolutions exist based on different characteristics in their input.

  1. Discrete-Time Circular Convolution: Involves periodic discrete signals.
  2. Continuous-Time Circular Convolution: Deals with continuous periodic signals.
  3. Cyclic Convolution in Finite Fields: Used in coding theory and cryptography.

Working Principle

Steps involved in circular convolution are:

  1. Period Expansion: Present input signals in the form of discontinuities.
  2. Shifting and Wrapping: Move one signal by a single sample and wrap it back on itself when it reaches the end.
  3. Element-wise Multiplication and Summation: Multiply corresponding elements of the signals together then summing them to give each value of the output signal.

Parameters of Circular Convolution

  • Input Signals: Signals that are being convolved.
  • Shift Register: Something that moves the signals along and wraps them round at each end as they do so.
  • Multiplier: It multiplies items element-by-element.
  • Accumulator: Sums the bits together to obtain outgoing signal

Construction

To set up a circular convolution system, you should have:

  1. Something for representing and storing periodic signals .
  2. Something for doing cyclic shifts with wrapping points (the logic).
  3. Multipliers that do operations like multiplication between respective items.
  4. A collector, which combines duplications during wrap arounds

Key Terminologies

  • Periodicity: Signal repeats itself after every defined period.
  • Modulo Operation: This is useful in implementing wrapping around in circular convolution processing method.
  • Circular Shift: A signal whose elements have been shifted with wrapping taking place.

Examples

Example in C

C
#include <stdio.h>

void circularConvolution(int x[], int h[], int y[],
                         int size)
{
    for (int i = 0; i < size; i++) {
        y[i] = 0;
        for (int j = 0; j < size; j++) {
            y[i] += x[j] * h[(i - j + size) % size];
        }
    }
}

int main()
{
    int x[] = { 1, 2, 3, 4 };
    int h[] = { 5, 0, 0, 0 };
    int n = 4;
    int y[n];

    circularConvolution(x, h, y, n);

    for (int i = 0; i < n; i++) {
        printf("%d ", y[i]);
    }
    return 0;
}

Output
5 10 15 20 
output for C code

Example in MATLAB

Matlab
x = [1, 2, 3, 4];
h = [5, 0, 0, 0];
N = length(x);
y = zeros(1, N);

for n = 1:N
    for m = 1:N
        y(n) = y(n) + x(m) * h(mod(n - m, N) + 1);
    end
end

disp(y);

Output

5 10 15 20
4
Output

Advantages and Disadvantages

Advantages

  • Fast computation using FFT algorithmic approach is employed herein,
  • Ideal for periodic waveform analysis purposes,
  • Implementation becomes very easy while working on digital filters design or realization,
  • Cyclic data handling can be attained.
  • Some applications may have computational complexity reduced.

Disadvantages

  • It can’t be used for non-periodic signals.
  • Signal wrapping needs to be properly dealt with.
  • The latter causes artifacts in the output.
  • Linear convolution, compared to circular convolution, has a wider range of application areas.
  • Difficulties in understanding and execution.

Applications

  1. Designing digital filters
  2. Processing signals in communication systems
  3. Audio signal processing
  4. Processing images
  5. Convolutional neural networks
  6. Periodic data analysis
  7. Error detection and correction in coding theory
  8. Cryptographic algorithms
  9. Radar signal processing
  10. Biomedical signal processing

Differences between Linear Convolution and Circular Convolution

Aspect

Linear Convolution

Circular Convolution

Signal Extension

Expect zero cushioning past the length of the flag.

Assumes periodic extension of the signal.


Length of Result

The result length is N+M−1 for input signals of lengths N and M.

The result length is the same as the input flag length, N.

Computation Complexity

Requires more operations due to longer result length and zero padding.

More efficient with fewer operations due to periodic extension.


Application Context

Used in systems where the signals do not repeat, like image processing, audio signal processing.

Ideal for systems involving periodic or cyclic data, such as digital communications and filter design.


Frequency Domain

Linear convolution corresponds to multiplication in the frequency domain after zero-padding and taking the FFT of both signals.

Circular convolution corresponds to element-wise multiplication in the frequency domain without additional zero-padding, using the FFT directly.


Artifacts

No wrapping artifacts, but edge effects due to zero padding can occur.

Potential wrapping artifacts if signals are not properly handled, but avoids edge effects seen in linear convolution.


Implementation

Can be implemented using straightforward multiplication and summation, but less efficient compared to circular convolution for long signals.

Can be efficiently implemented using FFT, which converts convolution into element-wise multiplication in the frequency domain, significantly speeding up computation.


Conclusion

Circular Convolution is a very important operation in signal processing specially when dealing with periodic signals or cyclic data. Its fast computation using FFT makes it indispensable for a number of applications ranging from digital filters to communication systems. Understanding its basic principles, merits and drawbacks will help to realize its potential fully as an essential tool under consideration.


Next Article

Similar Reads