1
$\begingroup$

I'm trying to write a program using MATLAB that samples and recovers a given signal with different sampling frequencies

The given signal is $x(t) = \sin (2\pi 200 t)$ and sampling frequencies are $200$,$300$,$400$ and $500$ Hz.

I used sinc interpolation formula.

It is not working,and I would like to know why.

Can you help me?

The code is:

 f=200; 
 fs=[200,300,400,500]; % sampling frequencies
for i = 1:length(fs)        

 Ts = 1/fs(i); % Sampling Period
 t = 0:1e-4:6/f; % time vector for continous plot
 w = f*2*pi;  
 xa = sin(w*t); % signal in continuous form

 t2=(0:Ts:6/f);  % time vector for sampling
 xb = sin(w*t2); % sampled signal 

 figure
 subplot(311); 
 plot(t,xa) % continous signal plot
 str = ['Signal x(t) = (' num2str(f) ' Hz)', ', Fs = ' num2str(fs(i)) ' Hz']; 
 title(str); 
 ylabel('Amplitude');
 xlabel('Time(s)');

 subplot(312); 

 stem(t2,xb); % sampled signal plot 
 title('Sampled signal'); 
 ylabel('Amplitude') 
 xlabel('Samples'); 

 xr = zeros(length(t));
 for k=1:length(t)
 for p=1:length(xb)
 xr(k)=xr(k) + xb(p)*sinc(fs(i)*(k-t2(p)));
 end
 end
 subplot(313);
 plot(t,xr);
 title('Recovered signal');
 ylabel('Amplitude');
 xlabel('Time(s)');
end
$\endgroup$
  • $\begingroup$ Haven't looked at your code, but here's something similar: mathworks.com/matlabcentral/fileexchange/… $\endgroup$ – Atul Ingle Sep 8 '17 at 21:05
  • $\begingroup$ Those sampling frequencies will create aliasing except for $f_s=500$ Hz. I hope you're aware of this and know what you should expect. $\endgroup$ – Fat32 Sep 8 '17 at 21:12
  • $\begingroup$ I'm aware of that,but recovered signal is weird even with 500hz sampling $\endgroup$ – Mateus Sep 8 '17 at 21:22
  • $\begingroup$ Hi Mateus, if you got an answer to your question (it looks like you did), please consider accepting it. $\endgroup$ – jojek Jan 15 '18 at 11:26
1
$\begingroup$

This line is wrong:

xr(k)=xr(k) + xb(p)*sinc(fs(i)*(k-t2(p)));

The correct one is:

xr(k)=xr(k) + xb(p)*sinc( ((k-1)*Tr-(p-1)*Ts)/Ts );

Where $Ts$ is the original sampling period and $Tr$ is the reconstruction sampling period. In your code $Ts$ is given by $T_s = 1/500$ for sampling frequency of $500$ Hz. And $T_r = 10^{-4}$ set by your continuous plot period.

Note that you will still have slight errors due to the fact that the input signal is not being perfectly bandlimited.

Here is the resulting plot for $Fs=500$ Hz, $f_0 = 200$ Hz and $T_r=10^{-4}$ seconds: enter image description here

it's ok now.

$\endgroup$
  • 4
    $\begingroup$ you may accept the answer if it worked for you... $\endgroup$ – Fat32 Sep 8 '17 at 22:00
  • 1
    $\begingroup$ It sure has! Thank you so much! Sorry for my delay! $\endgroup$ – Mateus Sep 10 '18 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.