I am hoping to correctly find the dominant frequencies of a wave function that is non-periodic and the amplitude is decaying along the wave. e.g.
y=c(7792.10,7693.50,7779.20,7766.55,7743.00,7738.20,7741.40,7717.40,7724.05,7816.95,7799.05,7766.35,7771.15,7689.60,7845.70,7801.85,7849.45,7826.65,7870.30,7839.80,7895.50,7838.30,7904.95,7885.00,7878.05,7956.90,7886.20,7928.50,7872.20,8006.05,7941.45,7991.60,8035.05,7927.45,8067.95,7969.80,8000.10,7995.70,8022.70,7998.30,7956.35,8020.55,8025.85,8000.45,7968.25,7961.25,7990.40,7975.40,7946.60,7972.75,7891.10,7933.90,7962.95,7994.25,7926.20,7884.30,7949.95,7854.45,7915.85,7876.75,7895.95,7857.45,7918.75,7897,7852.05,7861.65,7762.65,7910.05,7874.20,7859.80,7824.60,7826,7824.45,7819.50,7832.60,7752.60,7751.30,7746.65,7734.20,7728.15,7733.60,7648.00,7657.80,7686.65,7671.60,7675.10,7669,7652.05,7630.95,7651.85,7627.25,7651.05,7607.35,7636.40,7592,7601.80,7598.20,7622.20,7569.25,7586.50,7521.85,7596.35,7550,7490.85,7534.00,7459.65,7536.30,7477.95,7515.50,7428.70,7429,7482.25,7430.65,7454.40,7410.20,7416.95,7362.50,7378.75,7401,7372.00,7425.85,7382.20,7395.45,7394.05,7391.95,7341.25,7371,7337.00,7387.05,7311.85,7312.05,7332.30,7373.15,7366.95,7268,7323.30,7372.20,7377.40,7314.00,7361.10,7307.25,7295.35,7302,7304.75,7277.90,7274.30,7306.20,7308.25,7295.40,7249.50,7205,7304.60,7268.75,7292.30,7270.85,7229.55,7240.35,7274.40,7296,7291.90,7261.05,7291.85,7289.80,7271.65,7230.10,7299.35,7300,7253.60,7307.80,7247.10,7272.25,7338.10,7330.75,7284.35,7284,7304.75,7301.80,7325.45,7311.70,7379.20,7288.75,7318.30,7307,7313.50,7334.40,7328.90,7327.05,7380.40,7328.65,7341.70,7401,7344.50,7339.60,7379.20,7396.15,7417.85,7399.50,7393.65,7440,7419.20,7421.10,7428.65,7453.75,7448.95,7422.15,7455.85,7405,7389.05,7402.45,7348.90,7426.45,7398.85,7402.50,7437.00,7417,7346.85,7375.55,7418.60,7403.10,7434.05,7400.55,7345.30,7434,7344.70,7418.60,7428.70,7399.55,7412.75,7428.15,7347.05,7414,7405.00,7360.10,7420.40,7363.30,7375.90,7396.55,7323.75,7407,7407.45,7341.05,7313.65,7256.10,7314.85,7352.60,7335.80,7294,7385.60,7308.30,7293.85,7351.25,7309.90,7257.00,7288.30,7346,7252.45,7255.85,7244.50,7211.35,7229.00,7249.90,7294.30,7160,7185.60,7168.20,7207.15,7182.90,7142.70,7167.85,7148.75,7085,7110.55,7153.05,7120.40,7082.10,7113.00,7055.50,7036.25,7033,7039.55,7056.35,7000.75,7073.70,7011.95,7018.95,7016.50,6981,7081.15,6968.20,6970.25,7011.25,6960.95,6934.65,7028.10,6942,6972.15,6956.50,6956.10,6895.95,6966.10,6965.45,6912.95,6880,6909.10,6950.50,7041.30,6938.20,6889.15,6987.90,6912.95,6885,6960.25,6888.75,6904.65,6883.45,6868.40,6913.10,6866.20,6795,6938.85,6879.30,6873.75,6910.05,6919.65,6917.30,6906.80,6852,6852.60,6825.80,6857.85,6831.95,6780.00,6889.75,6813.90,6819,6846.20,6857.55,6894.25,6880.10,6844.55,6927.10,6931.70,6910,6894.30,6854.70,6892.60,6824.25,6843.45,6825.00,6867.50,6868,6834.90,6804.75,6799.80,6793.45,6848.80,6802.30,6821.70,6845,6855.45,6849.60,6910.70,6840.65,6902.95,6906.50,6891.95,6898,6861.10,6899.45,6892.25,6881.50,6857.40,6870.55,6867.00,6934,6876.40,6897.85,6883.75,6919.80,6818.30,6861.80,6899.35,6874,6958.55,6878.25,6943.70,6924.95,6924.20,6928.95,6975.10,6946,6853.00,6923.55,6949.40,6960.50,6870.75,6958.25,6940.65,6879,6941.75,6887.70,6887.15,6911.70,6907.80,6833.35,6918.65,6866,6866.40,6850.90,6869.20,6849.35,6854.45,6870.90,6846.40,6871,6812.65,6828.40,6788.40,6866.45,6810.50,6814.15,6822.85,6876,6828.85,6809.20,6779.95,6815.40)
plot(y, type='l')
One can see very clearly that the data are in a wave format. However there are some peaks that have less amplitude than others and this is not a periodic wave, also the wave is generally descending downwards.
I am told that Fourier Transform is used to essentially get the strength of different frequencies in your signal.
Based on my research of fourier transform analysis, I am told that the wave needs to oscillate around 0.
Hence I have searched for methods to normalise the data in a way that it will oscillate around 0- I used a package to identify the general downward trend and then subtracted that vector from the original raw data:
library(Rlibeemd)
x=ceemdan(y)
plot(x[,ncol(x)])
normalised=y-x[,ncol(x)]
plot(normalised, type='l')
Overall my question is: is this an appropriate/viable way to normalise my data in a way that I can then apply fft analysis to it?
I have observed the effects of this normalisation on my data and the results are much more interpretable than when I apply fft to the raw data. All that I want to know is if this normalisation method is viable?
convert.fft <- function(cs, sample.rate=1) {
cs <- cs / length(cs) # normalize
distance.center <- function(c)signif( Mod(c), 4)
angle <- function(c)signif( 180*Arg(c)/pi, 3)
df <- data.frame(cycle = 0:(length(cs)-1),
freq = 0:(length(cs)-1) * sample.rate / length(cs),
strength = sapply(cs, distance.center),
delay = sapply(cs, angle))
df
}
results from when the data is not normalised
y=c(7792.10,7693.50,7779.20,7766.55,7743.00,7738.20,7741.40,7717.40,7724.05,7816.95,7799.05,7766.35,7771.15,7689.60,7845.70,7801.85,7849.45,7826.65,7870.30,7839.80,7895.50,7838.30,7904.95,7885.00,7878.05,7956.90,7886.20,7928.50,7872.20,8006.05,7941.45,7991.60,8035.05,7927.45,8067.95,7969.80,8000.10,7995.70,8022.70,7998.30,7956.35,8020.55,8025.85,8000.45,7968.25,7961.25,7990.40,7975.40,7946.60,7972.75,7891.10,7933.90,7962.95,7994.25,7926.20,7884.30,7949.95,7854.45,7915.85,7876.75,7895.95,7857.45,7918.75,7897,7852.05,7861.65,7762.65,7910.05,7874.20,7859.80,7824.60,7826,7824.45,7819.50,7832.60,7752.60,7751.30,7746.65,7734.20,7728.15,7733.60,7648.00,7657.80,7686.65,7671.60,7675.10,7669,7652.05,7630.95,7651.85,7627.25,7651.05,7607.35,7636.40,7592,7601.80,7598.20,7622.20,7569.25,7586.50,7521.85,7596.35,7550,7490.85,7534.00,7459.65,7536.30,7477.95,7515.50,7428.70,7429,7482.25,7430.65,7454.40,7410.20,7416.95,7362.50,7378.75,7401,7372.00,7425.85,7382.20,7395.45,7394.05,7391.95,7341.25,7371,7337.00,7387.05,7311.85,7312.05,7332.30,7373.15,7366.95,7268,7323.30,7372.20,7377.40,7314.00,7361.10,7307.25,7295.35,7302,7304.75,7277.90,7274.30,7306.20,7308.25,7295.40,7249.50,7205,7304.60,7268.75,7292.30,7270.85,7229.55,7240.35,7274.40,7296,7291.90,7261.05,7291.85,7289.80,7271.65,7230.10,7299.35,7300,7253.60,7307.80,7247.10,7272.25,7338.10,7330.75,7284.35,7284,7304.75,7301.80,7325.45,7311.70,7379.20,7288.75,7318.30,7307,7313.50,7334.40,7328.90,7327.05,7380.40,7328.65,7341.70,7401,7344.50,7339.60,7379.20,7396.15,7417.85,7399.50,7393.65,7440,7419.20,7421.10,7428.65,7453.75,7448.95,7422.15,7455.85,7405,7389.05,7402.45,7348.90,7426.45,7398.85,7402.50,7437.00,7417,7346.85,7375.55,7418.60,7403.10,7434.05,7400.55,7345.30,7434,7344.70,7418.60,7428.70,7399.55,7412.75,7428.15,7347.05,7414,7405.00,7360.10,7420.40,7363.30,7375.90,7396.55,7323.75,7407,7407.45,7341.05,7313.65,7256.10,7314.85,7352.60,7335.80,7294,7385.60,7308.30,7293.85,7351.25,7309.90,7257.00,7288.30,7346,7252.45,7255.85,7244.50,7211.35,7229.00,7249.90,7294.30,7160,7185.60,7168.20,7207.15,7182.90,7142.70,7167.85,7148.75,7085,7110.55,7153.05,7120.40,7082.10,7113.00,7055.50,7036.25,7033,7039.55,7056.35,7000.75,7073.70,7011.95,7018.95,7016.50,6981,7081.15,6968.20,6970.25,7011.25,6960.95,6934.65,7028.10,6942,6972.15,6956.50,6956.10,6895.95,6966.10,6965.45,6912.95,6880,6909.10,6950.50,7041.30,6938.20,6889.15,6987.90,6912.95,6885,6960.25,6888.75,6904.65,6883.45,6868.40,6913.10,6866.20,6795,6938.85,6879.30,6873.75,6910.05,6919.65,6917.30,6906.80,6852,6852.60,6825.80,6857.85,6831.95,6780.00,6889.75,6813.90,6819,6846.20,6857.55,6894.25,6880.10,6844.55,6927.10,6931.70,6910,6894.30,6854.70,6892.60,6824.25,6843.45,6825.00,6867.50,6868,6834.90,6804.75,6799.80,6793.45,6848.80,6802.30,6821.70,6845,6855.45,6849.60,6910.70,6840.65,6902.95,6906.50,6891.95,6898,6861.10,6899.45,6892.25,6881.50,6857.40,6870.55,6867.00,6934,6876.40,6897.85,6883.75,6919.80,6818.30,6861.80,6899.35,6874,6958.55,6878.25,6943.70,6924.95,6924.20,6928.95,6975.10,6946,6853.00,6923.55,6949.40,6960.50,6870.75,6958.25,6940.65,6879,6941.75,6887.70,6887.15,6911.70,6907.80,6833.35,6918.65,6866,6866.40,6850.90,6869.20,6849.35,6854.45,6870.90,6846.40,6871,6812.65,6828.40,6788.40,6866.45,6810.50,6814.15,6822.85,6876,6828.85,6809.20,6779.95,6815.40)
head(convert.fft(fft(y)))
cycle freq strength delay
1 0 0.000000 304000.00 0.0000
2 1 1.111111 22070.00 -82.6000
3 2 2.222222 11230.00 -86.1000
4 3 3.333333 7748.00 -88.2000
5 4 4.444444 6402.00 -89.8000
6 5 5.555556 5126.00 -117.0000
7 6 6.666667 2682.00 -111.0000
results from when it is normalised
Note this time my 'convert.fft()' function does not require a normalisation method as the data are already normalised.
convert.fft2 <- function(cs, sample.rate=1) {
#cs <- cs / length(cs) # normalize
distance.center <- function(c)signif( Mod(c), 4)
angle <- function(c)signif( 180*Arg(c)/pi, 3)
df <- data.frame(cycle = 0:(length(cs)-1),
freq = 0:(length(cs)-1) * sample.rate / length(cs),
strength = sapply(cs, distance.center),
delay = sapply(cs, angle))
df
}
head(convert.fft2(fft(normalised)))
cycle freq strength delay
1 0 0.000000000 6960.00 0.0000
2 1 0.002341920 9623.00 -24.9000
3 2 0.004683841 18780.00 -53.0000
4 3 0.007025761 17520.00 169.0000
5 4 0.009367681 6201.00 167.0000
6 5 0.011709602 6988.00 147.0000
7 6 0.014051522 5647.00 144.0000
NOTE: if this is easier to do in Matlab that might be an alternative but I'm more used to R.
If it is the case that this method of normalisation is incorrect, I would be grateful if someone could suggest a better way