日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波

發(fā)布時間:2025/3/12 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 传感器信号处理仿真实验(c语言实现),均值滤波,滑动滤波 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

      • 總結
      • test1、動態(tài)顯示一段正弦波信號的曲線:
      • test2、現(xiàn)提供隨機信號函數(shù),隨意設定兩路不同幅度的隨機信號,動態(tài)顯示出來。
      • test3、用均值法將原始的傳感器信號進行濾波處理
      • test4、用滑動濾波法將原始的傳感器信號進行濾波處理

總結

1.為什么傳感器要進行信號處理:
儀器儀表上面的數(shù)據(jù)如果是跳來跳去的話,就沒法用,比如說壓力傳感器,一會顯示1一會顯示2,那么這個數(shù)字就沒多大意義,所以需要進行信號處理。
2.這個仿真的代碼中while(1)起到的是畫點的作用,
LCD_L0_DrawPixel(x, y)是畫一個像素點,可以用一個for循環(huán)改變這個點的xy坐標值畫不同的連續(xù)的點,很多個點動起來就成了一條線。
其中rand()%40意味著隨機信號的幅度在40以內。
3.void draw_graphic(int y,int z,int color)這個函數(shù)起到了讓點動起來的作用。

test1、動態(tài)顯示一段正弦波信號的曲線:

整個文件很大,但是目前只需要處理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、現(xiàn)提供隨機信號函數(shù),隨意設定兩路不同幅度的隨機信號,動態(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); }

實驗結果:

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语言实现),均值滤波,滑动滤波的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。