help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: rebuild signal from frequency domain to time domain tia sal22


From: William Krekeler
Subject: RE: rebuild signal from frequency domain to time domain tia sal22
Date: Wed, 9 Mar 2011 14:45:50 +0000

 

 

From: address@hidden [mailto:address@hidden On Behalf Of Doug Stewart
Sent: Wednesday, March 09, 2011 8:34 AM
To: Rick T
Cc: address@hidden
Subject: Re: rebuild signal from frequency domain to time domain tia sal22

 

 

On Wed, Mar 9, 2011 at 7:30 AM, Rick T <address@hidden> wrote:

Doug thanks for the info and quick response on why and where the zeros get added but I'm still a little confused as how to fix it.

When I look at the values in the array ya and yb_ifft they should be the same (time domain values) but they aren't.  Do I really just start deleting values?

 

tia sal22

 

On Wed, Mar 9, 2011 at 2:20 AM, Doug Stewart <address@hidden> wrote:

 

 

 

On Wed, Mar 9, 2011 at 7:11 AM, Rick T <address@hidden> wrote:

I changed the lines following your example but I get an error nonconformant arguments

due to the fact that ya and yb_ifft are not the same size arrays did I miss something

the code I changed is below.

 

thanks for the quick response :-)

 

%signal from frequency domain to time domain

clear all

%create time domain

Fs = 1000; % Sampling frequency

T = 1/Fs; % Sample time

L = 1000; % Length of signal

t = (0:L-1)*T; % Time vector

ya = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);

 

%create frequency domain

NFFT = 2^nextpow2(L); % Next power of 2 from length of y

yb = fft(ya,NFFT)/L;

f = Fs/2*linspace(0,1,NFFT/2+1);

 

%frequency back to time domain

yb_ifft=ifft(yb);

freq_to_time=ya-yb_ifft; %array size isn't the same anymore

subplot(2,2,1),plot(Fs*t(1:50),ya(1:50))

title('Signal ')

xlabel('time (milliseconds)')

 

% Plot amplitude spectrum.

subplot(2,2,2),plot(f,2*abs(yb(1:NFFT/2+1)))

title('Amplitude Spectrum of y(t)')

xlabel('Frequency (Hz)')

ylabel('|Y(f)|')

 

subplot(2,2,3),plot(Fs*t(1:50),freq_to_time(1:50))

title('rebuild Spectrum of y(t)')

xlabel('Frequency (Hz)')

ylabel('|Y(f)|') 

 

On Wed, Mar 9, 2011 at 1:54 AM, Andy Buckle <address@hidden> wrote:

On Wed, Mar 9, 2011 at 11:45 AM, Rick T <address@hidden> wrote:
> rebuild signal from frequency domain to time domain tia sal22
> Greetings all
> I would like to rebuild a signal from the frequency domain
> can this be done using fft?  If so does anyone have some
> example code?
> Here's what I have so far.  I create/import a signal and plot
> using the time domain.  Then I use fft to convert to
> the frequency domain and plot.  What I want to do now is
> be able to convert from the frequency domain data back to the time
> domain.  Then I'll be able to export the file as a wave file
> PS: I won't have an equation to work with because I'll be importing
> an audio file, and I'll be making changes when the signal is
> in the frequency domain.
> But at the moment I'm just trying to convert from the
> frequency domain back to the time domain. So the third plot
> when created would look just like the first plot in the time domain
> in the example below
>
> %time domain
> %create time domain
> Fs = 1000;                    % Sampling frequency
> T = 1/Fs;                     % Sample time
> L = 1000;                     % Length of signal
> t = (0:L-1)*T;                % Time vector
> y = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
> %frequency domain
> NFFT = 2^nextpow2(L); % Next power of 2 from length of y
> Y = fft(y,NFFT)/L;
> f = Fs/2*linspace(0,1,NFFT/2+1);
> subplot(2,1,1),plot(Fs*t(1:50),y(1:50))
> title('Signal ')
> xlabel('time (milliseconds)')
> % Plot  amplitude spectrum.
> subplot(2,1,2),plot(f,2*abs(Y(1:NFFT/2+1)))
> title('Amplitude Spectrum of y(t)')
> xlabel('Frequency (Hz)')
> ylabel('|Y(f)|')
> tia sal22
> --

>y=rand(1,4)
y =

  0.683785   0.772539   0.065463   0.410841

>f=fft(y)
f =

 Columns 1 through 3:

  1.93263 + 0.00000i   0.61832 - 0.36170i  -0.43413 + 0.00000i

 Column 4:

  0.61832 + 0.36170i

>y2=ifft(f)
y2 =

  0.683785   0.772539   0.065463   0.410841

>y-y2
ans =

 0.0000e+000  0.0000e+000  4.1633e-017  5.5511e-017



--
/* andy buckle */



--
-

 

 

 

This will pad some zeros to your data , so yes they will now be different lengths.

NFFT = 2^nextpow2(L); % Next power of 2 from length of y

yb = fft(ya,NFFT)/L; 

 

 

Doug Stewart



-

 

 

Try not using

NFFT = 2^nextpow2(L); % Next power of 2 from length of y

 

The reason people use this line is to speed up the calculation ( ie powers of 2 are easier to do the FFT)

but I don't think this will bother you unless you have very large data sets.

just try this.

yb = fft(ya)/L;

 

Doug

 

If you specify an N point fft, you need to use an N point ifft to return to the original signal. I think the difference you are seeing is caused by taking an N point fft and and M point ifft where M is < N because octave is choosing M to be the length of the non-zero padded signal.

 

Try the equivalent of:

                yt = some time signal;

                Yf = fft( yt, N);   % frequency domain

                yt2 = ifft( Yf, N);                % return to time domain

 

                [ size(yt2) size(yt) ]         % compare

                max( yt2 - yt )                    % should be zero (theory) or very close to it (precision error)

 

Bill

 

 

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]