Professional Documents
Culture Documents
MATLAB CODE:
Fs = 1000;
N = T*Fs;
x = [];
end
% Stopband frequency Rp = 1;
t = 0:1/Fs:length(x)/Fs-1/Fs; subplot(2,2,1);
plot(t, x);
xlabel('Time (seconds)');
ylabel('Amplitude');
subplot(2,2,2);
plot(t, y);
xlabel('Time (seconds)');
ylabel('Amplitude');
xlabel('Time (seconds)');
ylabel('Amplitude');
subplot(2,2,4);
plot(t, y_butter);
xlabel('Time (seconds)');
ylabel('Amplitude');
OUTPUT :
Input Voltage Frequency (Hz) Output Voltage
9V 50 28V
9V 100 28.52V
9V 1.5k 28.42V
9V 3k 28.30
9V 6k 19.5
9V 10k 19.2
9V 100k 19.4
voltage = [28, 28.52, 28.42, 28.30, 19.5, 19.2, 19.4]; % voltage values
frequency = [50, 100, 1500, 3000, 6000, 10000, 100000]; % frequency values in Hz
semilogx(frequency, gain);
xlabel('Frequency (Hz)');
ylabel('Gain (dB)');
title('Gain vs Frequency');
cutoff_frequency = 6000
hold on;
Plot -
STM CODE:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f4xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes */
#include "main.h"
#include "stm32f4xx_it.h"
/* Private includes */
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef */
/* USER CODE BEGIN TD */
/* Private define */
/* USER CODE BEGIN PD */
/* Private macro */
/* USER CODE BEGIN PM */
/* Private variables */
/* USER CODE BEGIN PV */
/* External variables */
extern TIM_HandleTypeDef htim2;
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
{
}
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
}
/**
* @brief This function handles Pre-fetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
{
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
{
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/******************************************************************************/
/* STM32F4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f4xx.s). */
/******************************************************************************/
/**
* @brief This function handles TIM2 global interrupt.
* */
* void TIM2_IRQHandler(void)
* {
* /* USER CODE BEGIN TIM2_IRQn 0 */
* static float x_last[2], y_last[2];
* float x_current;
* float y_current;
* /* USER CODE END TIM2_IRQn 0 */
* HAL_TIM_IRQHandler(&htim2);
* /* USER CODE BEGIN TIM2_IRQn 1 */
* // HAL_GPIO_TogglePin(GPIOD,
GPIO_PIN_12);
HAL_GPIO_TogglePin(GPIOC,
GPIO_PIN_3);
* //gsw_toggle();
*
* unsigned short int x_current_adc = HAL_ADC_GetValue(&hadc1);
*
* // Current input digital value to analog
x_current = (float)
(x_current_adc*3.3/4095.0);
* y_current = 0.2928932*(x_current + 2 * x_last[1] +
x_last[0])- 0.1715729*y_last[0];
*
* // move last input sample (n-1) to make it (n-2) sample for
next ISR x_last[0] = x_last[1];
*
* // move current input sample to make it (n-1) sample for
next ISR x_last[1] = x_current;
*
* // Store the output calcu-
lated for y_last[0] =
y_last[1];
* y_last[1] = y_current;
*
* HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R,((y_current*4095)/
3.3));
*
* HAL_ADC_Start(&hadc1);
* /* USER CODE END TIM2_IRQn 1 */
* }
*
- Sarvesh sudhan p
- Pes1ug20ee056