DSPRelated.com
Forums

should FFT{x-mean(x)} = FFT{x}-FFT{mean(x)} ?

Started by thedean515 August 28, 2010
Hi guys,

    The Linearity property of Fourier transform says:

z(t)=af1(t)+bf2(t)

the linear combination of the terms is unaffected by the transform.
Z(ω)=aF1(ω)+bF2(ω)

and 

Z(ω) = FFT{ z(t) }.

I synthesised a signal, sn as follows. I want to remove the mean values in
the signal. According to the Fourier transform property,

FFT{x-mean(x)} = FFT{x}-FFT{mean(x)}

the left hand side should equal to the right hand side. But my simulation
suggested they are different.

Can anyone sports any mistakes I've made?

Cheers,

 ---------------------------- Code Starts Here ----------------------------


%% Load FMCW data
clear all; close all; clc;
fs = 1; % We use scaleed samling rate here
NFFT = 2048;
scale = @(y) 10*log10(abs(y));
n = 0:149;
s = 2*sin(2*pi*0.2*n');
r = 10*sin(2*pi*0.15*n');

%  Generate Data and Visulize it
for jj = 1:37
    v = 0.3*randn(150,1);
    sn(:,jj) = s + v;
    rn(:,jj) = r + v;
end
sn (:,1:10) = rn(:,1:10);
sn (:,11:end) = sn(:,11:end) + rn(:,11:end);

% Unless you want to visualize the signal :-)
% for jj = 1:37
%     [Sn(:,jj),f] = periodogram(sn(:,jj),[],NFFT,fs);
% end
% figure;
% subplot(121); plot(f,scale(Sn(:,2)))
% subplot(122); imagesc(scale(Sn)); colorbar

ii = 2;
%% Time Domain 
sn_bg = sn-repmat(mean(sn,2),1,37);
[P_bg_1, f] = periodogram(sn_bg(:,ii),hamming(size(sn_bg,1)),NFFT,fs);

%% Freq Domain
for jj = 1:size(sn,2)
    [Psn_0(:,jj), f] = periodogram(sn(:,jj),hamming(size(sn,1)),NFFT,fs);
end
P_bg_2 = Psn_0-repmat(mean(Psn_0,2),1,37);
P_bg_2 = P_bg_2(:,ii);

%% Comparisons
figure; plot(f,scale(P_bg_1),'r-'); % title('Per-Ham, Mean Removal');
hold on;
plot(f,scale(P_bg_2),'b--')
legend('FFT(x-mean(x))','FFT(x) - FFT(mean(x))')


thedean515 wrote:
> Hi guys, > > The Linearity property of Fourier transform says: > > z(t)=af1(t)+bf2(t) > > the linear combination of the terms is unaffected by the transform. > Z(ω)=aF1(ω)+bF2(ω) > > and > > Z(ω) = FFT{ z(t) }. > > I synthesised a signal, sn as follows. I want to remove the mean values in > the signal. According to the Fourier transform property, > > FFT{x-mean(x)} = FFT{x}-FFT{mean(x)} > > the left hand side should equal to the right hand side. But my simulation > suggested they are different. > > Can anyone sports any mistakes I've made? > > Cheers, > > ---------------------------- Code Starts Here ---------------------------- > > > %% Load FMCW data > clear all; close all; clc; > fs = 1; % We use scaleed samling rate here > NFFT = 2048; > scale = @(y) 10*log10(abs(y)); > n = 0:149; > s = 2*sin(2*pi*0.2*n'); > r = 10*sin(2*pi*0.15*n'); > > % Generate Data and Visulize it > for jj = 1:37 > v = 0.3*randn(150,1); > sn(:,jj) = s + v; > rn(:,jj) = r + v; > end > sn (:,1:10) = rn(:,1:10); > sn (:,11:end) = sn(:,11:end) + rn(:,11:end); > > % Unless you want to visualize the signal :-) > % for jj = 1:37 > % [Sn(:,jj),f] = periodogram(sn(:,jj),[],NFFT,fs); > % end > % figure; > % subplot(121); plot(f,scale(Sn(:,2))) > % subplot(122); imagesc(scale(Sn)); colorbar > > ii = 2; > %% Time Domain > sn_bg = sn-repmat(mean(sn,2),1,37); > [P_bg_1, f] = periodogram(sn_bg(:,ii),hamming(size(sn_bg,1)),NFFT,fs); > > %% Freq Domain > for jj = 1:size(sn,2) > [Psn_0(:,jj), f] = periodogram(sn(:,jj),hamming(size(sn,1)),NFFT,fs); > end > P_bg_2 = Psn_0-repmat(mean(Psn_0,2),1,37); > P_bg_2 = P_bg_2(:,ii); > > %% Comparisons > figure; plot(f,scale(P_bg_1),'r-'); % title('Per-Ham, Mean Removal'); > hold on; > plot(f,scale(P_bg_2),'b--') > legend('FFT(x-mean(x))','FFT(x) - FFT(mean(x))') >
On Sat, 28 Aug 2010 18:29:29 -0500, Vladimir Vassilevsky
<nospam@nowhere.com> wrote:

> > >thedean515 wrote: >> Hi guys, >> >> The Linearity property of Fourier transform says: >> >> z(t)=af1(t)+bf2(t) >> >> the linear combination of the terms is unaffected by the transform. >> Z(?&#4294967295;)=aF1(?&#4294967295;)+bF2(?&#4294967295;) >> >> and >> >> Z(?&#4294967295;) = FFT{ z(t) }. >> >> I synthesised a signal, sn as follows. I want to remove the mean values in >> the signal. According to the Fourier transform property, >> >> FFT{x-mean(x)} = FFT{x}-FFT{mean(x)} >>
[Snipped by Lyons] Hi Vladimir, thedean515's notation is fabulously confusing. If "x" is a sequence, then "mean(x)" is a single number. So what the heck could be meant by "FFT{mean(x)}"? thedean515's code is too complicated for me to read. I wonder why he didn't generate a sinewave and call it x(n). Generate a constant-level sequence and call it dc(n). Then create a signal that's y(n) = x(n) + dc(n). Then he could have proven to himself that FFT{y(n)-dc(n)} = FFT{x(n)} = FFT{y(n)} -FFT{dc(n)}. [-Rick-] [-Rick-]
On Sep 5, 9:57&#4294967295;pm, Rick Lyons <R.Lyons@_BOGUS_ieee.org> wrote:
> > &#4294967295; &#4294967295;thedean515's notation is fabulously confusing. > > If "x" is a sequence, then "mean(x)" is a > single number. &#4294967295;So what the heck could be meant > by "FFT{mean(x)}"? > > thedean515's code is too complicated for me to > read.
i didn't bother to read it any more than to see that it's MATLAB (or Octave). in that case, MATLAB syntax has the feature that when adding or subtracting a scaler to or from an array, that number is added or subtracted from every element in the array. it's a little bit of an ugly wart, because in MATLAB, a scaler is treated as a 1x1 array. so it's an exception to the rule that the number of rows and columns have to be equal to add two matrices. but, i think, with that MATLAB extension considered, we can derive meaning from "FFT{mean(x)}" and "FFT{x-mean(x)}". r b-j
Fred wrote:
>> thedean515 wrote: >> >[[various lines aggressively snipped by michael]] >> > >> >sn_bg = sn-repmat(mean(sn,2),1,37); >> >[P_bg_1, f] = periodogram(sn_bg(:,ii),hamming(size(sn_bg,1)),NFFT,fs); >> > >> > [Psn_0(:,jj), f] =
periodogram(sn(:,jj),hamming(size(sn,1)),NFFT,fs);
>> >P_bg_2 = Psn_0-repmat(mean(Psn_0,2),1,37); >> >> Yes. Time to check your code.
To be more specific, it looks like you're subtracting the mean of the fft in the second case, not the fft of the mean. (ignoring distinctions between periodogram and fft) If not, then simplify it first and re-post. Michael