Lab 5
Lab 5
For a single pole radius draw the poles and zeros on a zero-pole plot by hand. Draw the
magnitudetransfer function |𝐻(𝜔)| of the above zero-pole plot over a range of 0 to pi. Given the
poles and zeros above find the transfer function 𝐻(𝜔) (USE A GENERIC POLE RADIUS 𝑅 or 𝑅𝑝
WHEN WRITING THELOCATIONS OF THE POLES IN THE TRANSFER FUNCTION). Simplify the
transfer function like what was done between Equation 3 and Equation 4.
Based on the given characteristics of the bandpass filter, I was able to find that the zeros should be
located at ω equals 0 and π and that the center frequency of the filter should be π/2; therefore, the
poles should beplaced on the imaginary axis and can be varied in magnitude from 0 to 1 to ensure
stability. Figure 1 below shows the handwritten work to calculate the frequencies of the filter and to
show what the pole zero plot should look like with a generic radius, R
Task 2.2: Normalize the transfer function at z = ejπ/2(i.e. Let 𝐻(𝑒𝑗𝜋2) = 𝐶 then define our
transferfunction to be H(z)/C. Plot the magnitude of the normalized transfer function in Matlab
over a range of [0,π] (Hint: Use w = 0 : 0.01 : π, z = exp(1i ∗ w), and the abs() function). Plot the
phase response of thenormalized transfer function in Matlab over a range of [0, π] (Hint: Use w
= 0:0.01:π, z = exp(1i ∗ w), andthe angle() function. Plot the zeros and poles using the zplane()
function.
I normalized the above transfer function by dividing the by the value of H(ω) at the center frequency
whichwas π/2. Figure 3 below shows the phase and magnitude response of the normalized transfer
function.
Task 2.3: Plot the -3db down bandwidth as a function of the poles’ radius 𝑅, choose a good
interval for incrementing 𝑅, why can’t some of these points be plotted?
Answer:To obtain the -3dB down bandwidth plot as a function of the pole radius R, I created a
numeric search method in MATLAB. I varied the value of R from 0 to 1 to visualize the bandwidth
throughout the entire stable region of the filter. Then I calculated the normalized transfer function
for each value of R and found the maximum value of the normalized H(ω) function. I then
subtracted a value of max(H(ω))/sqrt(2) – the corresponding -3dB value – from the entire array of
H(ω) and found the zeros of the resulting array. The indices of these zeros (or near zeros) were used
to return the starting and ending frequency values of the bandwidth. Finally, I plotted the bandwidth
values against the pole radius R to obtain the plot shown in Figure below.
The plot shows that the -3dB down bandwidth drops to nearly zero as the pole radius is increased
towards one. This is as expected as pushing the poles closer to the unit circle creates a sharper
bandpass peak while ensuring that the system is still stable. One interesting characteristic of this
plot is that there is a near linear relationship between R value and bandwidth for a large selection of
R values.
Task 2.4: Determine the coefficients of the difference equation for Direct Form 1 using
Equation 11 andEquation 12. Implement Direct Form 1 in C code and verify the filter shape
using a pulse wave and an FFT( Hint: Use a square wave with f=250Hz, A=1Vpp, Offset=0.5V,
Duty=0.4 percent for the pulse).
Answer: I was able to get both Direct Form I and Direct Form II to filter the signal. I tested a sinusoid
frequency input to confirm the characteristics of the bandpass filter. The filter passed the 12kHz
signal with unit gain and did not pass a 24kHz signal. The 24kHz sinusoid varied from full magnitude
to zero magnitude due to slight differences in true phase, but this confirms that the filter is having
an effect at this frequency. In the MATLB script, I implemented a solver to output the pole
locations, the normalized transfer function, and the direct form coefficients based on varying the
radius of the poles. In theory, extending the poles towards the unit circle would help give the
clearest peak at the center frequency.I implemented these coefficients and direct form I in the C
code included in Appendix A at the end of thisreport. Figure below shows the filter results along
with the oscilloscope’s built-in FFT function.
The oscilloscope output confirms that there is a band pass filter being applied to the signal. Since
the curvei n the FFT graph extends from 0 to 24 kHz and is centered on 12kHz, this is representative
of what might be expected from the MATLAB plots. Overall, the figure shows that the signal is being
filtered to a band of frequencies that match the given characteristics
Task 2.5: Determine the coefficients of the difference equation for Direct Form 2 using
Equation 11 and Equation 13 and Equation 14. Implement Direct Form 2 in C code and verify
the filter shape using a pulse and an FFT.
Similarly, to Direct Form I above, I implemented them in Direct Form II on the microcontroller.
Figure below shows the filter results along with the oscilloscope’s built-in FFT function. The
oscilloscope output confirms that a bandpass filter similar to what was plotted in MATLAB is
beingapplied to the signal. Figures below shows the results of Direct Form II for my second attempt
at applying the filter with a pole radius of 0.9
This is again similar to what is predicted based on the MATLAB plots. Overall, I was able to
implement both forms and filter the signal with a bandpass according to the characteristics given
in the lab.
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables -------------------------------------------
-------------
-*/
I2C_HandleTypeDef hi2c3;
SAI_HandleTypeDef hsai_BlockA2;
SAI_HandleTypeDef hsai_BlockB2;
DMA_HandleTypeDef hdma_sai2_a;
DMA_HandleTypeDef hdma_sai2_b;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes ---------------------------------
-------------
-*/
void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_I2C3_Init(void);
static void MX_SAI2_Init(void);
/* USER CODE BEGIN PFP */
void copy_array(int16_t* buffer_source, int16_t*
buffer_destination, uint16_t
length);
/* USER CODE END PFP */
/* Private user code -------------------------------------------
-------------
-*/
/* USER CODE BEGIN 0 */
//put global variable here
volatile float y;
volatile float ydelay=0;
volatile float ydelay2=0;
volatile float x;
volatile float xdelay=0;
volatile float xdelay2=0;
volatile float Rp=0.9;
volatile float C=10.5263;
volatile float w;
volatile float wdelay=0;
volatile float wdelay2=0;
void PUT_YOUR_LAB_CODE_HERE(int16_t input_left, int16_t
input_right, int16_t&
output_left, int16_t& output_right) {
// Part 5%%%%%%%%%%%%%%%
x=input_right;
w = x - 0.81 * wdelay2;
y = w - (1/C) * wdelay2;
output_right=y;
wdelay2=wdelay;
wdelay=w;
// Part 3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
// x=input_right;
//
// y = (1/C) * (x - xdelay2) - 0.81*ydelay2;
// output_right=y;
//
// xdelay2=xdelay;
// xdelay=x;
//
// ydelay2=ydelay;
// ydelay=y;
// output_right = input_right;
// output_left = input_left;
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------
-----------
-*/
/* Reset of all peripherals, Initializes the Flash interface and
the
Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C3_Init();
MX_SAI2_Init();
/* USER CODE BEGIN 2 */
R1 = (int16_t*)calloc(SAI_DATA_BUFFER_SIZE, sizeof(int16_t));
R2 = (int16_t*)calloc(SAI_DATA_BUFFER_SIZE, sizeof(int16_t));
T1 = (int16_t*)calloc(SAI_DATA_BUFFER_SIZE, sizeof(int16_t));
T2 = (int16_t*)calloc(SAI_DATA_BUFFER_SIZE, sizeof(int16_t));
SX_R = SX_T = 0;
codec_init(&hi2c3, USE_FREQ);
/// HAL_GPIO_WritePin(GPIOI, GPIO_PIN_1, 1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
while(SX_R) {}
HAL_SAI_Receive_DMA(&hsai_BlockB2, (uint8_t*)R1,
SAI_DATA_BUFFER_SIZE);
SX_R++;
while(SX_T) {}
HAL_SAI_Transmit_DMA(&hsai_BlockA2, (uint8_t*)T2,
SAI_DATA_BUFFER_SIZE);
SX_T++;
linear_copy(R2, T1, SAI_DATA_BUFFER_SIZE);
while(SX_R) {}
HAL_SAI_Receive_DMA(&hsai_BlockB2, (uint8_t*)R2,
SAI_DATA_BUFFER_SIZE);
SX_R++;
while(SX_T) {}
HAL_SAI_Transmit_DMA(&hsai_BlockA2, (uint8_t*)T1,
SAI_DATA_BUFFER_SIZE);
SX_T++;
linear_copy(R1, T2, SAI_DATA_BUFFER_SIZE);
// HAL_StatusTypeDef result = HAL_SAI_Receive(&hsai_BlockB2,
(uint8_t*)receive_buffer, SAI_DATA_BUFFER_SIZE, 1000);
//
// (void)result;
//
// linear_copy(receive_buffer, transmit_buffer,
SAI_DATA_BUFFER_SIZE);
//
// HAL_SAI_Transmit(&hsai_BlockA2, (uint8_t*)transmit_buffer,
SAI_DATA_BUFFER_SIZE, 1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified
parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 12;
RCC_OscInitStruct.PLL.PLLN = 192;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Activate the Over-Drive mode
*/
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType =
RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) !=
HAL_OK)
{
Error_Handler();
}
}
/**
* @brief Peripherals Common Clock Configuration
* @retval None
*/
void PeriphCommonClock_Config(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SAI2;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
PeriphClkInitStruct.PLLSAI.PLLSAIR = 2;
PeriphClkInitStruct.PLLSAI.PLLSAIQ = 2;
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV2;
PeriphClkInitStruct.PLLSAIDivQ = 1;
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
PeriphClkInitStruct.Sai2ClockSelection =
RCC_SAI2CLKSOURCE_PLLSAI;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief I2C3 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C3_Init(void)
{
/* USER CODE BEGIN I2C3_Init 0 */
/* USER CODE END I2C3_Init 0 */
/* USER CODE BEGIN I2C3_Init 1 */
/* USER CODE END I2C3_Init 1 */
hi2c3.Instance = I2C3;
hi2c3.Init.Timing = 0x00C0EAFF;
hi2c3.Init.OwnAddress1 = 0;
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c3.Init.OwnAddress2 = 0;
hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3,
I2C_ANALOGFILTER_ENABLE) !=
HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN I2C3_Init 2 */
/* USER CODE END I2C3_Init 2 */
}
/**
* @brief SAI2 Initialization Function
* @param None
* @retval None
*/
static void MX_SAI2_Init(void)
{
/* USER CODE BEGIN SAI2_Init 0 */
/* USER CODE END SAI2_Init 0 */
/* USER CODE BEGIN SAI2_Init 1 */
/* USER CODE END SAI2_Init 1 */
hsai_BlockA2.Instance = SAI2_Block_A;
hsai_BlockA2.Init.Protocol = SAI_FREE_PROTOCOL;
hsai_BlockA2.Init.AudioMode = SAI_MODEMASTER_TX;
hsai_BlockA2.Init.DataSize = SAI_DATASIZE_16;
hsai_BlockA2.Init.FirstBit = SAI_FIRSTBIT_MSB;
hsai_BlockA2.Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
hsai_BlockA2.Init.Synchro = SAI_ASYNCHRONOUS;
hsai_BlockA2.Init.OutputDrive = SAI_OUTPUTDRIVE_ENABLE;
hsai_BlockA2.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
hsai_BlockA2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
hsai_BlockA2.Init.AudioFrequency = USE_FREQ;
hsai_BlockA2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockA2.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockA2.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockA2.Init.TriState = SAI_OUTPUT_NOTRELEASED;
hsai_BlockA2.FrameInit.FrameLength = 64;
hsai_BlockA2.FrameInit.ActiveFrameLength = 32;
hsai_BlockA2.FrameInit.FSDefinition =
SAI_FS_CHANNEL_IDENTIFICATION;
hsai_BlockA2.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
hsai_BlockA2.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
hsai_BlockA2.SlotInit.FirstBitOffset = 0;
hsai_BlockA2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
hsai_BlockA2.SlotInit.SlotNumber = 4;
hsai_BlockA2.SlotInit.SlotActive = 0x00000005;
if (HAL_SAI_Init(&hsai_BlockA2) != HAL_OK)
{
Error_Handler();
}
hsai_BlockB2.Instance = SAI2_Block_B;
hsai_BlockB2.Init.Protocol = SAI_FREE_PROTOCOL;
hsai_BlockB2.Init.AudioMode = SAI_MODESLAVE_RX;
hsai_BlockB2.Init.DataSize = SAI_DATASIZE_16;
hsai_BlockB2.Init.FirstBit = SAI_FIRSTBIT_MSB;
hsai_BlockB2.Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;
hsai_BlockB2.Init.Synchro = SAI_SYNCHRONOUS;
hsai_BlockB2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockB2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;
hsai_BlockB2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockB2.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockB2.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockB2.Init.TriState = SAI_OUTPUT_NOTRELEASED;
hsai_BlockB2.FrameInit.FrameLength = 64;
hsai_BlockB2.FrameInit.ActiveFrameLength = 32;
hsai_BlockB2.FrameInit.FSDefinition =
SAI_FS_CHANNEL_IDENTIFICATION;
hsai_BlockB2.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
hsai_BlockB2.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
hsai_BlockB2.SlotInit.FirstBitOffset = 0;
hsai_BlockB2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
hsai_BlockB2.SlotInit.SlotNumber = 4;
hsai_BlockB2.SlotInit.SlotActive = 0x00000005;
if (HAL_SAI_Init(&hsai_BlockB2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SAI2_Init 2 */
/* USER CODE END SAI2_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA2_Stream4_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream4_IRQn);
/* DMA2_Stream6_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOI_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_1, GPIO_PIN_RESET);
/*Configure GPIO pin : PI1 */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error
return state
*/
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line
number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name
and line
number,
ex: printf("Wrong parameters value: file %s on line %d\r\n",
file, line)
*/
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
Appendix B: MATLAB Support Code
clear; close all; clc;
j = 1i;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%
% Mohammad Afrazi
% EE 472 DSP Lab
% Lab 5 - IIR Filter Design Using Poles and Zeros
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%
%given information
Fs = 48000;
Fc = 12000;
% Specifications:
% -F0=Fc=12kHz unit gain here
% -F0=0kHz,F0=24kHz zero gain here
%get the zero angle locations
f1 = 0/Fs;
f1 = checkFundamentalRange(f1);
w1 = 2*pi*f1;
f2 = 24000/Fs;
f2 = checkFundamentalRange(f2);
w2 = 2*pi*f2;
%get the center frequency location
fc = Fc/Fs;
fc = checkFundamentalRange(fc);
wc = 2*pi*fc;
%define the zeros
Rz = 1;
z1 = Rz*exp(1i*w1);
z2 = Rz*exp(1i*w2);
%define the poles
Rp = 0.5;
p1 = j*Rp*exp(1i*w1);
p2 = j*Rp*exp(1i*w2);
%plot H(w)
H = @(z) ((z-z1).*(z-z2))./((z-p1).*(z-p2));
figure()
plotMagAndPhase(H,"")
%normalize H(w) and plot
C = H(exp(1i*wc));
H = @(z) ((z-z1).*(z-z2))./((z-p1).*(z-p2))./C;
figure()
plotMagAndPhase(H,"Normalized ")
%calculate 3dB values
r = 0:.01:1;
BW = returnBandWidthValues(r,w1,w2,wc);
figure()
plot(r,BW)
title('-3dB Bandwidth versus R')
xlabel('R Value')
ylabel('Bandwidth (w)')
%draw a pzmap for normalized
figure()
grid on
zplane([z1;z2],[p1;p2])
title(sprintf("Zero-Pole Plot for r = %.1f",Rp))
%algebra and determining coefficients
syms R z
Rz = 1;
z1 = Rz*exp(1i*w1);
z2 = real(Rz*exp(1i*w2));
p1 = 1i*R*exp(1i*w1);
p2 = 1i*(R*real(exp(1i*w2)));
H = ((z-z1).*(z-z2))./((z-p1).*(z-p2))./real(C)
%plug R value and get corresponding coefficients
R = Rp;
zeros = [z1,z2];
poles = double([subs(p1),subs(p2)]);
B = poly(zeros);
A = poly(poles);
fprintf("The coefficients for B are...")
disp(B)
fprintf("The coefficients for A are...")
disp(A)
fprintf("The value of C is: %.3f\nThe value of 1/C
is:%.3f",real(C),1/real(C))
B = B/real(C);
fprintf("The normalized coefficients for B are...")
disp(B)
function f = checkFundamentalRange(f)
if(norm(f)>1/2)
if(f<0)
while(norm(f)>=1/2)
f=f+1;
end
elseif(f>0)
while(norm(f)>=1/2)
f=f-1;
end
end
end
end
function plotMagAndPhase(H,label)
w = 0.01:0.01:pi;
Hw = H(exp(1i.*w));
subplot(2,1,1)
plot(w,abs(Hw))
title(sprintf("%sMagnitude Response",label))
xlabel('w (radians)')
xticks([0,pi/4,pi/2,3*pi/4,pi])
xticklabels({'0','\pi/4','\pi/2','3*\pi/4','\pi'})
xlim([w(1)-.1,w(end)+.1])
ylabel('Magnitude')
subplot(2,1,2)
plot(w,angle(Hw).*(180./pi))
title(sprintf("%sPhase Response",label))
xlabel('w (radians)')
xticks([0,pi/4,pi/2,3*pi/4,pi])
xticklabels({'0','\pi/4','\pi/2','3*\pi/4','\pi'})
xlim([w(1)-.1,w(end)+.1])
ylabel('phase (degrees)')
end
function BW = returnBandWidthValues(r,w1,w2,wc)
j = 1i;
%define the zeros
Rz = 1;
z1 = Rz*exp(1i*w1);
z2 = Rz*exp(1i*w2);
%pre-allocate output
BW = zeros(1,length(r));
for i = 1:length(r)
%define the p