Prev: add_block for name of Blockset with SPACES??!!
Next: come and join www.pakdub.com a social network with full features like games, classifieds, forums, blogs and a lot more
From: kk KKsingh on 21 Feb 2010 00:17 Corrected code! Although its still giving me wrong results ! It will be great if some one can have a look on it In first loop i calculated DFT giving me correct result In second loop Its DFT for irregular samples clear all close all N=200; % Number sample points M=(N-1)/2; %Number of frequency points m=-M:M fo = 4; %frequency of the sine wave Fs = 50; %sampling rate Ts = 1/Fs; %sampling time interval t = 0:Ts:Ts*(N-1); %sampling period y = 2*sin(2*pi*fo*t); deltaf=2*pi/(N*Ts);%Defining the grid size of Fourier domain for k=1:length(m) freq = (-j*(2*pi/(N))*(k-1)); Wnk = exp(freq.*(0:length(t)-1)); X(k)=Ts*sum(y.*Wnk); end if mod(N,2)==0 k=-N/2:N/2-1; % N even else k=-(N-1)/2:(N-1)/2; % N odd end f=1/Ts/N*k; Y = fft(y); subplot(211); stem(f/max(abs(f)),fftshift(abs(X)/max(abs(X)))); title('DFT for Regular sampling') subplot(212); stem(f/max(abs(f)),fftshift(abs(Y)/max(abs(Y)))); title('FFT for Regular Sampling') numberOfIndexes = length(t) scrambledIndexes = randperm(numberOfIndexes) halfOfTheIndexes = scrambledIndexes(1:floor(length(scrambledIndexes)/2)); halfOfTheIndexes = sort(halfOfTheIndexes) yHalf = y(halfOfTheIndexes) tHalf = t(halfOfTheIndexes) plot(tHalf, yHalf) xlabel('tHalf'); ylabel('yHalf'); N1=length(tHalf) deltax=Ts; deltak=2*pi/length(tHalf)*deltax; Period=max(tHalf)-min(tHalf); deltax_n=zeros(N1,1) deltax_n(1,:)=(tHalf(1)-(tHalf(N1-1)-Period))/2 deltax_n(N1,:)=(tHalf(N1)-(tHalf(N1-2)-Period))/2 for j=2:N1-1; deltax_n(j,:)= deltax_n(j,:)+((tHalf(j+1)-tHalf(j-1))/2) end X1 = zeros(size(yHalf)); for k=1:N1 for j=1:N1 freq = (-1j*(2*pi/(N1*Ts))*(k-1)); Wnk = exp(freq.*tHalf(k)); X1(k)=deltax_n(j)*sum(yHalf'.*Wnk); end end if mod(N1,2)==0 k=-N1/2:N1/2-1; % N even else k=-(N1-1)/2:(N1-1)/2; % N odd end f1=1/Ts/N1*k; figure(2) stem(f1/max(abs(f1)),fftshift(abs(X1)/max(abs(X1))))
From: Rune Allnor on 21 Feb 2010 03:11 On 21 Feb, 01:51, "kk KKsingh" <akikumar1...(a)gmail.com> wrote: > Just wondering any body has written DFT for the irregular samples...I wrote a code but its wrong some where ! > > DFT for irregular samples are based on Reinmann sum method where instead of multiplying with dt we multiply we dt=t(n+1)-t(n-1)/2 and use original sample location t(n) Plain wrong. I don't know what a 'Reinman sum' is, but I assume you might have misspelled the name 'Riemann'. Now, like it or not, but that's the kind of trivial mistake, blunder, flaw - call it what you want - that has proved to be typical of your efforts. > I apologise if you think that its a trivial problem! But i tried a lot to solve this It *is* a trivial problem. You only need to understand what you are doing. But it's utterly totally essential that you *do* understand the basics. Rune
From: kk KKsingh on 21 Feb 2010 03:32 I am just trying to code a algorithm, I read in Paper ! And I was seeking some help in coding for that here is the detail of algorithm : This is for Irregular samples, I am trying to code : P=sum{n=0:N-1}x(n)exp(j*m*df*x(n))*delta_t df=2*pi/(N*dt) m=-M/2:M/2-1 [M is frequency point] l_{n}=(t_{n}+t_{n-1})/2 is the midpoint between two samples delta_t=l_(n+1)-l_{n} delta_t=t_{n+1}-t_{n-1}/2 I am just trying to code above ! If you can tell me how to write it in matlab without blunder that will be great ! I tried above and didnt get the right answer,,,,I wrote a code below for this for missing sin samples but didnt get the answer ...I am sorry if its trivial for you Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <24738d11-bf6b-4a3f-98b4-3c25d8fbd791(a)z35g2000yqd.googlegroups.com>... > On 21 Feb, 01:51, "kk KKsingh" <akikumar1...(a)gmail.com> wrote: > > Just wondering any body has written DFT for the irregular samples...I wrote a code but its wrong some where ! > > > > DFT for irregular samples are based on Reinmann sum method where instead of multiplying with dt we multiply we dt=t(n+1)-t(n-1)/2 and use original sample location t(n) > > Plain wrong. I don't know what a 'Reinman sum' is, but I assume > you might have misspelled the name 'Riemann'. Now, like it or not, > but that's the kind of trivial mistake, blunder, flaw - call it > what you want - that has proved to be typical of your efforts. > > > I apologise if you think that its a trivial problem! But i tried a lot to solve this > > It *is* a trivial problem. You only need to understand what you > are doing. But it's utterly totally essential that you *do* > understand the basics. > > Rune
From: kk KKsingh on 21 Feb 2010 03:47 Correction P=sum{n=0:N-1}x(n)exp(j*m*df*t(n))*delta_t There is t(n) not x(n)....Whole issue is this this algorithm gives best result for irregular samples in most of the IEEE paper i have seen ....And i am sure that i am making some mistake thats why seeking help "kk KKsingh" <akikumar1983(a)gmail.com> wrote in message <hlqr24$fc0$1(a)fred.mathworks.com>... > > > > I am just trying to code a algorithm, I read in Paper ! And I was seeking some help in coding for that here is the detail of algorithm : > > This is for Irregular samples, I am trying to code : > > P=sum{n=0:N-1}x(n)exp(j*m*df*x(n))*delta_t > > df=2*pi/(N*dt) > m=-M/2:M/2-1 [M is frequency point] > > l_{n}=(t_{n}+t_{n-1})/2 is the midpoint between two samples > delta_t=l_(n+1)-l_{n} > delta_t=t_{n+1}-t_{n-1}/2 > > I am just trying to code above ! If you can tell me how to write it in matlab without blunder that will be great ! I tried above and didnt get the right answer,,,,I wrote a code below for this for missing sin samples but didnt get the answer ...I am sorry if its trivial for you > > > > > > > > > > Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <24738d11-bf6b-4a3f-98b4-3c25d8fbd791(a)z35g2000yqd.googlegroups.com>... > > On 21 Feb, 01:51, "kk KKsingh" <akikumar1...(a)gmail.com> wrote: > > > Just wondering any body has written DFT for the irregular samples...I wrote a code but its wrong some where ! > > > > > > DFT for irregular samples are based on Reinmann sum method where instead of multiplying with dt we multiply we dt=t(n+1)-t(n-1)/2 and use original sample location t(n) > > > > Plain wrong. I don't know what a 'Reinman sum' is, but I assume > > you might have misspelled the name 'Riemann'. Now, like it or not, > > but that's the kind of trivial mistake, blunder, flaw - call it > > what you want - that has proved to be typical of your efforts. > > > > > I apologise if you think that its a trivial problem! But i tried a lot to solve this > > > > It *is* a trivial problem. You only need to understand what you > > are doing. But it's utterly totally essential that you *do* > > understand the basics. > > > > Rune
From: kk KKsingh on 21 Feb 2010 04:07
Well, I think i am aware of basics but still i will try to correct the DFT basics if i am wrong, But if some body can guide me where i am wrong in writing the code for above ...It will help me a lot Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <24738d11-bf6b-4a3f-98b4-3c25d8fbd791(a)z35g2000yqd.googlegroups.com>... > On 21 Feb, 01:51, "kk KKsingh" <akikumar1...(a)gmail.com> wrote: > > Just wondering any body has written DFT for the irregular samples...I wrote a code but its wrong some where ! > > > > DFT for irregular samples are based on Reinmann sum method where instead of multiplying with dt we multiply we dt=t(n+1)-t(n-1)/2 and use original sample location t(n) > > Plain wrong. I don't know what a 'Reinman sum' is, but I assume > you might have misspelled the name 'Riemann'. Now, like it or not, > but that's the kind of trivial mistake, blunder, flaw - call it > what you want - that has proved to be typical of your efforts. > > > I apologise if you think that its a trivial problem! But i tried a lot to solve this > > It *is* a trivial problem. You only need to understand what you > are doing. But it's utterly totally essential that you *do* > understand the basics. > > Rune |