To create a transfer function ( H(w) ) that is 1 for ( w ) in the range ([-2000, 2000]) and 0 otherwise, you can use the following MATLAB code. This code will create an array H of size 20001, where the values are set according to the specified conditions.
Here's the complete MATLAB code:
w = linspace(-5000, 5000, 20001);
H(w >= -2000 & w <= 2000) = 1;
disp('Transfer function H(w):');
title('Transfer Function H(w)');
Explanation
- Define the Frequency Range: Use linspace to create an array w of 20001 points ranging from -5000 to 5000. This ensures that we have enough points to cover the range and set the values accordingly.
- Initialize the Transfer Function: Create an array H of zeros with the same length as w.
- Set the Values of H(w): Use logical indexing to set the values of H to 1 for the range ([-2000, 2000]). The condition w >= -2000 & w <= 2000 identifies the indices where w is within the desired range.
- Display the Result: Use disp to display the resulting transfer function array.
- Plot the Transfer Function: Plot the transfer function using plot to visualize the values of H(w) over the frequency range.
Notes
- The linspace function generates linearly spaced vectors. Here, it is used to create a range of frequencies from -5000 to 5000 with a total of 20001 points.
- The logical indexing w >= -2000 & w <= 2000 is used to set the values of H to 1 for the specified range of w.
- The plot helps to visualize the transfer function, showing that it is 1 within the specified range and 0 outside of it.