传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波
文章目錄
- 總結(jié)
- test1、動(dòng)態(tài)顯示一段正弦波信號的曲線:
- test2、現(xiàn)提供隨機(jī)信號函數(shù),隨意設(shè)定兩路不同幅度的隨機(jī)信號,動(dòng)態(tài)顯示出來。
- test3、用均值法將原始的傳感器信號進(jìn)行濾波處理
- test4、用滑動(dòng)濾波法將原始的傳感器信號進(jìn)行濾波處理
總結(jié)
1.為什么傳感器要進(jìn)行信號處理:
儀器儀表上面的數(shù)據(jù)如果是跳來跳去的話,就沒法用,比如說壓力傳感器,一會(huì)顯示1一會(huì)顯示2,那么這個(gè)數(shù)字就沒多大意義,所以需要進(jìn)行信號處理。
2.這個(gè)仿真的代碼中while(1)起到的是畫點(diǎn)的作用,
LCD_L0_DrawPixel(x, y)是畫一個(gè)像素點(diǎn),可以用一個(gè)for循環(huán)改變這個(gè)點(diǎn)的xy坐標(biāo)值畫不同的連續(xù)的點(diǎn),很多個(gè)點(diǎn)動(dòng)起來就成了一條線。
其中rand()%40意味著隨機(jī)信號的幅度在40以內(nèi)。
3.void draw_graphic(int y,int z,int color)這個(gè)函數(shù)起到了讓點(diǎn)動(dòng)起來的作用。
test1、動(dòng)態(tài)顯示一段正弦波信號的曲線:
整個(gè)文件很大,但是目前只需要處理MainTask.c文件的內(nèi)容:
以下是MainTask.c文件的內(nèi)容
#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); }實(shí)驗(yàn)結(jié)果:
test2、現(xiàn)提供隨機(jī)信號函數(shù),隨意設(shè)定兩路不同幅度的隨機(jī)信號,動(dòng)態(tài)顯示出來。
#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); }實(shí)驗(yàn)結(jié)果:
test3、用均值法將原始的傳感器信號進(jìn)行濾波處理
#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); }實(shí)驗(yàn)結(jié)果:
test4、用滑動(dòng)濾波法將原始的傳感器信號進(jìn)行濾波處理
#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); }實(shí)驗(yàn)結(jié)果:
可以看出滑動(dòng)濾波比均值濾波效果好得多
總結(jié)
以上是生活随笔為你收集整理的传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tcping在linux用法,tcpin
- 下一篇: java反射 Method