Can someone please show me the code for the COMPLETE Chirp frequency response? I will include possible code needed, incl
Posted: Mon May 09, 2022 7:11 am
Can someone please show me the code for the COMPLETE Chirp frequency response? I will include possible code needed, including the individual Chirp frequency response.
Function for plot_freq_resp_magnitude (magnitude and gain mean the same thing here):
function plot_freq_resp_gain(f,H)
gainValue = 20*log10(abs(H));
plot(f, gainValue);
xlabel('Normal Freq in Hz');
ylabel('Gain in dB');
ylim([-100 10]);
grid on
end
Function for convolve:
function y = convolve(h,x)
N=length(x);
M=length(h);
m=M+N-1;
y=zeros(1,m);
xn=[x zeros(1,m-N)];
hn=[h zeros(1,m-M)];
for i=1:m
for j=1:i
y(i)=y(i)+xn(j)*hn(i-j+1);
end
end
disp(y)
end
Function for average power:
function pwr = avg_pwr(x)
siz = length(x)
sum = 0
for i = 1:siz
sum = sum + abs(x(i)*x(i));
end
pwr = sum/siz;
end
Function for Individual Chirp Frequency Response:
clc
close all
M = 256;
L = 256;
n = 0:M*L;
max_freq = 0.5;
x = chirp(n, 0, M*L, max_freq);
spectrogram(x, L, 0, L, 1, 'yaxis');
h = ones(1,10)*0.1;
% change this function to convolve function u have written.
y = conv(x,h);
figure
spectrogram(y, L, 0, L, 1, 'yaxis');
f = zeros(1, 256);
H = zeros(1, 256);
for n=(1:M)
f(n) = f_i(n*L-L/2);
start_s = 1 + (n-1)*L;
end_s = n*L;
P = avg_pwr(y(start_s:end_s));
H(n) = sqrt(2*P);
end
figure
plot(f,H);
title('Power Spectral Density');xlabel('Frequency(Hz)');ylabel('Average Power');
function power = avg_pwr(x)
power = sqrt(sum(x.^2))/length(x);
end
function freq = f_i(t)
freq = (0.5/256) *floor(t/256);
end
3.2 Assignment: Measure Complete Frequency Response Write a function that uses a chirp to measure the frequency response over a grid of M evenly spaced frequencies fd. Your function should contain code to . Construct a chirp of length M L samples, • Pass the chirp signal to a system that is passed as an input to your function, • Extract the magnitude of the frequency response from the output of the filter. Your function should be structured like this: function [H, f] - measure_freq_resp_chirp (sys_f_handle, M, L) % measure_freq_resp_chirp - measure the frequency response using a chirp H - measure_freq_resp_chirp (sys_f_handle 1, M] L]) g g g $ g g g g Input Variables: sys_f_hanfle - function handle to LTI system, will be invoked as y - sys_f_handle(x) M - number of blocks for computing average power L - number of samples per block g Output Variable: H - complex vector of length M; measured frequency response f - real vector of length M; frequency grid $check inputs if !isa (sys_f_handle, 'function_handle') error('measure_freq_resp: first input must be a function handle') end if nargin < 2 11 isempty (M) M - 512; end if nargin <3 || isempty (L) L-256; end %% Construct a chirp your code goes here 8% filter the chirp your code goes here %% Extract magnitude of frequency response $ your code goes here
Function for plot_freq_resp_magnitude (magnitude and gain mean the same thing here):
function plot_freq_resp_gain(f,H)
gainValue = 20*log10(abs(H));
plot(f, gainValue);
xlabel('Normal Freq in Hz');
ylabel('Gain in dB');
ylim([-100 10]);
grid on
end
Function for convolve:
function y = convolve(h,x)
N=length(x);
M=length(h);
m=M+N-1;
y=zeros(1,m);
xn=[x zeros(1,m-N)];
hn=[h zeros(1,m-M)];
for i=1:m
for j=1:i
y(i)=y(i)+xn(j)*hn(i-j+1);
end
end
disp(y)
end
Function for average power:
function pwr = avg_pwr(x)
siz = length(x)
sum = 0
for i = 1:siz
sum = sum + abs(x(i)*x(i));
end
pwr = sum/siz;
end
Function for Individual Chirp Frequency Response:
clc
close all
M = 256;
L = 256;
n = 0:M*L;
max_freq = 0.5;
x = chirp(n, 0, M*L, max_freq);
spectrogram(x, L, 0, L, 1, 'yaxis');
h = ones(1,10)*0.1;
% change this function to convolve function u have written.
y = conv(x,h);
figure
spectrogram(y, L, 0, L, 1, 'yaxis');
f = zeros(1, 256);
H = zeros(1, 256);
for n=(1:M)
f(n) = f_i(n*L-L/2);
start_s = 1 + (n-1)*L;
end_s = n*L;
P = avg_pwr(y(start_s:end_s));
H(n) = sqrt(2*P);
end
figure
plot(f,H);
title('Power Spectral Density');xlabel('Frequency(Hz)');ylabel('Average Power');
function power = avg_pwr(x)
power = sqrt(sum(x.^2))/length(x);
end
function freq = f_i(t)
freq = (0.5/256) *floor(t/256);
end
3.2 Assignment: Measure Complete Frequency Response Write a function that uses a chirp to measure the frequency response over a grid of M evenly spaced frequencies fd. Your function should contain code to . Construct a chirp of length M L samples, • Pass the chirp signal to a system that is passed as an input to your function, • Extract the magnitude of the frequency response from the output of the filter. Your function should be structured like this: function [H, f] - measure_freq_resp_chirp (sys_f_handle, M, L) % measure_freq_resp_chirp - measure the frequency response using a chirp H - measure_freq_resp_chirp (sys_f_handle 1, M] L]) g g g $ g g g g Input Variables: sys_f_hanfle - function handle to LTI system, will be invoked as y - sys_f_handle(x) M - number of blocks for computing average power L - number of samples per block g Output Variable: H - complex vector of length M; measured frequency response f - real vector of length M; frequency grid $check inputs if !isa (sys_f_handle, 'function_handle') error('measure_freq_resp: first input must be a function handle') end if nargin < 2 11 isempty (M) M - 512; end if nargin <3 || isempty (L) L-256; end %% Construct a chirp your code goes here 8% filter the chirp your code goes here %% Extract magnitude of frequency response $ your code goes here