DSP LAB
DSP LAB
clear all;
close all;
plot(x, y);
title('Sine Wave');
xlabel('Angle (radians)');
ylabel('sin(x)');
grid on;
clear all;
close all;
t = -10:10;
impulse_signal = zeros(size(t));
for i = 1:length(t)
if t(i) == 0
impulse_signal(i) = 1;
end
end
stem(t, impulse_signal);
title('Unit Impulse Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
//EXPLANATION -> This MATLAB code generates a unit impulse signal and plots it using the stem function. Here's an
1. **Initialization**:
- `clear all; close all;` are used to clear any existing variables and figures in the MATLAB workspace.
2. **Time Index**:
- `t = -10:10;` defines a time range from -10 to 10. This range determines the duration of the signal.
4. **Plotting**:
- `stem(t, impulse_signal);` plots the unit impulse signal.
- `title('Unit Impulse Signal');` sets the title of the plot.
- `xlabel('Time'); ylabel('Amplitude');` sets the labels for the x-axis and y-axis, respectively.
- `grid on;` displays the grid on the plot for better readability.
5. **Result**:
- The plot shows a unit impulse signal with an amplitude of 1 at the time instant t=0 and 0 elsewhere. The stem fun
###3 LAB. Unit Step Signal
clear all;
close all;
t = -10:10;
step_signal = zeros(size(t));
for i = 1:length(t)
if t(i) >= 0
step_signal(i) = 1;
end
end
stem(t, step_signal);
title('Unit Step Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
//EXPLANATION
This MATLAB code generates a unit step signal and plots it using the stem function. Here's an explanation of the cod
1. **Initialization**:
- `clear all; close all;` are used to clear any existing variables and figures in the MATLAB workspace.
2. **Time Index**:
- `t = -10:10;` defines a time range from -10 to 10. This range determines the duration of the signal.
4. **Plotting**:
- `stem(t, step_signal);` plots the unit step signal.
- `title('Unit Step Signal');` sets the title of the plot.
- `xlabel('Time'); ylabel('Amplitude');` sets the labels for the x-axis and y-axis, respectively.
- `grid on;` displays the grid on the plot for better readability.
5. **Result**:
- The plot shows a unit step signal with an amplitude of 1 for times greater than or equal to 0, and 0 for times less t
nature of the signal.
####4 LAB .growing exponential signal without using inbuilt libraryof exp function in digtal signal processing lab ma
% Parameters
A = 1; % Amplitude
alpha = 0.1; % Growth rate
N = 100; % Number of samples
n = 0:N-1; % Time index
//EXPLANATION
Certainly! Here's an explanation of the code:
1. **Parameters**:
- `A`: Amplitude of the exponential signal.
- `alpha`: Growth rate of the exponential signal.
- `N`: Number of samples to generate.
- `n`: Time index from 0 to `N-1`.
2. **Initialization**:
- We initialize an array `x` of size `N` to store the values of the exponential signal.
3. **Signal Generation**:
- We use a `for` loop to iterate from 1 to `N`.
- For each iteration `i`, we calculate the value of the exponential signal at index `i` using the formula \( A \times (1
4. **Plotting**:
- We use the `stem` function to plot the generated signal `x` against the time index `n`.
- The x-axis represents the time index `n`, and the y-axis represents the amplitude of the signal.
- The title of the plot is "Growing Exponential Signal (Approximated)".
###5 LAB. Plot a decaying exponential signal without using inbuilt library of exp function in digtal signal processing l
% Parameters
A = 1; % Amplitude
alpha = -0.1; % Decay rate (negative for decay)
N = 100; % Number of samples
n = 0:N-1; % Time index
1. **Parameters**:
- `A`: Amplitude of the decaying exponential signal.
- `alpha`: Decay rate of the exponential signal (negative for decay).
- `N`: Number of samples to generate.
- `n`: Time index from 0 to `N-1`.
2. **Initialization**:
- We clear any existing variables and close any open figures using `clear all; close all;`.
3. **Signal Generation**:
- We initialize an array `x` of size `N` to store the values of the decaying exponential signal.
- The `for` loop iterates over each element of `n` (from 1 to `N`).
- For each iteration `i`, we calculate the value of the decaying exponential signal at index `i` using the formula \(
4. **Plotting**:
- We use the `stem` function to plot the decaying exponential signal `x` against the time index `n`.
- The x-axis represents the time index `n`, and the y-axis represents the amplitude of the signal.
- We set the title of the plot to "Decaying Exponential Signal (Approximated)" using `title('Decaying Exponential Sign
- We set the labels for the x-axis and y-axis using `xlabel('n'); ylabel('Amplitude');`.
###6 LAB.PLOT THE CIRCULAR CONVOLUTION FOR THE TWO SEQUENCES WITH FOUR VALUES OF INPUT IN MATLAB
//EXPLANATION
Here's an explanation of the code for calculating and plotting the circular convolution of two sequences with four val
1. **Input Sequences**:
- `x = [1, 2, 3, 4];` and `h = [0.5, 0.2, 0.1, 0.3];` define two sequences with four values each. These are the sequence
3. **Plotting**:
- `stem(0:3, y);` plots the circular convolution result `y` against the index (0 to 3). The `stem` function is used to c
values.
5. **Grid**:
- `grid on;` adds a grid to the plot for better readability, making it easier to see the values of the convolution result
####7.PLOT THE DISCRETE FOURIER TRANSFORM FOR A FOUR POINT SEQUENCE ON A MATLAB CODE
//EXPLANATION
Here's an explanation of the code for calculating and plotting the Discrete Fourier Transform (DFT) of a four-point se
1. **Input Sequence**:
- `x = [1, 2, 3, 4];` defines a four-point sequence for which we want to calculate the DFT.
2. **DFT Calculation**:
- `X = fft(x);` calculates the DFT of the input sequence `x` using the Fast Fourier Transform (FFT) algorithm. The res
3. **Magnitude Plotting**:
- `stem(0:3, abs(X));` plots the magnitude of the DFT coefficients. The `abs` function is used to calculate the magn
- The x-axis represents the frequency index `k`, which ranges from 0 to 3 for a four-point DFT.
- The y-axis represents the magnitude of the DFT coefficients.
5. **Grid**:
- `grid on;` adds a grid to the plot for better readability, making it easier to see the values of the DFT coefficients.