传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波
生活随笔
收集整理的這篇文章主要介紹了
传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 總結
- test1、動態顯示一段正弦波信號的曲線:
- test2、現提供隨機信號函數,隨意設定兩路不同幅度的隨機信號,動態顯示出來。
- test3、用均值法將原始的傳感器信號進行濾波處理
- test4、用滑動濾波法將原始的傳感器信號進行濾波處理
總結
1.為什么傳感器要進行信號處理:
儀器儀表上面的數據如果是跳來跳去的話,就沒法用,比如說壓力傳感器,一會顯示1一會顯示2,那么這個數字就沒多大意義,所以需要進行信號處理。
2.這個仿真的代碼中while(1)起到的是畫點的作用,
LCD_L0_DrawPixel(x, y)是畫一個像素點,可以用一個for循環改變這個點的xy坐標值畫不同的連續的點,很多個點動起來就成了一條線。
其中rand()%40意味著隨機信號的幅度在40以內。
3.void draw_graphic(int y,int z,int color)這個函數起到了讓點動起來的作用。
test1、動態顯示一段正弦波信號的曲線:
整個文件很大,但是目前只需要處理MainTask.c文件的內容:
以下是MainTask.c文件的內容
#include "GUI.h" #include "GUI_Protected.h"#include <stdio.h> #include <string.h> #include <math.h> #define pi 3.1415926 #define LVBOTIME 20 extern const GUI_BITMAP bmMicriumLogo; extern const GUI_BITMAP bmMicriumLogo_1bpp; void draw_graphic(int y,int z,int color); int yy[2][320]; int LVBO[LVBOTIME];/* ******************************************************************* * * main() * ******************************************************************* */ void MainTask(void) {int Cnt =0;int YPos,shidu=0,wendu=0;int x,y=0,flag_x=1,flag_y=1;float z=0,i=0;int LCDXSize = LCD_GET_XSIZE();int LCDYSize = LCD_GET_YSIZE();const GUI_BITMAP *pBitmap;GUI_Init();GUI_SetColor(GUI_BLUE);GUI_SetBkColor(GUI_WHITE);GUI_Clear();GUI_DispStringHCenterAt("jym016", 280, 200);while(1){i++;if(i==360) i=0;z=sin(i/180*pi*4);draw_graphic(z*20+120,1,GUI_RED);} }void draw_graphic(int y,int z,int color) {int x=0;GUI_SetColor(GUI_WHITE);for(x=0;x<320;x++){ LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }for(x=0;x<320;x++){yy[z][x]=yy[z][x+1];}yy[z][319]=y;GUI_SetColor(color);for(x=0;x<320;x++){LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }GUI_Delay(50); }實驗結果:
test2、現提供隨機信號函數,隨意設定兩路不同幅度的隨機信號,動態顯示出來。
#include "GUI.h" #include "GUI_Protected.h"#include <stdio.h> #include <string.h> #include <math.h> #define pi 3.1415926 #define LVBOTIME 20 extern const GUI_BITMAP bmMicriumLogo; extern const GUI_BITMAP bmMicriumLogo_1bpp; void draw_graphic(int y,int z,int color); int yy[2][320]; int LVBO[LVBOTIME];/* ******************************************************************* * * main() * ******************************************************************* */ void MainTask(void) {int Cnt =0;int i,YPos,shidu=0,wendu=0;int x,y,flag_x=1,flag_y=1;float z=0;int LCDXSize = LCD_GET_XSIZE();int LCDYSize = LCD_GET_YSIZE();const GUI_BITMAP *pBitmap;GUI_Init();GUI_SetColor(GUI_BLUE);GUI_SetBkColor(GUI_WHITE);GUI_Clear();GUI_DispStringHCenterAt("jym016", 280, 200);while(1){y = rand()%40;draw_graphic(y+50,0,GUI_RED);y = rand()%10;draw_graphic(y+150,1,GUI_BLUE);} }void draw_graphic(int y,int z,int color) {int x=0;GUI_SetColor(GUI_WHITE);for(x=0;x<320;x++){ LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }for(x=0;x<320;x++){yy[z][x]=yy[z][x+1];}yy[z][319]=y;GUI_SetColor(color);for(x=0;x<320;x++){LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }GUI_Delay(50); }實驗結果:
test3、用均值法將原始的傳感器信號進行濾波處理
#include "GUI.h" #include "GUI_Protected.h"#include <stdio.h> #include <string.h> #include <math.h> #define pi 3.1415926 #define LVBOTIME 20 extern const GUI_BITMAP bmMicriumLogo; extern const GUI_BITMAP bmMicriumLogo_1bpp; void draw_graphic(int y,int z,int color); int yy[2][320]; int LVBO[LVBOTIME];/* ******************************************************************* * * main() * ******************************************************************* */ void MainTask(void) {int Cnt =0;int i,YPos,shidu=0,wendu=0;int x,y=0,flag_x=1,flag_y=1;float z=0;int LCDXSize = LCD_GET_XSIZE();int LCDYSize = LCD_GET_YSIZE();const GUI_BITMAP *pBitmap;GUI_Init();GUI_SetColor(GUI_BLUE);GUI_SetBkColor(GUI_WHITE);GUI_Clear();GUI_DispStringHCenterAt("jym016", 280, 200);while(1){draw_graphic(y+50,0,GUI_RED);for(x=0;x<LVBOTIME;x++){y = rand()%40;z+=y;}z/=LVBOTIME;draw_graphic(z+150,1,GUI_GREEN);} }void draw_graphic(int y,int z,int color) {int x=0;GUI_SetColor(GUI_WHITE);for(x=0;x<320;x++){ LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }for(x=0;x<320;x++){yy[z][x]=yy[z][x+1];}yy[z][319]=y;GUI_SetColor(color);for(x=0;x<320;x++){LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }GUI_Delay(50); }實驗結果:
test4、用滑動濾波法將原始的傳感器信號進行濾波處理
#include "GUI.h" #include "GUI_Protected.h"#include <stdio.h> #include <string.h> #include <math.h> #define pi 3.1415926 #define LVBOTIME 20 extern const GUI_BITMAP bmMicriumLogo; extern const GUI_BITMAP bmMicriumLogo_1bpp; void draw_graphic(int y,int z,int color); int yy[2][320]; int LVBO[LVBOTIME];/* ******************************************************************* * * main() * ******************************************************************* */ void MainTask(void) {int Cnt =0;int i,YPos,shidu=0,wendu=0;int x,y,flag_x=1,flag_y=1;float z=0;int LCDXSize = LCD_GET_XSIZE();int LCDYSize = LCD_GET_YSIZE();const GUI_BITMAP *pBitmap;GUI_Init();GUI_SetColor(GUI_BLUE);GUI_SetBkColor(GUI_WHITE);GUI_Clear();GUI_DispStringHCenterAt("jym016", 280, 200);while(1){y = rand()%40;draw_graphic(y+50,0,GUI_RED);for(x=0;x<LVBOTIME;x++)LVBO[x] = LVBO[x+1];LVBO[LVBOTIME-1] = y;z=0;for(x=0;x<LVBOTIME;x++)z += LVBO[x];z/=LVBOTIME;draw_graphic(z+140,1,GUI_GREEN);} }void draw_graphic(int y,int z,int color) {int x=0;GUI_SetColor(GUI_WHITE);for(x=0;x<320;x++){ LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }for(x=0;x<320;x++){yy[z][x]=yy[z][x+1];}yy[z][319]=y;GUI_SetColor(color);for(x=0;x<320;x++){LCD_L0_DrawPixel(x+1, yy[z][x]);if(yy[z][x]<yy[z][x+1])GUI_DrawVLine(x+1, yy[z][x], yy[z][x+1]); elseGUI_DrawVLine(x+1, yy[z][x+1], yy[z][x]); }GUI_Delay(50); }實驗結果:
可以看出滑動濾波比均值濾波效果好得多
總結
以上是生活随笔為你收集整理的传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tcping在linux用法,tcpin
- 下一篇: java反射 Method