Thread Subject: Why does the frequency spectrum shift?

Subject: Why does the frequency spectrum shift?

From: waystark@yahoo.com (Bobby)

Date: 8 Nov, 2004 10:24:51

Message: 1 of 7

I've designed lowpass FIR filter with cutoff frequency 3kHz. I've
plotted its magnitude and phase response which looks OK.

Now I feed that filter with the signal which contains two frequencies
150 Hz and 4 kHz: s = 100*cos(300*pi*t + pi/4) + 20*cos(8000*pi*t -
pi/3);

The sampling frequency is 10 kHz

In the following Matlab code I plot frequency spectrum of these
original and filtered signals.

On the first plot I can see two spikes which correspond to frequencies
150 Hz and 4 kHz.

On the second plot I see only one big spike at 3.4 kHz and I don't
understand why this is happening. I expected to se the only spike
corresponding to 150 Hz, since 4 kHz should be filtered out.

Obviously there is some error in plotting filtered signal and I don't
understand what is wrong. Again the filter itself is OK because, I
plotted its Magnitude and Phase response and it looks fine.

Can anyone look at the code below and tell me what is wrong with
plotting filtered output signal? Thank you in advance.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Original Signal

Fs = 10000;
t = (1:512)/Fs;
s1 = sin(2*pi*t*5); s2=sin(2*pi*t*15); s3=sin(2*pi*t*30);
%s = s1+s2+s3;

s = 100*cos(300*pi*t + pi/4) + 20*cos(8000*pi*t - pi/3);

S = fft(s,512);

w = (0:255)/256*(Fs/2);
subplot(2,1,1) ;
plot(w,abs([S(1:256)]));
xlabel('Frequency (Hz)');
ylabel('Original Signal Spectrum');
grid;

% Kaiser Filter Design
wp=0.6*pi; ws=0.62*pi; d=0.05;
A=-20*log10(d);
if A < 21;
beta=0;
elseif A > 50;
beta=0.1102*(A-8.7);
else;
beta=0.5842*(A-21)^0.4 + 0.07886*(A-21);
end
M=round((A-8)/(2.285*(ws-wp)));
wc=(wp+ws)/2;

n=0:M; del=floor(M/2);
hLP=(wc/pi)*sinc((wc/pi)*(n-del));

