question about the signal smoothing example
4 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a question about the signal smoothing example given in the documentation of Matlab.
load bostemp
days = (1:31*24)/24;
plot(days, tempC)
axis tight
ylabel('Temp (\circC)')
xlabel('Time elapsed from Jan 1, 2011 (days)')
title('Logan Airport Dry Bulb Temperature (source: NOAA)')
I understand that this example wants to emphasize that the measurements are taken 24 hours a day, 31 days for January. So the variable 'days' ranges from 1 to 31*24. But why divide it by 24?
Also,
hoursPerDay = 24;
coeff24hMA = ones(1, hoursPerDay)/hoursPerDay;
avg24hTempC = filter(coeff24hMA, 1, tempC);
plot(days,[tempC avg24hTempC])
I understand that this example refers to the moving average of length N (in this case N = 24). I don't understand why there is a need to set N = 24. Why can't it be just N = 1?
Thanks for your insights
0 个评论
采纳的回答
Honglei Chen
2017-7-12
For the first question, the data is recorded hourly, so the samples are done in 1:31*24. However, in the display, the x axis is labeled as days, that's why it needs to be divided by 24.
For the second question, the N is basically the window length you use to smooth the data. The longer the window is, the smoother the curve you get, but you also lose all the sudden changes in between. In this case it wants to smooth the data over a 24 hour period, that's why the N is set to 24. If you set N to 1, since the data is recorded hourly rate, there will be essentially no smoothing.
HTH
3 个评论
Honglei Chen
2017-7-12
Unfortunately none because that depends on your application. Taking this particular one as an example, you can probably think of N as "what is the variation I'm interested in?" If you really want to see the hourly change in the series, then you probably cannot do any smoothing. On the other hand, if you say I only want to see the change happens on every 6 hours or so, then you can set N to 6. Does this help?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!