자세한 설명이 없어서 대충 혼돈의 카오스중..

pffft_transform()이 가장 처음 접하는 함수이긴 한데 이걸로 하니 1Hz가 아니라 4Hz에 진동이 있는걸로 검출이 되서

pffft_transform_ordered()로 바꾸니 의도한 대로 분석이 되서 일단 쓰는데, 무슨 차이인진 모르겠다.

 

int n = 32000;
int nc = ( n / 2 ) + 1;

int Nfloat = n;
int Nbytes = Nfloat * sizeof(float);

float *X = pffft_aligned_malloc(Nbytes);
float *Y = pffft_aligned_malloc(Nbytes);
float *Z = pffft_aligned_malloc(Nbytes);

PFFFT_Setup *s = pffft_new_setup(n, PFFFT_REAL);

for(int i = 0; i < 8; i++)
    pffft_transform_ordered(s, X, Z, 0, PFFFT_FORWARD);
for ( i = 0; i < nc; i++ )
    printf ( "  %3d,%12f,%12f,%12f,%12f,%12f\n", i, Z[i*2], Z[i*2+1],  
        sqrt(Z[i*2] * Z[i*2] +  Z[i*2+1] * Z[i*2+1]),
        atan2(Z[i*2+1], Z[i*2]),
        atan2(Z[i*2+1], Z[i*2]) * 180 / PI
    );

pffft_aligned_free(Z);
pffft_aligned_free(Y);
pffft_aligned_free(X);
pffft_destroy_setup(s);

