Dear fellows,i have modified code but i have problem in plotting the last figure(4) and problem is in this line plot(tvec,abs(zifft)).Problem was in my resolution in FFT.Can anyone edit my code please.
clc,close all,clear all
codn=100;
% fc=6e+3;
fs=36000;
bode=1000;
code=round(rand(1,codn));
code_len=round(1/bode/(1/fs))
for ii=1:codn
x((ii-1)*code_len+1:code_len*ii)=code(ii)
end
x2 = x-(1/2) % get rid of most of the dc peak
% set up time and frequency arrays
length(x)
N = length(x)
delt = 1/fs;
delf = fs/N;
tvec = (1:N)*delt;
n = 2^nextpow2(N);
fvec = (-n/2:n/2-1)*delf ; % shifted frequency array
figure(1)
plot(tvec,x2(1,:)+0.5)
title('orignal baseband')
xlabel('time');
ylabel('amplitude')
ylim([-1 1.5]);
y = fftshift(fft(x2,n));
z=abs(y);
figure(2)
plot(fvec,z)
title('FFT')
xlabel('frequency')
ylabel('amplitude')
figure(3)
z=y;
z(abs(fvec)>=50& abs(fvec)<=150)=0
plot(fvec,abs(y))
xlabel('frequency removed from 50 to 150 HZ');
ylabel('amplitude')
figure(4)
zf=fftshift(z)*n;
zifft=ifft(zf)+0.5;
plot(tvec,abs(zifft))
ylim([-1 1.5])
title('recovered signal')
xlabel('time');
ylabel('amplitude')

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 7일
편집: KALYAN ACHARJYA 2019년 11월 8일

0 개 추천

In the line no 44, see both variable have different lengths, how can plot two different lengths vectors
here
plot(tvec,abs(zifft))
##
>> whos tvec
Name Size Bytes Class Attributes
tvec 1x3600 28800 double
>> whos zifft
Name Size Bytes Class Attributes
zifft 1x4096 32768 double
Do change the code/equations, ensure that, in any plot all vectors must be same length.
Please check with back approach and see length of required variables why vectors reflects those having different lengths.

댓글 수: 7

imran khan
imran khan 2019년 11월 7일
sir i know vectors have different lengths but i don't know how to solve this issue can you please help me.
Daniel M
Daniel M 2019년 11월 7일
You can choose to change your tvec to reflect the usage of n, or you can take the ifft with N as second input.
imran khan
imran khan 2019년 11월 7일
i tried but can't figure out
imran khan
imran khan 2019년 11월 7일
i am using n dear not N
Daniel M
Daniel M 2019년 11월 7일
Read what I said again more carefully.
@Imran
Is this?
figure(4)
y=fftshift(fft(x2,length(tvec)));
z=y;
z(abs(fvec)>=50 & abs(fvec)<=150)=0
zf=fftshift(z)*n;
zifft=ifft(zf)+0.5;
plot(tvec,abs(zifft))
%ylim([-1 1.5])
title('recovered signal')
xlabel('time');
ylabel('amplitude')
56.png
imran khan
imran khan 2019년 11월 12일
no dear its not right.In time domain my signal should be close to figure(1) but with little bit distortion

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2019년 11월 7일

댓글:

2019년 11월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by