'Calculate power spectral density in R but define output length
I have 3 different signals. I want to calculate their spectral density and then do some extra analysis. The 3 signals have different lengths so when I find spectral density the output is of different lengths. I have tried:
pspectrum; eegfit; fft
but none of them seems to have such an option. In MATLAB this was fairly straightforward
fft(signal,output_length)
so I think I am missing a basic function here....
Solution 1:[1]
I found the solution here https://dsp.stackexchange.com/questions/60322/matlab-and-r-functions-for-fft-n-point-fft-and-dimension-issue
It turns out that fft(x,n) in MATLAB just pads with 0 or truncates depending on the size of x.
EDIT: Just to clarify that MATLAB truncates or pads x (input signal) and not the fft output (I found out the hard way). So in R you have to do the following:
- Fix the size of input signal
- Run fft as usual
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
