<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199</link>
    <title>MATLAB Central Newsreader - Ifft on modified array fails</title>
    <description>Feed for thread: Ifft on modified array fails</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 06 Nov 2009 19:36:04 -0500</pubDate>
      <title>Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#692758</link>
      <author>Travis Bland</author>
      <description>My end goal is to take an array, fft, set a range of frequencies equal to 0, and then ifft.&lt;br&gt;
I get stuck once i set anything equal to 0. My ifft output is still complex. I stopped using my code, and just got an array in the workspace, manually changed a few entries to 0, and then tried plot(ifft(vf)) - i got scribbles, and complex results.&lt;br&gt;
&lt;br&gt;
So i looked at some old code a friend wrote, he puts this in before he sets to 0. It's c++&lt;br&gt;
&lt;br&gt;
for (int i = 0; i &amp;lt; nx; i++)&lt;br&gt;
{&lt;br&gt;
	for (int j = 0; j &amp;lt; nyp; j++)&lt;br&gt;
	{&lt;br&gt;
		real(output1(i,j)) = real(output1(i,j))               /* sqrt(nx*ny)*/; &lt;br&gt;
		imag(output1(i,j)) = imag(output1(i,j))           /* sqrt(nx*ny)*/; &lt;br&gt;
	}&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
So i tried real(vf) = real(vf).... matlab didn't like that.&lt;br&gt;
&lt;br&gt;
Any ideas?&lt;br&gt;
Thanks, &lt;br&gt;
&amp;nbsp;Travis</description>
    </item>
    <item>
      <pubDate>Fri, 06 Nov 2009 21:10:21 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#692788</link>
      <author>Matt </author>
      <description>&quot;Travis Bland&quot; &amp;lt;travisbland88@yahoo.com&amp;gt; wrote in message &amp;lt;hd1tr4$9lk$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; My end goal is to take an array, fft, set a range of frequencies equal to 0, and then ifft.&lt;br&gt;
&amp;gt; I get stuck once i set anything equal to 0. My ifft output is still complex. I stopped using my code, and just got an array in the workspace, manually changed a few entries to 0, and then tried plot(ifft(vf)) - i got scribbles, and complex results.&lt;br&gt;
=======&lt;br&gt;
&lt;br&gt;
We need to see more.&lt;br&gt;
&lt;br&gt;
Why do you expect to get real output from the ifft? Is it a symmetric spectrum? Are the frequencies being set to 0 in such a way as to preserve this symmetry? </description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 04:01:02 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#692846</link>
      <author>Travis Bland</author>
      <description>&quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd23bt$l4f$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Travis Bland&quot; &amp;lt;travisbland88@yahoo.com&amp;gt; wrote in message &amp;lt;hd1tr4$9lk$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; My end goal is to take an array, fft, set a range of frequencies equal to 0, and then ifft.&lt;br&gt;
&amp;gt; &amp;gt; I get stuck once i set anything equal to 0. My ifft output is still complex. I stopped using my code, and just got an array in the workspace, manually changed a few entries to 0, and then tried plot(ifft(vf)) - i got scribbles, and complex results.&lt;br&gt;
&amp;gt; =======&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; We need to see more.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Why do you expect to get real output from the ifft? Is it a symmetric spectrum? Are the frequencies being set to 0 in such a way as to preserve this symmetry? &lt;br&gt;
&lt;br&gt;
Yes and yes. It is a symmetric spectrum and i believe i modified it to preserve that. It's data taken from ice samples in antarctica. And i guess i just assumed a complex answer was wrong, if i can just do abs(vt) and get good results, that's fine with me.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Here's some of my code, i just copied the parts for 0-100 mhz (and left 100-1000 out)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
load std000.txt&lt;br&gt;
vt=std000(:,2)&lt;br&gt;
&lt;br&gt;
%power of vt over entire length of data file&lt;br&gt;
for n = 1:length(vt) ;&lt;br&gt;
vt_s = vt_s + (vt(n) .^2);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
vf = (fft(vt));&lt;br&gt;
vf_s =0;&lt;br&gt;
&lt;br&gt;
%power of vf over entire file&lt;br&gt;
for k= 1:length(vt);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;vf_s = vf_s + (abs( (vf(k)/sqrt(N)) .^2));&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% 0 - 100 mhz removed&lt;br&gt;
freq100 = vf;&lt;br&gt;
bandwidth = 2000000000;&lt;br&gt;
N = length(vt);&lt;br&gt;
bin_ratio = bandwidth / N;&lt;br&gt;
low_cut = 1  ;    % user defined--- low cutoff &lt;br&gt;
high_cut = 100  ;  % user defined--- high cutoff &lt;br&gt;
low_bin = (low_cut * 1000000) / ( bin_ratio);&lt;br&gt;
high_bin = (high_cut * 1e6) / (  bin_ratio);&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
high_bin = ceil(high_bin);&lt;br&gt;
low_bin = floor(low_bin);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
for i = 1:high_bin;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;freq100(i) = 0;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
for p = (N - high_bin):(N - low_bin);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;freq100(p) = 0;&lt;br&gt;
end &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
%skipping through same calculations for different frequency ranges... we get to the %summation section&lt;br&gt;
&lt;br&gt;
vt_100 = ifft(freq100);&lt;br&gt;
vt_100_s = 0;&lt;br&gt;
for n = 1:length(vt) ;&lt;br&gt;
&amp;nbsp;vt_100_s = vt_100_s + (vt_100(n) .^2);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thanks!</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 15:12:01 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#692898</link>
      <author>Matt </author>
      <description>&quot;Travis Bland&quot; &amp;lt;travisbland88@yahoo.com&amp;gt; wrote in message &amp;lt;hd2rdu$l9g$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; high_bin = ceil(high_bin);&lt;br&gt;
&amp;gt; low_bin = floor(low_bin);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i = 1:high_bin;&lt;br&gt;
&amp;gt;     freq100(i) = 0;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for p = (N - high_bin):(N - low_bin);&lt;br&gt;
&amp;gt;     freq100(p) = 0;&lt;br&gt;
&amp;gt; end &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I don't see anything symmetric in this truncation. &lt;br&gt;
&lt;br&gt;
The important thing to remember is that, for a given index k, if you set &lt;br&gt;
freq100(k)=0, then you must also set &lt;br&gt;
freq100(N+1-k)=0 to preserve conjugate symmetry of the spectrum. &lt;br&gt;
&lt;br&gt;
So, if you set freq100(1:high_bin)=0, as above, you must also set&lt;br&gt;
freq100(N+1-(1:high_bin))=0 as well</description>
    </item>
    <item>
      <pubDate>Sat, 07 Nov 2009 16:04:01 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#692899</link>
      <author>Matt </author>
      <description>&quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd42o1$re2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; The important thing to remember is that, for a given index k, if you set &lt;br&gt;
&amp;gt; freq100(k)=0, then you must also set &lt;br&gt;
&amp;gt; freq100(N+1-k)=0 to preserve conjugate symmetry of the spectrum. &lt;br&gt;
&lt;br&gt;
Make that freq100(N+2-k)=0</description>
    </item>
    <item>
      <pubDate>Sun, 08 Nov 2009 08:17:03 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#692966</link>
      <author>Travis Bland</author>
      <description>&quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd45ph$3ij$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd42o1$re2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The important thing to remember is that, for a given index k, if you set &lt;br&gt;
&amp;gt; &amp;gt; freq100(k)=0, then you must also set &lt;br&gt;
&amp;gt; &amp;gt; freq100(N+1-k)=0 to preserve conjugate symmetry of the spectrum. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Make that freq100(N+2-k)=0&lt;br&gt;
&lt;br&gt;
Well i could be mistaken but i think that's what i'm doing, i just do it in the second for loop. The plot is reflected at 1000mhz, when i run the code and remove   0-100mhz, 1900-2000mhz is also removed... so it stays symmetric, visually at least.&lt;br&gt;
&lt;br&gt;
Is it deeper that? If i'm just wrong, i can accept that, take your advice and move on; i'm good at that! :) &lt;br&gt;
&lt;br&gt;
thanks for your time!</description>
    </item>
    <item>
      <pubDate>Sun, 08 Nov 2009 16:27:01 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#693029</link>
      <author>Matt </author>
      <description>&quot;Travis Bland&quot; &amp;lt;travisbland88@yahoo.com&amp;gt; wrote in message &amp;lt;hd5upv$nr4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd45ph$3ij$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd42o1$re2$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; The important thing to remember is that, for a given index k, if you set &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; freq100(k)=0, then you must also set &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; freq100(N+1-k)=0 to preserve conjugate symmetry of the spectrum. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Make that freq100(N+2-k)=0&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Well i could be mistaken but i think that's what i'm doing, i just do it in the second for loop. The plot is reflected at 1000mhz, when i run the code and remove   0-100mhz, 1900-2000mhz is also removed... so it stays symmetric, visually at least.&lt;br&gt;
