Getting y-axis shift during FFT noise removal - r

I'm trying to do a noise removal by FFT in R. The trouble I'm having is that I get a y-axis shift during the process and I'm not sure what the cause is. I have read up on FFT and used this resource as a guide. See below for the code I have been executing as well as sample graphics of the result. Here is a dropbox link to the csv file. data.csv
data=read.csv('data.csv')
plot(data,type='l')
#FFT filtration function
fft.filter=function(data,threshold){
temp=fft(data)
temp[threshold:length(data)-threshold]=0+0i
temp=Re(fft(temp,inverse=TRUE)/length(temp))
return(temp)
}
data2=data
data2$Signal=fft.filter(data2$Signal,100)
Unfiltered Plot:
Filtered Plot:
As the images show, the data scaling looks fine, I'm just getting a shift that I don't think I should be. The FFT function is working to remove noise from the series.

There is a problem with the indexing. It is indexing from 0 to length(data)-threshold, whereas you want threshold:(length(data)-threshold) I believe. Change the indexing line to
temp[threshold:(length(data)-threshold)]=0+0i

Related

Cannot use plot() function in RStudio for large objects

I am trying to use the default plot() function in R to try and plot a shapefile that is about 100MB, using RStudio. When I try and plot the shapefile, the command doesn't finish executing for around 5 minutes, and when it finally does, the plotting window remains blank. When I execute the same process exactly in VS Code, the plot appears almost instantly, as expected.
I have tried uninstalling and reinstalling RStudio with no success.
I can't speak for what VStudio does, but I can guarantee that plotting 100MB worth of data points is useless (unless the final plot is going to be maybe 6 by 10 meters in size).
First thing: can you load the source file into R at all? One would hope so since that's not a grossly huge data blob. Then use your choice of reduction algorithms to get a reasonable number of points to plot, e.g. 800 by 1600, which is all a monitor can display anyway.
Next try plotting a small subset to verify the data are in a valid form, etc.
Then consider reducing the data by collapsing maybe each 10x10 region to a single average value, or by using ggplot2:geom_hex .

Converting rectangular pixels to square pixels in R

I'm working with an asc file in R and trying to run it through some GIS processing on a script that was written by someone else. The current chunk of code I'm working on is
asc <- (raster(inputRas))
asc.extent <- extent(asc)
head <- read.ascii.grid.header(inputRas)
writeRaster(asc, "outputRas", format="SAGA", overwrite=TRUE)
which works until the last line. It's failing here because my raster is in rectangular coordinates, which SAGA doesn't like. I've spent a lot of time googling and trying different functions, but nothing has worked that didn't cause other problems down the line. I considered using projectRaster() for a while because the resolution can be changed within it, but I don't actually want to change the projection. Any help would be appreciated, thanks.
Instead of raster::projectRaster, you can use raster::resample

How to draw the following 3D Matlab plot/graph?

I am working on a data analytics project as part of my result.
I have cleaned and sorted my data as I wanted.
I want to show the data as shown in the figure below.
I have multiple files.
Each file represents a single day and the date in each file is hour and activity (as shown in the picture).
I am working in Matlab, I know how to do the 3D graphs. I also know about the ribbon function in Matlab.
But I can't exactly figure out how to draw the following graph. Any assistance will be highly appreciated. Thank you.
If you still haven't solved the issues, you can use ribbon plot in matlab. Please find the details in the following link.
https://www.mathworks.com/help/matlab/ref/ribbon.html
For example, if X is the vector containing all the data, then you can simply write.
ribbon(X(:,1));

How to plot the data I read from a file in R?

Our instructor assigned us with typing a R script. We don't have any study paper or source for the codes that the instructor typed on class so I'm trying to get help from the articles on internet but I still couldn't find a guide for what I need. Please don't get me wrong, I don't request for someone to do my homework I'm just looking for some tips or any guide links that can help me. When I search on google, not all of the results are related to this and they are usually not helping me or too complicated. The assignment is:
Read data from a .txt file. (I researched and learned how to read data but my problem is I don't know which type of data should I type on the text file to make it plottable by average, standart deviation, histogram etc.)
On the first screen, plot the data, plot the average and plot the standart deviation as line
on the second screen, plot a line from corner to corner and sort the values on it
third screen, plot the data as histogram and plot the distribution function on it
4th screen, plot the anomaly and anomaly line = 0, then make the values that are higher than the anomaly line with different pch than the ones that is lower
finally get the png of 4 screens (i found how to do this)
Thanks.
Which type of data?
You should use metric data. For example the height/age of pople.
For example let's assuhe you have a dataframe yourDataframe:
height
160
155
176
153
185
On the first screen, plot the data
You can use R's standard plot function there: lines(yourDataframe$height)
plot the average and plot the standart deviation
There are already function for those things (for example mean(yourDataframe$height)). Just ask Google.
You can add those values to your linechart using points(mean(yourDataframe$height)).
I think after you did this you will be able to solve the rest of your assignment by yourself. R has quite a big community and you will find everything you need by googling. I guess this is how most people learn R.

Plot two large Raster Data Sets in a Scatter Plot

i have a problem with plotting two Raster Data Sets in R.
I use two different IRS LISS III Scenes (with the same Extent) and what i want is to plot the pixel values of both scenes in one Scatterplot (x= Layer1 and y=Layer2).
My problem is now the handling of the big amount of data. Each Scene has about 80.000.000 pixels due reclassification and other processing i was able to scale down the values to a amount of 12.000.000 in each raster. But when i try to import these values e.g. in a data.frame or load them from an ascii file i always got problems with my memory.
Is it possible two plot such an amount of data, and when yes it would be great if someone could help me, i was trying it for two days now and right now im desperated.
Many thanks,
Stefan
Use the raster package, there's a good chance it will work out of the box since it has good "out-of-memory" handling. If it doesn't work with the ASCII grids, convert them to something more efficient (like an LZW-compressed and tiled GeoTIFF) with GDAL. And if they are still too big resize them, that's all the graphics rendering process will do anyway. (You don't say how you resized originally, or give any details on how you are trying to read them).

Resources