In digital signal processing (DSP), it is customary to write transfer functions as rational expressions in z − 1 and to order the numerator and denominator terms in ascending powers of z − 1 . Consider the following transfer function: H z b z a z z z ( ) ( ) ( ) . − − − − − = = + + 1 1 1 1 1 2 3 1 0 2 To apply this transfer function to the data in count.dat : 1 Load the matrix count into the workspace: load count.dat; 2 Extract the first column and assign it to x : x = count(:,1); 3 Enter the coefficients of the denominator ordered in ascending powers of z − 1 to represent 1 0 2 1 + − . z : a = [1 0.2]; 1-14
Filtering Data 4 Enter the coefficients of the numerator to represent 2 3 1 + − z : b = [2 3]; 5 Call the filter function: y = filter(b,a,x); 6 Compare the original data and the shaped data with an overlaid plot of the two curves: t = 1:length(x); plot(t,x,'-.',t,y,'-'), grid on legend('Original Data','Shaped Data',2) As you can see from the plot, this filter primarily modifies the amplitude of the original data. 1-15
1 Data Processing Plot of Original and Shaped Data 1-16
Detrending Data Detrending Data In this section... “Introduction” on page 1-17 “Example: Removing Linear Trends from Data” on page 1-17 Introduction The MATLAB ® function detrend subtracts the mean or a best-fit line (in the least-squares sense) from your data. If your data contains several data columns, each data column is detrended separately. Removing a trend from the data enables you to focus your analysis on the fluctuations in the data about the trend. A linear trend typically indicates a systematic increase or decrease in the data. This might be caused by sensor drift, for example. You must decide whether it makes sense to remove trend effects in the data based on the objectives of your analysis. Example: Removing Linear Trends from Data This example shows how to remove a linear trend from daily closing stock prices to emphasize the price fluctuations about the overall increase. This data is available in the Financial Toolbox™ predict_ret_data.mat file. You can follow along with the steps in this example to perform the following tasks: • “Loading and Plotting Data” on page 1-18 • “Detrending Data and Plotting Results” on page 1-19 1-17
1 Data Processing Loading and Plotting Data 1 Load the sample data: load predict_ret_data.mat This adds the variable sdata to the workspace, which contains the daily stock prices. 2 View the contents of the column vector sdata : sdata The last data value is a NaN , which must be removed before detrending the data. 3 Identify and remove the NaN value from sdata : sdata(any(isnan(sdata),2),:) =  For more information about removing NaN s, see “Removing NaNs from Data” on page 1-7. 4 Plot the data: plot(sdata,'+') legend('Original Data',1); xlabel('Time (days)'); ylabel('Stock Price (dollars)'); 1-18
Detrending Data Daily Closing Stock Prices Notice the systematic increase in the stock prices when this data was collected.
You've reached the end of your free preview.
Want to read all 220 pages?
- Fall '16