-1
$\begingroup$

Hello i ha built this code which create a only one replica of the data, how can i create the whole photo shown bellow of many cycles as shown bellow? i read in the internet that zero padding could create it,but its not wotking. How could it be done? Thanks.

f1=10;
f2=20;
f3=70;
% twice the sampling rate
Fs=2.05*70; % sampling frequency is a bit above 2 times to get all the peaks.
Ts=1/Fs;
Tn=0:Ts:1;
fft_L=length(Tn);
y4_samples=10*sin(2*pi*f1*Tn)+10*sin(2*pi*f2*Tn)+10*sin(2*pi*f3*Tn);
%stem(Tn_new,y4_samples);
ff=fft(y4_samples);
ff1 = abs(ff/fft_L);
fft2 = ff1(1:floor(fft_L/2)+1);
fft2(2:end) = 2*fft2(2:end);
f = Fs*(0:fft_L/2)/fft_L;
plot(f, fft2)

nyquist sampling

$\endgroup$
0
$\begingroup$

Try upsample command in MATLAB. Upsampling (interleaving by zeros) will create replicas of fourier transform. You can then re-label your x-axis appropriately. Example of fft of y4_samples upsampled by 4 below.

enter image description here

Adding code :

f1=10;
f2=20;
f3=70; 
% twice the sampling rate 
Fs=2.05*70; % sampling frequency is a bit above 2 times to get all the peaks. 
Ts=1/Fs;
Tn=0:Ts:1;
fft_L=length(Tn);
y4_samples=10*sin(2*pi*f1*Tn)+10*sin(2*pi*f2*Tn)+10*sin(2*pi*f3*Tn);
y5=upsample(y4_samples,4);
fft_L=fft_L*4; %update fft_L
%stem(Tn_new,y4_samples);
ff=fft(y5);
ff1 = abs(ff/fft_L);
f = Fs*(-fft_L/2:fft_L/2-1)/fft_L;
plot(f, ff1)
| improve this answer | |
$\endgroup$
  • $\begingroup$ could you please post the code of the upsample command you used to create these replicas? Thanks $\endgroup$ – rocko445 Apr 12 at 11:22
  • $\begingroup$ $y = upsample(x,4)$ is what I used here to create 4 replicas. $\endgroup$ – jithin Apr 12 at 11:34
  • $\begingroup$ Hello i Have tried to use the upsample command its not working as shown in the code bellow. Where did i go wrong? f1=10; f2=20; f3=70; % twice the sampling rate Fs=2.05*70; % sampling frequency is a bit above 2 times to get all the peaks. Ts=1/Fs; Tn=0:Ts:1; fft_L=length(Tn); y4_samples=10*sin(2*pif1*Tn)+10*sin(2*pif2*Tn)+10*sin(2*pi*f3*Tn); y5=upsample(y4_samples,4); %stem(Tn_new,y4_samples); ff=fft(y5); ff1 = abs(ff/fft_L); fft2 = ff1(1:floor(fft_L/2)+1); fft2(2:end) = 2*fft2(2:end); f = Fs*(0:fft_L/2)/fft_L; plot(f, fft2) $\endgroup$ – rocko445 Apr 22 at 15:07
  • $\begingroup$ There is a mistake in your code. When you did upsample by 4, your frequency axis length became 4 times. But you did not account for this. I will add the corrected code in my answer. I added line 11. $\endgroup$ – jithin Apr 22 at 15:29
  • $\begingroup$ You are plotting only positive frequencies. Is that enough? You do not want to show negative frequencies? $\endgroup$ – jithin Apr 22 at 15:31

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.