[링크 : https://bitbucket.org/jpommier/pffft/src/master/]

 

성능비교 테스트. pffft가  double을 미지원하는 것을 제외하면 최소 4배는 빠르게 처리한다고 보면 될 듯.

(complex는 double이 되긴 한데 real은 float만 되는 듯?)

fftw
2023-06-15 02:40:48.089
2023-06-15 02:40:48.109 --- plan 생성 20ms
2023-06-15 02:40:48.133 --- 32k 8ch 연산 23~24ms

pffft
2023-06-15 02:40:48.136
2023-06-15 02:40:48.139 --- plan 생성 3ms
2023-06-15 02:40:48.146 --- 32k 8ch 연산 6~7ms

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

fft window type과 진폭 보정계수  (0) 2023.07.04
fft window 함수  (0) 2023.07.03
fft 결과의 amplitude가 0.5가 나오는 이유  (0) 2023.06.13
overlap kissfft  (0) 2023.06.12
fft size overlap window size  (0) 2023.06.12
Posted by 구차니
프로그램 사용/synergy2023. 6. 15. 10:27

접속도 다 정상적으로 되는데 마우스가 안넘어 간다.

그래서 찾아보니 barrier가 wayland를 지원하지 않아 발생하는 문제일 듯.

 

아무튼 로그인 시에 세션을 ubuntu x.org로 선택하니 문제없이 작동한다.

[링크 : https://github.com/debauchee/barrier/issues/1659]

 

하여간에.. 멀 하던.. wayland는 갈길이 먼가...

'프로그램 사용 > synergy' 카테고리의 다른 글

synergyc - synergy client for linux  (2) 2010.03.20
시너지 (Synergy) for linux  (4) 2010.01.15
시너지 (Synergy) - KVM 프로그램(?)  (4) 2009.11.13
Posted by 구차니

이산 푸리에 변환 자체가 원래 그런거다.. 라는 의미인가?

Because the discrete Fourier transform matches the input signal with complex exponentials and a cosine is the sum of two complex exponentials divided by 2. The same is true of a sine (except it's divided by 2i)
That is where the factor of 1/2 is coming from. Since you have a real-valued signal, if you are only interested in looking at the magnitude, you can just keep the "positive" frequencies and scale them by 2.
ThemeCopy

[링크 : https://kr.mathworks.com/matlabcentral/answers/84141-why-fft-function-returns-amplitude-divided-by-2]

 

수식을 흐린눈으로 봐도.. 모르겠다.

[링크 : https://en.wikipedia.org/wiki/Discrete_Fourier_transform]

 

fftw 가 실제로 계산하는 것이라는데 수식상으로는 e^-2 밖에 눈에 안띄는데 어떤 부분이 divide by 2 부분일까?

The forward (FFTW_FORWARD) discrete Fourier transform (DFT) of a 1d complex array X of size n computes an array Y, where:


.The backward (FFTW_BACKWARD) DFT computes:.

[링크 : https://www.fftw.org/fftw3_doc/The-1d-Discrete-Fourier-Transform-_0028DFT_0029.html]

 

 

+

2023.06.16

이해를 못하고 있었는데 아래글을 읽고 아! 싶어졌다.

 

Size of FFT in 1D is not half of the signal length. It's still the signal length (assuming FFT length was of the signal length). However for real data, due to conjugate symmetryhalf of this is redundant and can be dicarded to reduce storage. Note however that, when it's required to process the FFT data, you have to construct the full length from the half and proceed.

This is also the reason why spectral analysis software display only positive frequencies for real data; i.e, negative frequencies will be a mirror copy (of the magnitude) of positive frequencies.

But you don't have to discard the half. You can just retain it.

For image processing, the symmetry of FFT for real input data again exist and if you wish you can also dicard half of the image FFT data. Whether this will be employed or not depends on the intentions of the package.

아니요.

1D에서 FFT의 크기는 신호 길이의 절반이 아닙니다. 여전히 신호 길이입니다(FFT 길이가 신호 길이라고 가정). 그러나 실제 데이터의 경우 공액 대칭으로 인해 이 중 절반이 중복되며 저장 공간을 줄이기 위해 버려질 수 있습니다. 단, FFT 데이터 처리가 필요한 경우 절반에서 전체 길이를 구성하여 진행해야 합니다.

이것이 스펙트럼 분석 소프트웨어가 실제 데이터에 대해 양의 주파수만 표시하는 이유이기도 합니다. 즉, 음수 주파수는 양수 주파수의 (크기의) 거울 사본이 될 것입니다.

그러나 절반을 버릴 필요는 없습니다. 그대로 유지하시면 됩니다.

이미지 처리의 경우 실제 입력 데이터에 대한 FFT의 대칭이 다시 존재하며 원하는 경우 이미지 FFT 데이터의 절반을 버릴 수도 있습니다. 이것이 사용될지 여부는 패키지의 의도에 따라 다릅니다.

[링크 : https://dsp.stackexchange.com/questions/55239/why-is-the-size-of-results-from-fft-half-the-size-of-the-input-while-that-is-no]

[링크 : https://brianmcfee.net/dstbook-site/content/ch06-dft-properties/Conjugate-Symmetry.html]

 

예전 mathwork 에서 double sided amplitude 라는 그래프가 있었는데

실제로 FFT 변환은 -N/2 ~ 0 ~ N/2 대역에 대해서 나오지만

부호만 다를뿐 대칭된 정보이기에 메모리가 귀하던 시절 메모리 절약을 위해 절반을 휙~ 날려 버린 듯.

그래서 FFT 변환(? DFT?)을 하면 일반적으로 0~N/2 까지의 주파수가 나오고, 그걸 대칭시켜서 써야 하는 듯.

 

[링크 : https://kr.mathworks.com/help/matlab/ref/fft.html]

 

이해가 갈 듯.. 안 갈 듯 한데

복소수 공간에서 대칭적으로 나오기 때문에 한쪽만 계산하면 다른쪽 벡터가 없어서 절반 길이만 나온다고 보면 될 것 같기도?

[링크 : https://brianmcfee.net/dstbook-site/content/ch06-dft-properties/Conjugate-Symmetry.html]

 

+

켤례 복소수 하니 먼가 단어가 익숙한 느낌 (-_-)

실수를 복소수로 바꾸는건 허수가 0인 걸로 바꾸면 되는거고

켤레 복소수는 실수는 냅두고 허수부 부호만 뒤집으면 된다고.

공액(켤레) 복소수 

[링크 : https://kwon-jjing.tistory.com/40]

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

fft window 함수  (0) 2023.07.03
pFFFT 사용법  (0) 2023.06.15
overlap kissfft  (0) 2023.06.12
fft size overlap window size  (0) 2023.06.12
fftw 라이브러리 사용 테스트  (0) 2023.06.12
Posted by 구차니

fftw에서 overlap 하는 예제는 못 찾았고

kissfft를 이용해서 (bsd-3 clause) 하는 예제도 아니고 걍.. git 발견

 

아무튼 아래와 같이 입력을 중첩하고 결과를 낸다는데

그림을 봐도 어떻게 데이터를 구성하고 합쳐내는지 감이 안온다.


overlap add
input

output


[링크 : https://github.com/fbdp1202/DSP_Overlap-Save_Overlap_Add]

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

pFFFT 사용법  (0) 2023.06.15
fft 결과의 amplitude가 0.5가 나오는 이유  (0) 2023.06.13
fft size overlap window size  (0) 2023.06.12
fftw 라이브러리 사용 테스트  (0) 2023.06.12
fft 잘못 사용하고 있었나?  (0) 2023.06.02
Posted by 구차니

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

fft 결과의 amplitude가 0.5가 나오는 이유  (0) 2023.06.13
overlap kissfft  (0) 2023.06.12
fftw 라이브러리 사용 테스트  (0) 2023.06.12
fft 잘못 사용하고 있었나?  (0) 2023.06.02
fft 라이브러리 목록  (0) 2023.06.01
Posted by 구차니

fftw()에

1. 입력 범위는 크게 의미 없으나 0.0~1.0 사이로 1의 높이로 정규화 하는 것이 용이할 수도 있음

2. DC 성분은 fft_result[0]에 있으며 / Sample 을 하면 DC 성분의 높이를 알 수 있음

2. sine() 성분은 fft_result[1~1/N]에 있으며 / Sample 을 하면 sine() 성분의 높이를 알 수 있음. (+/- x로 해석?)

3. phase는 모르겠다 -ㅁ-

-----------------

입력 값 범위 테스트

그냥 정상적인 0~1 사이의 실수 범위 입력

  for ( i = 0; i < n; i++ )
    in[i] = ( double ) sin ( 360.0f * (double)i / n  * 3.1415927f / 180.0f);

 

입력 범위 확인

출력 결과

도대체.. 1Hz 에서 32는 무슨 의미냐..

샘플링 횟수로 나눌게 아니라 최대 주파수 로 나누어야 하는건가?

  Input Data:

    0,    0.000000
    1,    0.098017
    2,    0.195090

...

  Output FFT Coefficients:

    0,   -0.000000,    0.000000,    0.000000
    1,    0.000003,  -32.000000,   32.000000
    2,   -0.000000,    0.000001,    0.000001

 

걍 무지성으로 100,000 곱하기(0 다섯개)

  for ( i = 0; i < n; i++ )
    in[i] = ( double ) sin ( 360.0f * (double)i / n  * 3.1415927f / 180.0f) * 100000;

 

FFT 결과 자체는 동일하지만(?) 결과 자체는 곱해준 100,000 만큼 증가

  Input Data:

    0,    0.000000
    1, 9801.714305
    2,19509.032738

...

  Output FFT Coefficients:

    0,   -0.008742,    0.000000,    0.008742
    1,    0.271011,-3199999.955619,3200000.000000
    2,   -0.008742,    0.118444,    0.118767

 

위상(phase)

동일 값, 위치만 8 칸 미룸(8/64 = 1/8 phase)

phase는 atan(b/a) 로 계산한다는데 일단 하라는대로 하니, -1.5 대충 pi/2 정도 최대값으로 나오는 듯.

  Input Data:

    0,    0.000000
    1, 9801.714305
    2,19509.032738
    3,29028.468510
    4,38268.344246
    5,47139.674887
    6,55557.024665
    7,63439.329895
    8,70710.679664
    9,77301.046896
   10,83146.962748
   11,88192.127851
   12,92387.954506
   13,95694.034604
   14,98078.528786
   15,99518.473069
   16,100000.000000


  Output FFT Coefficients:

    0,   -0.008742,    0.000000,    0.008742,    3.141593
    1,    0.271011,-3199999.955619,3199999.955619,   -1.570796
    2,   -0.008742,    0.118444,    0.118767,    1.644472
  Input Data:

    0,70710.679664
    1,77301.046896
    2,83146.962748
    3,88192.127851
    4,92387.954506
    5,95694.034604
    6,98078.528786
    7,99518.473069
    8,100000.000000
    9,99518.472212
   10,98078.527081
   11,95694.032066
   12,92387.951160
   13,88192.123730
   14,83146.957891
   15,77301.041350
   16,70710.673482

  Output FFT Coefficients:

    0,    0.119650,    0.000000,    0.119650,    0.000000
    1,2262741.972266,-2262741.421146,3199999.995629,   -0.785398
    2,   -0.048261,    0.083753,    0.096663,    2.093553

[링크 : https://blog.naver.com/lyb0684/221159899932]

 

atan과 atan2는 범위가 다르다고 한다. (범위가 달라지는 거지 radian을 degree로 계산하는게 달라지는건 아니니..)

atan
RETURN VALUE
       On success, these functions return the principal value of the arc  tan‐
       gent of x in radians; the return value is in the range [-pi/2, pi/2].

atan2
RETURN VALUE
       On  success, these functions return the principal value of the arc tan‐
       gent of y/x in radians; the return value is in the range [-pi, pi].

 

아무튼 귀찮으니 atan2의 radian 값 출력을 각도로 변환해서 출력해보면

  for ( i = 0; i < nc; i++ )
  {
      printf ( "  %3d,%12f,%12f,%12f,%12f,%12f\n", i, out[i][0], out[i][1],  
      sqrt(out[i][0] * out[i][0] +  out[i][1] * out[i][1]),
      atan2(out[i][1], out[i][0]) * 180 / PI,
      atan(out[i][1] / out[i][0]) * 180 / PI
  }

[링크 : https://spiralmoon.tistory.com/entry/프로그래밍-이론-두-점-사이의-절대각도를-재는-atan2]

 

뭔가 잘못 계산한 느낌이다?

+ 0      1,    0.000003,  -32.000000,   32.000000,  -89.999993,  -89.999993
+ 8     1,   22.627420,  -22.627414,   32.000000,  -44.999992,  -44.999992
+ 16     1,   32.000000,    0.000004,   32.000000,    0.000008,    0.000008
+ 32     1,   -0.000006,   32.000000,   32.000000,   90.000007,  -89.999988

 

 

+

DC성분

아래와 같이 1.0 값으로 64개를 만들어 fft를 돌리면

  for ( i = 0; i < n; i++ )
  { 
    in[i] = ( double )1.0f;
  }

 

64번 샘플링한게 1씩 있어서 합산하여 64가 나오나?

아무튼 실수부의 경우 -와 +의 차이가 있지만 abs()로 처리하면 부호가 사라지니 같은 값으로 보이게 된다.

  Output FFT Coefficients:

    0,   64.000000,    0.000000,   64.000000,    0.000000,    0.000000,    0.000000
  Output FFT Coefficients:

    0,  -64.000000,    0.000000,   64.000000,    3.141593,  179.999995,   -0.000000

 

0.5로 하면 32가 나온다. 도대체 이 DC는 어떻게 해석해야 할까?

  Output FFT Coefficients:

    0,   32.000000,    0.000000,   32.000000,    0.000000,    0.000000,    0.000000

 

sin() * 0.5는 DC 성분이 0으로 나오고 1Hz 에서는 16 으로 나온다(0.5로 봐야하나?)

  Output FFT Coefficients:

    0,   -0.000000,    0.000000,    0.000000,    3.141593,  179.999995,   -0.000000
    1,    0.000001,  -16.000000,   16.000000,   -1.570796,  -89.999993,  -89.999993
    2,   -0.000000,    0.000001,    0.000001,    1.644472,   94.221297,  -85.778698

 

sin() * 0.5 + 0.5(0.0~1.0=1.0) 하면 DC 32에 1Hz 16 (1 * 16?)

 

걍 맘편하게 주파수는 진폭, DC는 

  Output FFT Coefficients:

    0,   32.000000,    0.000000,   32.000000,    0.000000,    0.000000,    0.000000
    1,    0.000001,  -16.000000,   16.000000,   -1.570796,  -89.999993,  -89.999993
    2,   -0.000000,    0.000001,    0.000001,    1.644472,   94.221297,  -85.778698

 

sin() 은(-1.0~1.0=2.0 Height?) DC 0 1Hz 32 (2 * 16?)

 

  Output FFT Coefficients:

    0,   -0.000000,    0.000000,    0.000000,    3.141593,  179.999995,   -0.000000
    1,    0.000003,  -32.000000,   32.000000,   -1.570796,  -89.999993,  -89.999993

 

sin() * 0.5 + 0.5 (0.0~1.0=1.0) 에 절반의 파형만 줄 경우

1Hz에 18 

  Output FFT Coefficients:

    0,   26.177734,    0.000000,   26.177734,    0.000000,    0.000000,    0.000000
    1,    0.500000,  -18.177734,   18.184609,   -1.543297,  -88.424406,  -88.424406
    2,   -3.403504,   -0.000000,    3.403504,   -3.141593, -179.999990,    0.000005

 

sin(2x)

 

sin 주기가 늘어났다고 해서 16이 아니게 되는건 또 아니네?

그 와중에 0.5의 DC는 또 32.. 도대체 머냐고?!

0.5 * 64 = 32

sine 16/32 = 0.5. 혹시 +-0.5 라는건가?

  Output FFT Coefficients:

    0,   32.000000,    0.000000,   32.000000,    0.000000,    0.000000,    0.000000
    1,   -0.000000,   -0.000001,    0.000001,   -1.716660,  -98.357374,   81.642621
    2,    0.000003,  -16.000000,   16.000000,   -1.570796,  -89.999988,  -89.999988
    3,   -0.000000,    0.000001,    0.000001,    1.652756,   94.695926,  -85.304069
    4,   -0.000000,    0.000001,    0.000001,    1.718417,   98.458014,  -81.541981

 

혹시나 해서 sin(2x) * 0.1 + 0.9 해보는데

57.6

산술적으로는 64 * 0.9 = 57.6

3.2 / 32 = 0.1 이니.. DC랑 혼합될 때랑 단독일때랑 다르게 나오나?

(+- 0.1 로 해석하면 쉬울지도?)

  Output FFT Coefficients:

    0,   57.600000,    0.000000,   57.600000,    0.000000,    0.000000,    0.000000
    1,   -0.000000,   -0.000000,    0.000000,   -1.716660,  -98.357374,   81.642621
    2,    0.000001,   -3.200000,    3.200000,   -1.570796,  -89.999988,  -89.999988
    3,   -0.000000,    0.000000,    0.000000,    1.652756,   94.695926,  -85.304069

 

sin(2x)의 절반 파형만 도배!

고조파 처럼 나오네?

DC 52.3

4Hz 6.8, 8Hz 1.42, 12Hz 0.65, 16Hz 0.39, 20Hz 0.28, 24Hz 0.23, 28Hz0.20,  32Hz 0.19 (합계 10.251662)

  Output FFT Coefficients:

    0,   52.306340,    0.000000,   52.306340,    0.000000,    0.000000,    0.000000
    1,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
    2,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
    3,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
    4,   -6.856612,   -0.000001,    6.856612,   -3.141593, -179.999990,    0.000005
    5,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
    6,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
    7,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
    8,   -1.425690,   -0.000000,    1.425690,   -3.141592, -179.999986,    0.000009
    9,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
   10,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
   11,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
   12,   -0.652365,   -0.000000,    0.652365,   -3.141592, -179.999983,    0.000012
   13,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
   14,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
   15,    0.000000,    0.000000,    0.000000,    0.000000,    0.000000,        -nan
   16,   -0.397825,   -0.000000,    0.397825,   -3.141592, -179.999982,    0.000013
   17,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   18,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   19,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   20,   -0.286168,   -0.000000,    0.286168,   -3.141592, -179.999983,    0.000012
   21,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   22,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   23,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   24,   -0.231164,   -0.000000,    0.231164,   -3.141592, -179.999986,    0.000009
   25,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   26,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   27,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   28,   -0.204855,   -0.000000,    0.204855,   -3.141593, -179.999990,    0.000005
   29,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   30,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   31,    0.000000,   -0.000000,    0.000000,   -0.000000,   -0.000000,        -nan
   32,   -0.196983,    0.000000,    0.196983,    3.141593,  179.999995,   -0.000000

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

overlap kissfft  (0) 2023.06.12
fft size overlap window size  (0) 2023.06.12
fft 잘못 사용하고 있었나?  (0) 2023.06.02
fft 라이브러리 목록  (0) 2023.06.01
fftw 다차원 분석  (0) 2023.05.27
Posted by 구차니

freecad로 fan 설계

[링크 : https://www.youtube.com/watch?v=fdikenPo4pE]

 

freecad로 설계한 도면을 salome를 이용하여 mesh(?)로 변환

[링크 : https://www.youtube.com/watch?v=FwseuCiSdiE]

[링크 : https://www.salome-platform.org/?page_id=15]

[링크 : https://www.salome-platform.org/]

 

openfoam + paraview

[링크 : https://www.youtube.com/watch?v=79-x2YQVE6Q]

[링크 : https://github.com/20jeka08/OpenFOAM_Propeller_simpleFoam] openfoam 설정(?) 파일

'프로그램 사용 > openFOAM' 카테고리의 다른 글

mpirun illegal instruction  (0) 2023.09.01
openFOAM tutorial with youtube  (0) 2023.05.24
openfoam on ubuntu  (0) 2023.05.24
openFOAM tutorial  (4) 2023.05.24
openfoam7 on ubuntu 18.04  (0) 2020.08.09
Posted by 구차니

gnuplot이 논문 등에서 그래프 그리는 용도로 많이 언급되는데 써보는건 첨인듯..

 

인터프리터(?)에서 아래와 같이 명령을 주면 된다고 한다.

gnuplot:> splot [2:-1] [-1:2] 3*x**2 + 2y**2

[링크 : https://namu.wiki/w/gnuplot]

 

혹시나 해서 gnuplot-qt를 깔았는데 저 gui가 qt 기반인건가?

$ gnuplot

G N U P L O T
Version 5.4 patchlevel 2    last modified 2021-06-01 

Copyright (C) 1986-1993, 1998, 2004, 2007-2021
Thomas Williams, Colin Kelley and many others

gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type "help FAQ"
immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'
gnuplot> splot [2:-1] [-1:2] 3*x**2 + 2y**2
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

gnuplot> splot [2:-1] [-1:2] 3*x**2 + 2y**2
                                       ^
         unexpected or unrecognized token: y

gnuplot> quit

 

아무튼 이쁘게 잘 그려준다.

 

csv 파일을 그리려면 ,를 구분자로 설정해주면 되고

set datafile separator ','
plot "test.csv" using 0:1 with lines

[링크 : https://raymii.org/s/tutorials/GNUplot_tips_for_nice_looking_charts_from_a_CSV_file.html]

[링크 : https://stackoverflow.com/questions/48885697/gnuplot-graph-csv]

 

using 뒤에 숫자는 X 축과 Y축에 대해서 설정하는 것이고, 기본적으로 1 열에 대해서만 그래프를 그려준다.

using 1:3 파일에 있는 1열(X축)과 3열(Y축)을 사용하겠음

[링크 : https://m.blog.naver.com/gfeel323/40201727680]

 

여러 열을 한 그래프에 그리고 싶으면 아래와 같이  , "" 하고 using 구문을 추가해도 되고, for 문을 이용해서 반복해도 된다.

> plot "tt.csv" using 0:1 with lines, "" using 0:2 with lines
> plot for [col=1:4] 'file' using 0:col with lines

[링크 : https://stackoverflow.com/questions/16073232/gnuplot-plotting-a-file-with-4-columns-all-on-y-axis]

[링크 : https://raymii.org/s/tutorials/GNUplot_tips_for_nice_looking_charts_from_a_CSV_file.html]

 

만약 csv 파일에 일련번호로 쓸 내용이 없다면(대개는 시간이 있긴 하지만)

아래의 명령을 이용하여 x 축에 pseudocolumns를 추가해줄 수 있다고 한다.

가장 편한건 x축 지정하지 않는 using n이 무난한 듯.

plot "file.dat" using (column(0)):3

You can even use plot "file.dat" using 0:3
Or, as pointed out in the other answer, even plot "file.dat" using 3

[링크 : https://stackoverflow.com/questions/9664472/having-automatic-x]

 

stackoverflow에 내용을 참조해서 도움말을 보니 column("컬럼명") 혹은 column("컬럼 번호") 로 쓰는데

인덱스는 0부터가 아니라 1부터 시작되는 듯

gnuplot> help plot datafile using
// 생략
 if the data file contains
       Height    Weight    Age
       val1      val1      val1
       ...       ...       ...
 then the following plot commands are all equivalent
       plot 'datafile' using 3:1, '' using 3:2
       plot 'datafile' using (column("Age")):(column(1)), \
                    '' using (column("Age")):(column(2))
       plot 'datafile' using "Age":"Height", '' using "Age":"Weight"

 

그렇기에 (column(0)) 을 해주면 되는데 column(0)에러 난다.(!)

gnuplot> help plot datafile using pseudocolumns
 Expressions in the `using` clause of a plot statement can refer to additional
 bookkeeping values in addition to the actual data values contained in the input
 file. These are contained in "pseudocolumns".
       column(0)   The sequential order of each point within a data set.
                   The counter starts at 0, increments on each non-blank,
                   non-comment line, and is reset by two sequential blank
                   records.  The shorthand form $0 is available.
       column(-1)  This counter starts at 0, increments on a single blank line,
                   and is reset by two sequential blank lines.
                   This corresponds to the data line in array or grid data.
                   It can also be used to distinguish separate line segments
                   or polygons within a data set.
       column(-2)  Starts at 0 and increments on two sequential blank lines.
                   This is the index number of the current data set within a
                   file that contains multiple data sets.  See `index`.
       column($#)  The special symbol $# evaluates to the total number of
                   columns available, so column($#) refers to the last
                   (rightmost) field in the current input line.
                   column($# - 1) would refer to the last-but-one column, etc.

 

터미널 변경은 set terminal을 쓰면 된다.

$ gnuplot

G N U P L O T
Version 5.4 patchlevel 2    last modified 2021-06-01 

Copyright (C) 1986-1993, 1998, 2004, 2007-2021
Thomas Williams, Colin Kelley and many others

gnuplot home:     http://www.gnuplot.info
faq, bugs, etc:   type "help FAQ"
immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'

gnuplot> set terminal dumb
Terminal type is now 'dumb'
Options are 'feed  size 79, 24 aspect 2, 1 mono'

[링크 : https://www.postgresql.kr/blog/gnuplot_dumb_terminal.html]

 

같은 그래프를 dump과

 

qt로 설정해서 출력한 모양

 

qt 에서 휠 드래그로 중심이동은 안되고

ctrl - wheel로 x축, y축 확대

ctrl - shift- wheel은 x 축 확대

shift - wheel 혹은 alt -wheel 로 x축 이동

wheel 로 y 축 이동이 기본 값으로 지정된다.

'프로그램 사용 > gnuplot' 카테고리의 다른 글

gnuplot  (0) 2022.06.13
Posted by 구차니

입력값을 정규화 하려고 했는데

fftw를 쓴다고 알려진 matlab의 예제를 보니

입력값 범위로 정규화하는게 아니라(입력 값이 8bit 라면 /256 으로 0~1 사이 값으로..)

입력 받는 샘플의 갯수로 정규화 해줘야 하는 건가?

 

아무튼 정규화 했다고 생각했는데 진폭이 이상하게 1이상의 값이 나왔는데

그거 탓이었나 싶기도 하고.. 다시 테스트 해봐야 할 듯

 

Fs = 1000;            % Sampling frequency                    
T = 1/Fs;             % Sampling period       
L = 1500;             % Length of signal
t = (0:L-1)*T;        % Time vector

푸리에 변환을 계산합니다.

Y = fft(X);
양방향 스펙트럼 P2를 계산합니다. 그런 다음, P2와 짝수 값 신호 길이 L을 기반으로 하여 단방향 스펙트럼 P1을 계산합니다.

P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

[링크 : https://kr.mathworks.com/help/matlab/ref/fft.html]

 

fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out,
                           fftw_r2r_kind kind, unsigned flags);
fftw_plan fftw_plan_r2r_2d(int n0, int n1, double *in, double *out,
                           fftw_r2r_kind kind0, fftw_r2r_kind kind1,
                           unsigned flags);
fftw_plan fftw_plan_r2r_3d(int n0, int n1, int n2,
                           double *in, double *out,
                           fftw_r2r_kind kind0,
                           fftw_r2r_kind kind1,
                           fftw_r2r_kind kind2,
                           unsigned flags);
fftw_plan fftw_plan_r2r(int rank, const int *n, double *in, double *out,
                        const fftw_r2r_kind *kind, unsigned flags);

[링크 : https://www.fftw.org/fftw3_doc/More-DFTs-of-Real-Data.html]

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

fft size overlap window size  (0) 2023.06.12
fftw 라이브러리 사용 테스트  (0) 2023.06.12
fft 라이브러리 목록  (0) 2023.06.01
fftw 다차원 분석  (0) 2023.05.27
fft phase 연산  (0) 2023.04.07
Posted by 구차니

'프로그램 사용 > fft, fftw' 카테고리의 다른 글

fftw 라이브러리 사용 테스트  (0) 2023.06.12
fft 잘못 사용하고 있었나?  (0) 2023.06.02
fftw 다차원 분석  (0) 2023.05.27
fft phase 연산  (0) 2023.04.07
fftw input range?  (0) 2023.04.07
Posted by 구차니