필터 지우기
필터 지우기

cannot get fftshift to shift frequency

조회 수: 2 (최근 30일)
Rodger Herbst
Rodger Herbst 2019년 11월 22일
답변: Sk Group 2021년 10월 27일
I am trying to verify an FFT computation by producing the original signal. Below I explain the situation. My question is in CAPS below
VACCL.csv has the following format. (no line spaces)
sec VACCL
0 1
0.125 1.002
0.25 1.002
0.375 1.007
0.5 1.002
0.625 1.002
0.75 1
0.875 1.002
1 1.005
1.125 1.005
1.25 1.005
1.375 1.002
1.5 1.002
in command line I typed:
TT = readtimetable(VACCL.csv');
Using signal analysis tool on TT, I was able to plot the original signal and a frequency response. The frequency response was plotted in Hz, but signal time was plotted in hours. In input file VACCL.csv, time was given in seconds.
I then Imported VACCL.csv as matrix with 64 bit double precision and typed
Y = fft(VACCL)
Y was generated in the workspace as complex double: 2 columns: one real, one Imaginary
When I plotted Y(:,2) on sig analyzer, the display was identical to original signal analyzer result except for axis labels: the signal was plotted in samples, while the normalized frequency was plotted from 0 to 1.0
Then I typed:
Y_SHIFTED = fftshift(Y)
When I plotted Y_SHIFTED in signal analyzer,
the time signal was broken in two halfs, left and right, and the two halves switched, while
the frequency remained normalized from 0 to 1.0.
HOW DO I GET THE FREQUENCY SHIFTED RATHER THAN THE SIGNAL?
  댓글 수: 2
Rodger Herbst
Rodger Herbst 2019년 11월 23일
Thanks; this code works great !
Star Strider
Star Strider 2019년 11월 23일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 11월 22일
You need to create the frequency vector yourself.
Probably the easiest way is to use the linspace function.
Try this:
VACCL = [ 0 1
0.125 1.002
0.25 1.002
0.375 1.007
0.5 1.002
0.625 1.002
0.75 1
0.875 1.002
1 1.005
1.125 1.005
1.25 1.005
1.375 1.002
1.5 1.002];
Ts = mean(diff(VACCL(:,1))); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = size(VACCL,1); % Signal Length
VACCLv = VACCL(:,2); % Signal Vector
Y = fft(VACCLv)/L; % Fourier Transform
Y_SHIFTED = fftshift(Y); % Shift
Fv = linspace(-Fn, Fn, size(Y,1)); % * Frequency Vector *
figure
plot(Fv, abs(Y_SHIFTED))
grid
Experiment to get different results.

추가 답변 (1개)

Sk Group
Sk Group 2021년 10월 27일

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by