Moving average of semi-deviation

Hello,
I am trying to calculate the moving average of the semi-deviation of 1 column of data. I have been able to find a semi-deviation add-in but cannot find anything about making a moving average of the semi-deviation.
Any help appreciated.

답변 (4개)

Image Analyst
Image Analyst 2016년 6월 15일

0 개 추천

What is the definition of " semi-deviation"?
If you mean "Standard Deviation" then try stdfilt() or movstd().

댓글 수: 1

If you have a column vector of data and want the sd of data below the mean, just to
theMean = mean(data);
semiDeviation = std(data(data<theMean));

댓글을 달려면 로그인하십시오.

N/A
N/A 2016년 6월 16일

0 개 추천

Basically is measures the standard deviation of the values that fall below the mean only.
I guess I can use the script I found and run it through a loop to get the moving average. How would I do this?
Star Strider
Star Strider 2016년 6월 16일

0 개 추천

I wrote my own function from your link and implemented an unfortunately inefficient filter to get the moving semideviation (using my own semideviation function):
semidev = @(x) sqrt(sum((mean(x(:)) - x(x(:) < mean(x(:)))).^2) / length(x(:)));
intvl = 10; % Index Interval For Moving Average
t = 1:100; % Time Vector
data = randn(1, 100); % Create Data
datav = [data, data(end-intvl+1:end)]; % ‘Pad’ ‘data’ With Repeat End Data
for k1 = 1:length(datav)-intvl;
wndw = k1:k1+intvl; % Subscript ‘Window’
sv(wndw) = semidev(datav(wndw)); % Calculate Semideviation Over ‘Window’
end
sv = sv(1:length(data)); % Trim To Correct Length
figure(1)
plot(t, data, 'bp')
hold on
plot(t, sv, '-r')
hold off
grid
It runs. I’ll let you determine if it produces the correct results.
N/A
N/A 2016년 6월 17일

0 개 추천

Thanks for the reply Star Strider. After some thought and further reading I propose the following code.
intvl = 10; % Index Interval For Moving Average
t = 1:100; % Time Vector
data = randn(1, 100); % Create Data
data_movmean = movmean( data, [intvl, 0] ); % Moving average of data
data_ds = data; % Set up downside dta array
data_ds( data > data_movmean ) = 0; % Modify downside data - zero values above mean
data_movdsstd = movstd( data_ds, [intvl, 0] ); % Semi-deviation
figure( 1 )
plot( t, data, 'bp' )
hold on
plot( t, data_movdsstd, '-r' )
hold off
grid

댓글 수: 2

Star Strider
Star Strider 2016년 6월 17일
If it gives you the result you want, go for it!
I based my anonymous function code on the expression you linked to. It should give you the result you want, since all the x-values meeting the criteria are set to their appropriate values, and those that do not meet the criteria are set to zero by default anyway.
The movstd call here will include the zeros in the calculation. From the definition, it sounds like you want to ignore those points, rather than treat them as zero. I think you could do this by:
data_ds( data > data_movmean ) = nan;
data_movdsstd = movstd( data_ds, [intvl, 0], 'omitnan' );
This should actually ignore those points rather than just consider them to be zero.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기

제품

질문:

N/A
2016년 6월 15일

댓글:

2016년 6월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by