You are on page 1of 7

Digital Signal Processing Lab 21EC42 (expts which are not present in manual)

1. "Verification of linear property circular time shift property and circular frequency
shift property of DFT".
**Aim:**
The aim of this code is to demonstrate and verify three important properties of the Discrete Fourier
Transform (DFT): the linear property, circular time shift property, and circular frequency shift property. By
implementing these properties in code and performing mathematical comparisons, the code aims to show
that the DFT behaves as expected when subjected to various transformations.

**Objectives:**
1. Implement a basic Scilab script that generates a sample signal and computes its DFT.
2. Verify the linear property of the DFT by demonstrating that the DFT of the sum of two signals is equal
to the sum of their individual DFTs.
3. Verify the circular time shift property by confirming that a circular shift in the time domain results in a
phase shift in the frequency domain.
4. Verify the circular frequency shift property by confirming that a frequency-shifted signal in the time
domain corresponds to a phase-shifted DFT.

**Algorithm:**
1. Define the parameters:
- Choose the number of samples `N`.
- Create a vector of time indices `n` from 0 to `N-1`.

2. Generate the input signal:


- Define a sample input signal (e.g., a sine wave) as `x = sin(2*%pi*0.25*n)`.

3. Compute the DFT:


- Calculate the DFT of the input signal using `X = fft(x)`.

4. Verify the Linear Property:


- Generate two new signals, e.g., `x1 = sin(2*%pi*0.25*n)` and `x2 = cos(2*%pi*0.25*n)`.
- Compute the DFTs of `x1` and `x2` as `X1 = fft(x1)` and `X2 = fft(x2)`.
- Calculate the sum of `X1` and `X2` as `X_sum = X1 + X2`.
- Compare the sum `X_sum` with the original DFT `X` using the norm of their difference.

5. Verify the Circular Time Shift Property:


- Define a circular shift amount `k`.
- Perform circular shifting of the input signal using the `circularShift` function.
- Compute the DFT of the shifted signal as `X_shifted = fft(x_shifted)`.
- Calculate the expected DFT after circular time shifting: `expected_X_shifted = X .* exp(-
%i*2*%pi*k*n/N)`.

6. Verify the Circular Frequency Shift Property:


- Define a frequency shift amount `k0`.
- Perform frequency shifting of the input signal in the time domain.
- Compute the DFT of the frequency-shifted signal as `X_freq_shifted = fft(x_freq_shifted)`.
- Calculate the expected DFT after circular frequency shifting by circularly shifting `X` as
`expected_X_freq_shifted = X(circularShift(1:N, -k0))`.
- Compare `X_freq_shifted` with `expected_X_freq_shifted` using the norm of their difference.

7. Display the Results:

This algorithm implements the verification of the linear property, circular time shift property, and circular
frequency shift property of the Discrete Fourier Transform using a sample Scilab code. The objectives are
met by comparing the expected results with the computed results using norms of differences.

Code:
function x = circularShift(signal, k)
n = length(signal);
k = mod(k, n); // Ensure k is within the range [0, n-1]
x = [signal(n-k+1:n), signal(1:n-k)];
endfunction

N = 8; // Number of samples
n = 0:N-1; // Time indices

// Define a sample input signal (e.g., a sine wave)


x = sin(2*%pi*0.25*n);

// Compute the DFT of the input signal


X = fft(x);

// Linear Property: x1[n] + x2[n] -> X1[k] + X2[k]


x1 = sin(2*%pi*0.25*n);
x2 = cos(2*%pi*0.25*n);
X1 = fft(x1);
X2 = fft(x2);
X_sum = X1 + X2;

disp("Linear Property:");
disp(norm(X - X_sum)); // Check if X = X1 + X2

// Circular Time Shift Property: x[n-k] -> X[k] * exp(-j*2*pi*k*n/N)


k = 2; // Circular shift amount
x_shifted = circularShift(x, k);
X_shifted = fft(x_shifted);
expected_X_shifted = X .* exp(-%i*2*%pi*k*n/N);

disp("Circular Time Shift Property:");


disp(norm(X_shifted - expected_X_shifted)); // Check if X_shifted = X * exp(-j*2*pi*k*n/N)

// Circular Frequency Shift Property: x[n] * exp(j*2*pi*k*n/N) -> X[k-k0]


k0 = 2; // Frequency shift amount
x_freq_shifted = x .* exp(%i*2*%pi*k0*n/N);
X_freq_shifted = fft(x_freq_shifted);
expected_X_freq_shifted = X(circularShift(1:N, -k0));

