⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inter_poly.m

📁 Interpolation FIR Design Example for Stratix Devices
💻 M
字号:
data_width = 18;    % Data input bit width
I = 4;              % Interpolation factor
max_data = 2^(data_width-1)-1;
min_data = -max_data;

% Filter Coefficients
coef=[-702 -22825 -32871 -21572 11845 58648 103632 131071 131071 103632 58648 11845 -21572 -32871 -22825 -702];
coef1=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];

  
%Impulse response

   Inp = zeros(300,1);
   Inp(10)=max_data;
   %Impulse Response Plotting
   figure(1);
   output = resample(Inp, I, 1, coef);
   impulse_output = output;
   sz = size(output);
   max_x = max(sz);
   xline = linspace (0, max_x - 1, max_x);
   plot (xline, output,'r');
   title ('Time Display of Impulse Response');
   grid on;
   zoom on;
   outfile1 = fopen('imp_in.txt','w');
	fprintf(outfile1, '%d ', Inp);
   fclose(outfile1);
   outfile1 = fopen('m_Inpulse_out.txt','w');
	fprintf(outfile1, '%d\n', output);
   fclose(outfile1);
   
   % Frequency Domain Plotting 
    to_plot = output;
    figure(2);
    freqdat = fft(to_plot);
    absdat = abs(freqdat);
    maxdat = max (absdat);
    logdat = 20*log10(absdat);
    sz = size(to_plot);
    numpts = max(sz);
    freq_res = 1/numpts;
    xline = linspace (0, ( (1/2)- freq_res ), round(numpts/2) );
   	plot (xline, logdat(1: round(numpts/2) ), 'b');
    title ('Frequency Display of Impulse Response');
    grid on;
    zoom on;
    xlabel ('Frequency');
    ylabel ('Magnitude - dB');
    
%Step Response
 
    step= zeros(300,1);
 	for	i=10:300
			step(i) = max_data;
	end;
	%step Response Plotting
    figure(3);
    output = resample(step, I, 1, coef);
    step_output = output;
    sz = size(output);
    max_x = max(sz);
    xline = linspace (0, max_x - 1, max_x);
  	plot (xline, output,'r');
    title ('Time Display of Step Response');
    grid on;
    zoom on;
    outfile2 = fopen('step_in.txt','w');
	fprintf(outfile2, '%d\n', step);
    fclose(outfile2);
      outfile2 = fopen('m_Step_out.txt','w');
	fprintf(outfile2, '%d\n', output);
    fclose(outfile2);
  
   % Frequency Domain Plotting 
    to_plot = output;
    figure(4);
    freqdat = fft(to_plot);
    absdat = abs(freqdat);
    maxdat = max (absdat);
    logdat = 20*log10(absdat);
    sz = size(to_plot);
    numpts = max(sz);
    freq_res = 1/numpts;
    xline = linspace (0, ( (1/2)- freq_res ), round(numpts/2) );
  	plot (xline, logdat(1: round(numpts/2) ), 'b');
    title ('Frequency Display of Step Response');
    grid on;
    zoom on;
    xlabel ('Frequency');
    ylabel ('Magnitude - dB');
    
%Ramdom Input

    random = round((rand(1, 100)-0.5)*(2^data_width-2)-1); 
    int_random = round(random);
    zero_init = zeros(10,1);
    zero_init = zero_init';
    int_random = [zero_init int_random];
    % Saturating Input Value
    a_in = find (int_random > max_data);
    b_in = find (int_random < min_data);
    if (~isempty(a_in)|~isempty(b_in))
         lenax = length (a_in);
         lenbx = length (b_in);
        for i = 1:lenax
             int_random(a_in(i)) = max_data;
        end
        for i = 1:lenbx
             int_random(b_in(i)) = min_data;
         end
    end
   %Random Response Plotting
   int_random = [0 0 0 0 0 0 0 0 0 0 -15784 -41931 -48702 -35370 -27987 23992 -99681 -121077 -10854];
    figure(5);
    output = resample(int_random, I, 1, coef);
    random_output = output;
    sz = size(output);
    max_x = max(sz);
    xline = linspace (0, max_x - 1, max_x);
  	plot (xline, output,'r');
    title ('Time Display of random Response');
    grid on;
    zoom on;
    outfile3 = fopen('rand_in.txt','w');
	fprintf(outfile3, '%d ', int_random);
	fclose(outfile3);
    outfile3 = fopen('m_Random_out.txt','w');
	fprintf(outfile3, '%d\n', output);
	fclose(outfile3);

  
    % Frequency Domain Plotting 
    to_plot = output;
    figure(6);
    freqdat = fft(to_plot);
    absdat = abs(freqdat);
    maxdat = max(absdat);
    logdat = 20*log10(absdat);
    sz = size(to_plot);
    numpts = max(sz);
    freq_res = 1/numpts;
    xline = linspace (0, ( (1/2)- freq_res ), round(numpts/2) );
   	plot (xline, logdat(1: round(numpts/2) ), 'b');
    title ('Frequency Display of Random Response');
    grid on;
    zoom on;
    xlabel ('Frequency');
    ylabel ('Magnitude - dB');
    
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -