Reply by Walter Roberson September 7, 20102010-09-07
On 06/09/10 9:43 PM, Greg Heath wrote:

> Next time use a single submission with a comma separated > distribution list; e.g., > > Newsgroups: comp.dsp, comp.soft-sys.matlab.
Technical note: there should not be any spaces between the list of newsgroups. Newsgroups: comp.dsp,comp.soft-sys.matlab Your posting software might be forgiving and fix this for you, but the technical standards say that the spaces must not be there.
Reply by Greg Heath September 6, 20102010-09-06
On Aug 28, 2:03&nbsp;pm, "thedean515" <jiangwei0515@n_o_s_p_a_m.gmail.com>
wrote:
> Hi guys, > > &nbsp; &nbsp; 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(&omega;)=aF1(&omega;)+bF2(&omega;) > > and > > Z(&omega;) = 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,
The most egregious mistake you made was wasting helpers time by separately sending identical posts to comp.dsp and comp.soft-sys.matlab. Next time use a single submission with a comma separated distribution list; e.g., Newsgroups: comp.dsp, comp.soft-sys.matlab. Greg Heath
Reply by Fred Marshall August 29, 20102010-08-29
Tim Wescott wrote:

> > Try _just_ what you're talking about above, without windowing. Then go > from there. >
Good advice. Or, just window the sequence before doing anything else and proceed from there just as intended without further consideration of the window - it's just a new sequence to deal with. Fred
Reply by Tim Wescott August 29, 20102010-08-29
On 08/28/2010 11:03 AM, 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(&omega;)=aF1(&omega;)+bF2(&omega;) > > and > > Z(&omega;) = 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 ----------------------------
(and gets snipped) I see windowing in the code -- if you're windowing x you need to subtract the mean _after_ windowing; subtracting the mean, then windowing, means that instead of finding fft(x - mean(x)) you're finding fft((x - mean(x)) .* window). I think you'll find that fft(mean(x) * window) has energy at a lot more places than fft(mean(x)) does. Try _just_ what you're talking about above, without windowing. Then go from there. If there's still issues, then make sure they're not numeric. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by SPHiNX August 28, 20102010-08-28
Hi,

x-mean(x) ??

If the x is a sample value, then mean(x) is x :-)
This means mean(x) = x
Then x-mean(x) = ZERO --> FFT(x) = FFT(mean(x)) ;-)

BR,
SPHiNX


>Yes. Time to check your code. > >Also, complicated code like that is pretty lazy dude! I wouldn't even >read it. Easier to write something simpler like this which makes the
point:
> >x=rand(64,1); >y(1:64)=mean(x); %did you do this? Easy mistake to not do this..... >y=y'; >x1=x-y; >xdiff=x-y-x1 >fx=fft(x); >fy=fft(y); >fx1=fft(x1); >fdiff=fx-fy-fx1 > >Shows that the functions are equal in time and equal in frequency >because their differences are zero (or as close as one can get
numerically).
> >Fred >
Reply by Fred Marshall August 28, 20102010-08-28
Yes.  Time to check your code.

Also, complicated code like that is pretty lazy dude!  I wouldn't even 
read it.  Easier to write something simpler like this which makes the point:

x=rand(64,1);
y(1:64)=mean(x);  %did you do this?  Easy mistake to not do this.....
y=y';
x1=x-y;
xdiff=x-y-x1
fx=fft(x);
fy=fft(y);
fx1=fft(x1);
fdiff=fx-fy-fx1

Shows that the functions are equal in time and equal in frequency 
because their differences are zero (or as close as one can get numerically).

Fred
Reply by thedean515 August 28, 20102010-08-28
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(&omega;)=aF1(&omega;)+bF2(&omega;)

and 

Z(&omega;) = 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))')