disp("Circular Frequency Shift Property:");


disp(norm(X_freq_shifted - expected_X_freq_shifted)); // Check if X_freq_shifted = X(k - k0)

Conclusion:
The Scilab code demonstrated that the DFT satisfies the linear property, circular time shift property, and
circular frequency shift property, validating its fundamental properties in signal processing and analysis.

1. Computation of linear convolution of two sequences using the Inverse Discrete


Fourier Transform (IDFT).

**Aim:**
The aim of this code is to compute the linear convolution of two sequences using the Inverse Discrete
Fourier Transform (IDFT). By implementing this process, the code aims to demonstrate how the
convolution operation can be performed in the frequency domain and then transformed back to the time
domain.
**Objectives:**
1. Implement a Scilab script that computes the IDFT of the product of DFTs of two sequences to achieve
linear convolution.
2. Demonstrate how linear convolution in the time domain corresponds to multiplication in the frequency
domain.
3. Verify that the result obtained using the IDFT matches the result obtained using the conventional linear
convolution operation.

**Algorithm:**
1. Define the input sequences:
- Define two input sequences, for example, `x` and `h`.

2. Compute the DFTs:


- Calculate the DFTs of both input sequences using the `fft` function:
- `X = fft(x)`
- `H = fft(h)`

3. Perform frequency domain multiplication:


- Multiply the corresponding elements of the DFTs `X` and `H` to get the frequency domain result
`Y_freq`:
- `Y_freq = X .* H`

4. Compute the IDFT:


- Calculate the IDFT of the frequency domain result `Y_freq` using the `ifft` function:
- `y_conv = ifft(Y_freq)`

5. Display the Results:


- Print the resulting sequence `y_conv`, which represents the linear convolution of sequences `x` and `h`.

**Scilab Code:**
```scilab
// Define the input sequences
x = [1, 2, 3, 4];
h = [0.5, 0.25, 0.125];

// Compute the DFTs of the input sequences


X = fft(x);
H = fft(h);

// Perform frequency domain multiplication


Y_freq = X .* H;

// Compute the IDFT to get the linear convolution result


y_conv = ifft(Y_freq);

// Display the results


disp("Input Sequence x:");
disp(x);
disp("Input Sequence h:");
disp(h);
disp("Linear Convolution using IDFT:");
disp(real(y_conv)); // Display the real part of the result
‘’’
Conclusion:
The code employs IDFT to compute linear convolution of input sequences. It highlights the frequency-
domain multiplication's equivalence to time-domain convolution, reinforcing the connection between these
fundamental signal processing operations.

3."Computation of circular convolution of two given sequences using IDFT"

**Aim:** Compute circular convolution using IDFT for efficient sequence convolution.

**Objective:** Implement circular convolution by multiplying sequences in frequency domain using IDFT
for accurate and faster convolution results.

**Algorithm**

Inputs:
- Two input sequences, x and h, each of length N.

1. Check if the lengths of sequences x and h are the same.


- If not, raise an error indicating that the sequences must have the same length.

2. Calculate the FFT (Fast Fourier Transform) of sequence x using the `fft` function, and store it in X.

3. Calculate the FFT of sequence h using the `fft` function, and store it in H.

4. Perform point-wise multiplication in the frequency domain.


- Multiply the corresponding elements of X and H element-wise to obtain a new sequence Y.
5. Calculate the Inverse FFT (IDFT) of sequence Y using the `ifft` function.
- Store the result in the circularConvolution variable.

6. Output the circularConvolution sequence, which represents the circular convolution of sequences
x and h.

**Code**

function circularConvolution = circular_convolution(x, h)


N = length(x);
if N <> length(h)
error("Input sequences must have the same length.");
end

X = fft(x);
H = fft(h);

Y = X .* H; // Point-wise multiplication in the frequency domain

circularConvolution = ifft(Y);
endfunction

// Example usage
x = [1, 2, 3, 4];
h = [0.5, 0.5, 0.5, 0.5];

result = circular_convolution(x, h);


disp("Circular Convolution Result:");
disp(result);
x = [1, 2, 3, 4];
h = [0.5, 0.5, 0.5, 0.5];
result = circular_convolution_using_idft(x, h);
disp(result);
**Conclusion:** The code successfully demonstrates circular convolution through IDFT, showcasing
its effectiveness in achieving precise and efficient sequence convolution.

You might also like