|
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 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: >y=rand(1,4)
-- 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 |
[Prev in Thread] | Current Thread | [Next in Thread] |