欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

fftshift - Shift zero-frequency component to center of spectrum

最编程 2024-08-14 14:35:14
...

You can process multiple 1-D signals by representing them as rows in a matrix. Then use the dimension argument to compute the Fourier transform and shift the zero-frequency components for each row.

Create a matrix A whose rows represent two 1-D signals, and compute the Fourier transform of each signal. Plot the power for each signal.

fs = 100;               % sampling frequency
t = 0:(1/fs):(10-1/fs); % time vector
S1 = cos(2*pi*15*t);
S2 = cos(2*pi*30*t);
n = length(S1);
A = [S1; S2];
X = fft(A,[],2);
f = (0:n-1)*(fs/n);     % frequency range
power = abs(X).^2/n;    % power
plot(f,power(1,:),f,power(2,:))

Shift the zero-frequency components, and plot the zero-centered power of each signal.

Y = fftshift(X,2);
fshift = (-n/2:n/2-1)*(fs/n); % zero-centered frequency range
powershift = abs(Y).^2/n;     % zero-centered power
plot(fshift,powershift(1,:),fshift,powershift(2,:))