How can i fine the convolution of a linear system with given input

17 views (last 30 days)
Bhawana Garg on 15 Feb 2015
Commented: shah khan on 7 Apr 2018
I have an adc with linear transfer function h(n)in time domain , and input to this is x(n), a sampled sine wave ,output of adc should be linear convolution of h(n) and x(n).when I convert output into frequency domain using fft, i am getting the amplitude 4 times higher then the input, whereas Gain of ADC is 1.Anyone can please help in this regard
Bhawana Garg on 17 Feb 2015
Thanks for replying john.here is the code in which first i have simulated multifrequency signal then applied a window to it and took the FFT. Then simulated an ideal ADC and applied the signal to that adc and calculated the ouput.Finally calculated FFT of the output signal and compared with the FFT of input. Amplitudes at peaks should be almost same at both sides, which is not coming
% simulation of multifrequency signal fs=10000; % sampling frequency N=2048; % Number of samples k=1/fs; % Frequency Resolution f0=fs/N; f=(0:1:N-1)*f0; %Map the frequency to frequency bin amp_ip=[1.7,1.14]; freq_ip=[1000,1600]; phase_ip=[0,pi/8]; i=1; x1= amp_ip(i)*sin(2*pi*freq_ip(i)*(0:1:N-1)/fs +phase_ip(i)); i=2; x2= amp_ip(i)*sin(2*pi*freq_ip(i)*(0:1:N-1)/fs +phase_ip(i)); x=x1+x2;%+x3+x4; figure(1); plot(f,x); hold on;
%Convert into Frequency domain xf=(fft(x))/N; %compute the amplitude spectrum amp_xf=abs(xf); freq_bin=(0:1:N/2)*f0; amp_xf_ss(1)=amp_xf(1); amp_xf_ss(2:N/2+1)=2*amp_xf(2:N/2+1); % Get the single sided spectrum %subplot(2,1,2); plot(freq_bin,amp_xf_ss(1:N/2+1)); hold on;
figure(2); title('\fontname{Arial}FFT of Input signal','Fontsize',14,'Fontweight','Bold'); xlabel('\fontname{Arial} Frequency','Fontsize',12,'Fontweight','Bold'); ylabel('\fontname{Arial}Amplitude','Fontsize',12,'Fontweight','Bold');
% Generate different windows % Length of window is considered equal to number of samples
figure(3)
n=1:1:N;
x_rect=x(n).*rectwin(N)'; % Rectangular Window
plot(n,x_rect); title('\fontname{Arial}Rectangular Window','Fontsize',14,'Fontweight','Bold'); xlabel('\fontname{Arial} Frequency','Fontsize',12,'Fontweight','Bold'); ylabel('\fontname{Arial}Amplitude','Fontsize',12,'Fontweight','Bold'); hold on %FFT analysis of windowed signal amp_ip_rect_ss(1)=amp_ip_rect(1); amp_ip_rect_ss(2:N/2+1)=2*amp_ip_rect(2:N/2+1); % Get the single sided spectrum phase_ip_rect_ss=phase(amp_ip_rect1(1:N/2+1));
%estimation of peaks and their corresponding locations rough=amp_ip_rect_ss; [peak_rc,locs_rc,freq_rc]=PEAK(amp_ip_rect_ss,f); f0_ss=1/((N/2+1)*k);
nob=5; level=2^nob;
v_ref=5.12; lsb=v_ref/level; % lsb is least significant bit A=((level/2))*lsb;%max. value of amplitude L=(level/2)-1; Vmin(1,level)=0;
Vc(1,level)=0; Vmax(1,level)=0; CODE(1,level)=0; CODE_noise=0; qe_idl(1,level)=0;
figure(5); z=1; rough1=0; set(gcf, 'color', [1 1 1]) for j= -L-1:1:L+1%biplolar ADC (-128 to +127)
k=j+L+1; %(k=0 to 255)
z=k+1; %(z=1 to 256)
Vmin(z)=(j-0.5)*lsb; % min value at each code
Vc(z)=(j)*lsb; %mid value at each code
Vmax(z)= (j+0.5)*lsb; % max value at each code
CODE(z)=k; %equivalent digital output code
for i=Vmin(z):.001:Vmax(z)
% subplot(2,1,1);
stairs(i,k);
hold on;
%grid on;
for p=k:.1:k+1
plot(Vmax(z),p);
end
end
end
amp_ip_rect_ss=rough;
%Output of ADC for the applied input signal rectangular window CODE_rect=0;
for i=1:1:N for j=1:1:level-1 if (x_rect(i)>=Vmin(j) && x_rect(i)<=Vmin(j+1)) CODE_rect(i)=j-1; end end
end
CODE_rect=CODE_rect.*lsb;
figure(6);
P=length(CODE_OUT);
xf_rect=abs(fft(CODE_OUT))/P; %compute the amplitude spectrum
% Convert into single sided spectrum f11_rect=(0:1:P)*fs/P; xf1_rect(1)=xf_rect(1); %Single sided amplitude of output signal xf1_rect(2:P/2+1)=2*xf_rect(2:P/2+1); % Get the single sided spectrum %subplot(2,1,2); plot(f11_rect,xf_rect(1:P+1)); hold on;
rough=xf1_rect;
[pks_OAR,pks_OLR,pks_OFR]=PEAK(xf1_rect,f11_rect);
xf1_rect=rough;

Kamal Hussain on 7 Apr 2018
Edited: Kamal Hussain on 7 Apr 2018
here i have written a code for linear convolution using tabular method.
%linear convolution using tabular method
x=[1 2 3 4];
y=[1 2 3 4];
shift=0;
lin_conv=[zeros(1,length(x)+length(y)-1)];
for i=1:length(y)
shiftedd=shiftFTN(x,length(x),length(y),shift);
lin_conv=lin_conv + y(i).*shiftedd
shift=shift+1;
end
%i have used a self made function shiftFTN to shift the sequence to the right by 1.
function [Y]=shiftFTN(A,len_A,len_B,shift)
Y=zeros(1,len_A+len_B -1);
Y(shift+1:end)=[A(1:end),zeros(1,length(Y)-(shift+len_A))];
shah khan on 7 Apr 2018
great effort