% Kaiser window
[HKaiser,W] = freqz(hLP.*kaiser(M+1, beta)',1);

%Plot 2: Filtered Signal
InputRot90 = rot90(s);
Output1 = HKaiser .* InputRot90 ;
FilteredSpectrum=fft(Output1);

omega=-pi:2*pi/length(FilteredSpectrum):pi-2*pi/length(FilteredSpectrum);
subplot(2,1,2) ;
plot(w, abs([FilteredSpectrum(1:256)]));
title('Filtered Signal Spectrum');
grid;

Subject: Why does the frequency spectrum shift?

From: Randy Poe

Date: 8 Nov, 2004 10:59:45

Message: 2 of 7

Bobby wrote:
> I've designed lowpass FIR filter with cutoff frequency 3kHz. I've
> plotted its magnitude and phase response which looks OK.
>
> Now I feed that filter with the signal which contains two frequencies
> 150 Hz and 4 kHz: s = 100*cos(300*pi*t + pi/4) + 20*cos(8000*pi*t -
> pi/3);
>
> The sampling frequency is 10 kHz
>
> In the following Matlab code I plot frequency spectrum of these
> original and filtered signals.
>
> On the first plot I can see two spikes which correspond to
frequencies
> 150 Hz and 4 kHz.

As far as I can tell, there seems to be confusion between
whether you are in the time or frequency domain.
>
> s = 100*cos(300*pi*t + pi/4) + 20*cos(8000*pi*t - pi/3);
>
> S = fft(s,512);

s is in the time domain, S in the frequency domain.
> % Kaiser window
> [HKaiser,W] = freqz(hLP.*kaiser(M+1, beta)',1);
>
> %Plot 2: Filtered Signal
> InputRot90 = rot90(s);
> Output1 = HKaiser .* InputRot90 ;

HKaiser appears to be the frequency-domain representation
of your filter (the transfer function, not the impulse
response). But you applied it to s, not S.

> FilteredSpectrum=fft(Output1);

Since you did your digital filtering by multiplication,
I surmise that Output1 is supposed to be in the freq
domain. But then you fft it again??

You need to figure out which domain you're in for
each step, and which one you want to be in.

           - Randy

Subject: Why does the frequency spectrum shift?

From: Bobby

Date: 9 Nov, 2004 00:56:40

Message: 3 of 7

Randy,

Thank you very much. Your post was very helpful.

Bobby

"Randy Poe" <poespam-trap@yahoo.com> wrote in message
news:1099940385.935745.213980@c13g2000cwb.googlegroups.com...
> Bobby wrote:
> > I've designed lowpass FIR filter with cutoff frequency 3kHz. I've
> > plotted its magnitude and phase response which looks OK.
> >
> > Now I feed that filter with the signal which contains two frequencies
> > 150 Hz and 4 kHz: s = 100*cos(300*pi*t + pi/4) + 20*cos(8000*pi*t -
> > pi/3);
> >
> > The sampling frequency is 10 kHz
> >
> > In the following Matlab code I plot frequency spectrum of these
> > original and filtered signals.
> >
> > On the first plot I can see two spikes which correspond to
> frequencies
> > 150 Hz and 4 kHz.
>
> As far as I can tell, there seems to be confusion between
> whether you are in the time or frequency domain.
> >
> > s = 100*cos(300*pi*t + pi/4) + 20*cos(8000*pi*t - pi/3);
> >
> > S = fft(s,512);
>
> s is in the time domain, S in the frequency domain.
> > % Kaiser window
> > [HKaiser,W] = freqz(hLP.*kaiser(M+1, beta)',1);
> >
> > %Plot 2: Filtered Signal
> > InputRot90 = rot90(s);
> > Output1 = HKaiser .* InputRot90 ;
>
> HKaiser appears to be the frequency-domain representation
> of your filter (the transfer function, not the impulse
> response). But you applied it to s, not S.
>
> > FilteredSpectrum=fft(Output1);
>
> Since you did your digital filtering by multiplication,
> I surmise that Output1 is supposed to be in the freq
> domain. But then you fft it again??
>
> You need to figure out which domain you're in for
> each step, and which one you want to be in.
>
> - Randy
>

Subject: Why does the frequency spectrum shift?

From: Kishore

Date: 2 Feb, 2009 00:20:02

Message: 4 of 7

Hi,
old thread revisited by a neophyte!!...

Well, it is true that the signal is filtered by multiplying, the actual signal and the frequency response of the signal ( both in time domain)...
So, there is no need for fft again.

My question is i tried the same code with the above said modification,but still i get the 4000 HZ component in the out put. I think i am missing some thing here..

secondly , when the omega vector is scaled by FS/2, the actual spectrum is shifted to left -but what is intended is only frequency components till FS/2 should be displayed.

Here is the modified code at the end

InputRot90 = rot90(S);
Output1 = HKaiser .* InputRot90 ; % filtered output
Output1 = Output1'; % transpose.


omega = (0:length(Output1)-1)*((Fs/2)/length(Output1)); % display till Fs/2 ??
subplot(2,1,2) ;
plot(omega(1:256), abs([Output1(1:256)]));


Can anybody help??

Thanks a lot..

Subject: Why does the frequency spectrum shift?

From: Kishore

Date: 2 Feb, 2009 00:36:02

Message: 5 of 7

correction..

signals multiplied in frequency domain..

Subject: Why does the frequency spectrum shift?

From: Kishore

Date: 7 Feb, 2009 14:47:12

Message: 6 of 7

can anybody pls reply??>


"Kishore " <kishore3385@yahoo.co.in> wrote in message <gm5f5h$974$1@fred.mathworks.com>...
> correction..
>
> signals multiplied in frequency domain..

Subject: Why does the frequency spectrum shift?

From: Kishore

Date: 7 Feb, 2009 15:02:02

Message: 7 of 7

Ok i got it...
thanks...

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com