===============&lt;br&gt;
&lt;br&gt;
Well, visual tests can be misleading when the discrepancies are too small to show up noticably in a plot.  &lt;br&gt;
&lt;br&gt;
One clue here that something is wrong is that the number of steps in your first for-loop is high_bins, while the 2nd for-loop runs over &lt;br&gt;
high_bins-low_bins+1 elements. So, the two loops are just not going to even be of the same length (let alone be symmetric) unless low_bins=1. If low_bins is equal to 1 all the time, I don't know why you would have it in there as a variable.&lt;br&gt;
&lt;br&gt;
It occurs to me that maybe you want your first for-loop to start from low_bins instead of from 1, e.g.&lt;br&gt;
&lt;br&gt;
for i = low_bin:high_bin;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;freq100(i) = 0;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
If so, you still need to make sure the 2nd for-loop uses the N+2-k rule, so it should be&lt;br&gt;
&lt;br&gt;
range=low_bin:high_bin;&lt;br&gt;
&lt;br&gt;
range(range==1)=[];  %No need to include DC&lt;br&gt;
&lt;br&gt;
symrange=N+2-range; %The symmetric counterpart using the N+2-k rule&lt;br&gt;
&lt;br&gt;
for p = symrange&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;freq100(p) = 0;&lt;br&gt;
end </description>
    </item>
    <item>
      <pubDate>Sun, 08 Nov 2009 20:30:05 -0500</pubDate>
      <title>Re: Ifft on modified array fails</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265199#693071</link>
      <author>Matt </author>
      <description>&quot;Matt &quot; &amp;lt;xys@whatever.com&amp;gt; wrote in message &amp;lt;hd6rgl$kgj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; for i = low_bin:high_bin;&lt;br&gt;
&amp;gt;     freq100(i) = 0;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If so, you still need to make sure the 2nd for-loop uses the N+2-k rule, so it should be&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; range=low_bin:high_bin;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; range(range==1)=[];  %No need to include DC&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; symrange=N+2-range; %The symmetric counterpart using the N+2-k rule&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for p = symrange&lt;br&gt;
&amp;gt;     freq100(p) = 0;&lt;br&gt;
&amp;gt; end &lt;br&gt;
&lt;br&gt;
Also, you would really do well to get acquainted with MATLAB's vector indexing operations and get rid of these for loops:&lt;br&gt;
&lt;br&gt;
%For-loop Free !!!!&lt;br&gt;
&lt;br&gt;
range=low_bin:high_bin;&lt;br&gt;
symrange=N+2-range(range~=1);&lt;br&gt;
&lt;br&gt;
freq100(range)=0;  &lt;br&gt;
freq100(symrange)=0;</description>
    </item>
  </channel>
</rss>

