Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("akima", quietly = TRUE)
- attach(mtcars)
- par(mfrow=c(3,2))
- numberCount = 100;
- from = -2;
- to = 2;
- tau = 1;
- a = 1;
- m = 2;
- h = 1;
- xreal <- from + (0:100)*(to - from)/(100)
- x <- from + (0:numberCount)*(to - from)/(numberCount)
- discrete <- function(x, ap = a, taup = tau) ifelse(x <= taup/2, ifelse(x >= -taup/2, ap, 0), 0)
- triangle <- function(x, ap = a, taup = tau) ifelse(x >= -taup/2,
- ifelse(x <= taup/2,
- ifelse(x <= 0, 2 * ap / taup * (x + taup / 2),
- - 2 * ap / taup * (x - taup / 2)) , 0), 0);
- sawtooth <- function(x, ap = a, taup = tau) ifelse(x >= -taup/2,
- ifelse(x <= taup/2,
- ifelse(x <= 0, 2 * ap * x / taup + ap,
- 2 * ap * x / taup - ap), 0), 0);
- gauss <- function(x, ap = a, taup = tau, mp = m) ap * exp(-(2*x/taup)^mp)
- showGraphics <- function(func) {
- valuesreal <- func(xreal);
- values <- func(x)
- plot(xreal, valuesreal, type = c("p"), ylab = "y", xlab = "x", main = paste("Исходный график (поточечно)"), asp = 0.8);
- plot(xreal, valuesreal, type = c("l"), ylab = "y", xlab = "x", main = paste("Исходный график (линией)"), asp = 0.8);
- f <- fft(values);
- f2 = append(f, c(f[1]), after = length(f));
- realf <- Re(f);
- imaginef <- Im(f)
- barplot(Re(f2), xlab = paste("Real spectres"), main = paste("Действительная часть спектра"));
- barplot(Im(f2), xlab = paste("Im spectres"), main = paste("Мнимая часть спектра"));
- invrealf <- Re(fft(f, inverse = TRUE) / length(realf))
- hx <- c();
- hf <- c();
- for (i in 0:(numberCount + 1)) {
- if (h == 0 || i %% h == 0) {
- hx = append(hx, x[i], after = length(hx));
- hf = append(hf, f[i], after = length(hf));
- }
- }
- hinvf <- (fft(hf, inverse = TRUE) / length(hf));
- plot(hx, hinvf, type = c("p"), ylab = "y", xlab = "x", main = paste("Восстановленный график"), asp = 0.8, col = c("white"));
- #lines(spline(x = hx, y = hinvf, n = 10 * length(hx)), col = c("blue"))
- plot(hx, hinvf, type = c("l"), ylab = "y", xlab = "x", main = paste("Восстановленный график (линией)"));
- }
- showGraphics(gauss)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement