一维信号光滑去毛刺处理

  以下是威斯康星大学交通系博士申请遇到的一道题,有兴趣的可以交流

Problem:

 Implement theKalman Filter (Use identity matrix for statepropagation)or other smoothing filter of your choice on the enclosed “speed24.csv” .Compare the filtered and the original data in a time-series plot (x: timeinterval, y: speed data). Report ME, MAE, and MAPE of the filtering results. Ifthe filter contains any parameters, e.g.smoothing window,smoothing coefficient, experiment to find the best fittingparameters that produces the best trend of the original data.( 平滑窗口,平滑参数,试验找到最好的拟合参数以得到原始数据的最好趋势。)

以下是matlab实现的算法

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. function xdense = linear_interp(x, t, tdense)  
  2. xdense = zeros(size(tdense));  
  3.   
  4. for i = 1:length(tdense)  
  5.     ind_b = find(tdense(i) >= t, 1, 'last');  
  6.     if isempty(ind_b)  
  7.         ind_b = 1;  
  8.         ind_e = 1;  
  9.         lambda = 1;  
  10.     elseif ind_b == length(t)  
  11.         ind_e = ind_b;  
  12.         lambda = 0;  
  13.     else  
  14.         ind_e = ind_b + 1;  
  15.         lambda = (tdense(i) - t(ind_b)) / (t(ind_e) - t(ind_b));  
  16.     end;  
  17.       
  18.     xdense(i) = (1 - lambda) * x(ind_b) + lambda * x(ind_e);  
  19. end;  


[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. %--------------------------------------------------------------------------  
  2. % apply fourier analysis on each window size, estimate the dominant  
  3. % frequency, and remove high freqs...  
  4.   
  5. % partition the signals and perform fourier analysis so that we get the  
  6. % dominant freq, then smooth the signal using sigma that changes with the  
  7. % dominant freq...  
  8. %--------------------------------------------------------------------------  
  9.   
  10. clear all;  
  11. %clc;  
  12. %close all;  
  13.   
  14. % 可以调整的参数  
  15. windowSize = 41;  
  16.   
  17. % step 1: read signals from input file  
  18. FILE_PATH = 'E:\data.csv';  
  19. signal = CSVREAD(FILE_PATH);  
  20. S_signal = signal;  
  21.   
  22.   
  23. smoothed_result = zeros(length(signal), 1);  
  24.   
  25. % 不考虑NAN数据  
  26. nan = isnan(signal);  
  27. an = ~isnan(signal);  
  28. signal = signal(~isnan(signal));  
  29.   
  30. n = length(signal);  
  31. starts = 1:windowSize:n;  
  32. if starts(end) + windowSize > n  
  33.     starts(end) = n - windowSize + 1;  
  34. end;  
  35.   
  36. dominantSigmas_sample = zeros(length(starts), 1);  
  37.   
  38. % perform fourier analysis.  
  39. for i = 1:length(starts)  
  40.     sel = starts(i):starts(i)+windowSize-1;  
  41.     coeffs = fft(signal(sel) - mean(signal(sel)));  
  42.     % find the dominant one...  
  43.     [maxVal, maxIndex] = max(abs(coeffs(1:floor(windowSize/2))));  
  44.     dominantSigmas_sample(i) = windowSize / maxIndex/5;  
  45. end;  
  46.   
  47. % simple local linear interpolate...  
  48. dominantSigmas = linear_interp(dominantSigmas_sample, starts + windowSize/2, (1:n)');  
  49.   
  50. smoothed_signal = zeros(n, 1);  
  51. % then smooth the signal   
  52. for i = 1:n  
  53.     % blur the image locally...  
  54.     sigma = dominantSigmas(i);  
  55.     % 高斯函数分布特性,  
  56.     % http://blog.csdn.net/fullyfulei/article/details/8758372  
  57.     span = round(3*sigma);  
  58.       
  59.     sel = (max(1, i - span):min(n, i + span))';  
  60.     filter = exp(- (sel - i).^2 / 2 / sigma^2);  
  61.       
  62.     smoothed_signal(i) = sum(signal(sel) .* filter) / sum(filter);  
  63. end  
  64. smoothed_result(nan) = NaN;   
  65. smoothed_result(an) = smoothed_signal;  
  66. maxPoint = [false; smoothed_result(2:end-1) > smoothed_result(3:end) & smoothed_result(2:end-1) > smoothed_result(1:end-2); false];  
  67. minPoint = [false; smoothed_result(2:end-1) < smoothed_result(3:end) & smoothed_result(2:end-1) < smoothed_result(1:end-2); false];  
  68.   
  69. figure  
  70. subplot(2,1,1)  
  71. plot(S_signal);  
  72. subplot(2,1,2)  
  73. plot(smoothed_result);  
  74.   
  75.   
  76.   
  77. % ME, MAE, MAPE  
  78. E = smoothed_signal - signal;  
  79. AE = abs(E);  
  80.   
  81. ME = sum(E)/n;  
  82. MAE = sum(AE)/n;  
  83. MAPE = sum(abs(E./signal))/n;  


  • 7
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
一维信号是一种在时间轴上变化的信号,例如音频信号或传感器数据。使用卷积神经网络(CNN)处理一维信号可以帮助我们提取信号中的特征并进行分类或预测任务。 例如,假设我们有一个音频信号的问题,需要将其分类为说话人的语音或音乐。首先,我们将音频信号转换为一维数据,并输入到CNN模型中。 一维信号的CNN处理图例如下: 输入层:我们将一维信号作为输入。每个信号点都表示为一个数字,并按照时间顺序排列。 卷积层:卷积层用于提取信号中的局部特征。通过卷积操作,我们将窗口滑动到信号上,并使用卷积核(参数矩阵)进行特征提取。每次卷积操作会生成一个新的特征图,其中每个特征点表示在特定位置上的信号的某种特征。 池化层:池化层用于对卷积操作后的特征图进行下采样,减少特征图大小。通过池化,我们可以保留重要的特征并丢弃无关紧要的细节,从而降低了计算复杂度并增强了模型的鲁棒性。 全连接层:全连接层用于将汇总后的特征输入到分类器进行分类或预测任务。在全连接层中,我们将特征向量展平,并通过多个全连接层进行特征映射和变换。最后,输出层使用softmax函数将特征转换为概率分布,表示不同类别的概率。 这样,通过在CNN中引入一维信号处理,我们可以从中提取并利用丰富的音频或传感器数据中的特征,从而实现分类、预测等各种应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值