MSP PROJECT
Frequency Isolation and Time-Varying
Filtering of a Chirp Signal.
NAME : S.LOKESH
SC CODE : SC24M077
BRANCH : M.TECH
DEPT : DSP
ABSTRACT:
Frequency Isolation and Time-Varying Filtering of a Chirp Signal
demonstrates the use of signal filtering techniques to analyze and
manipulate a chirp signal. The objectives are to isolate the lower-frequency
and higher-frequency portions of the chirp using low-pass and high-pass
filters, respectively. Additionally, a time-varying filter is designed to adapt
dynamically to the chirp’s frequency sweep. The results are visualized
through spectrograms to provide insights into the frequency isolation and
tracking capabilities of each filtering approach.
INTRODUCTION:
A chirp signal is a sinusoidal waveform whose frequency increases (up-chirp)
or decreases (down-chirp) over time. Chirps are widely used in radar, sonar,
and communication systems due to their unique spectral characteristics. In
this project, filtering techniques are applied to isolate specific frequency
components of a chirp signal and adapt to its dynamic frequency sweep.
The project consists of three main objectives:
1. Isolation of the lower-frequency portion of the chirp signal using a low-
pass filter.
2. Isolation of the higher-frequency portion of the chirp signal using a high-
pass filter.
3. Implementation of a time-varying filter to dynamically track the chirp’s
instantaneous frequency.
Chirp Signal Generation
A chirp signal is a signal where the frequency increases or decreases over
time. For this experiment, we generate a chirp signal with the following
parameters:
Sampling Frequency (Fs): 1000 Hz
Duration: 5 seconds
Start Frequency (f0): 0 Hz
End Frequency (f1): 500 Hz
Filter Design and Application
Three types of filters are applied to the chirp signal:
1. Low-pass filter: Allows frequencies below 150 Hz to pass and
attenuates higher frequencies.
2. High-pass filter: Allows frequencies above 350 Hz to pass and
attenuates lower frequencies.
3. Time-varying low-pass filter: The cutoff frequency changes
dynamically over time based on the chirp signal's frequency at each
point.
Spectrogram Analysis
A spectrogram is a visual representation of the signal's frequency content
over time. It is generated by applying a Short-Time Fourier Transform
(STFT) to the signal.
The cutoff frequency of the low-pass filter changes over time to match the
frequency of the chirp signal at each point. The filter dynamically adapts to
the chirp's frequency at every time step.
The following spectrograms are produced for each signal:
1. Original Chirp Signal: The spectrogram shows the frequency sweep
from 0 Hz to 500 Hz over 5 seconds.
2. Low-pass Filtered Signal: The spectrogram of the low-pass filtered
signal shows the retained lower frequencies (below 150 Hz), with
high-frequency components filtered out.
3. High-pass Filtered Signal: The spectrogram of the high-pass filtered
signal retains the higher frequencies (above 350 Hz) and filters out
the lower frequencies.
4. Time-varying Filtered Signal: The time-varying filter adapts its cutoff
frequency to follow the chirp signal’s frequency, producing a
spectrogram that adjusts to the frequency sweep.
PYTHON CODE IMPLEMENTATION AND PLOT
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import chirp, butter, filtfilt, spectrogram
# Define parameters
Fs = 1000 # Sampling frequency (Hz)
t = np.linspace(0, 5, Fs*5) # Time vector (5 seconds)
f0 = 0 # Start frequency (Hz)
f1 = 500 # End frequency (Hz)
# Generate the chirp signal
chirp_signal = chirp(t, f0, t[-1], f1)
# Low-pass filter design (cutoff at 150 Hz)
def butter_lowpass(cutoff, fs, order=4):
nyquist = 0.5 * fs
normal_cutoff = cutoff / nyquist
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return b, a
# High-pass filter design (cutoff at 350 Hz)
def butter_highpass(cutoff, fs, order=4):
nyquist = 0.5 * fs
normal_cutoff = cutoff / nyquist
b, a = butter(order, normal_cutoff, btype='high', analog=False)
return b, a
# Apply low-pass filter to isolate lower frequencies
b_low, a_low = butter_lowpass(150, Fs)
low_freq_signal = filtfilt(b_low, a_low, chirp_signal)
# Apply high-pass filter to isolate higher frequencies
b_high, a_high = butter_highpass(350, Fs)
high_freq_signal = filtfilt(b_high, a_high, chirp_signal)
# Time-varying filter implementation
time_varying_signal = np.zeros_like(chirp_signal) # Initialize the output
signal
window_size = int(Fs / 10) # Length of each window (100 ms)
# Ensure we have at least the filter length in each segment
min_segment_length = 30 # Minimum length for a segment to filter
(based on filter order)
# Process signal in windows with dynamic filtering
for i in range(len(t)):
# Dynamic cutoff frequency based on the chirp's frequency at time t(i)
cutoff_freq = f0 + (f1 - f0) * (t[i] / t[-1])
passband_freq = cutoff_freq - 20 # Adjust passband
# Ensure positive passband frequency
if passband_freq <= 0:
passband_freq = 1
# Design time-varying low-pass filter
b_tv, a_tv = butter_lowpass(passband_freq, Fs)
start_idx = max(i, 0)
end_idx = min(i + window_size, len(chirp_signal))
if end_idx - start_idx < min_segment_length:
continue
filtered_segment = filtfilt(b_tv, a_tv, chirp_signal[start_idx:end_idx])
time_varying_signal[start_idx:end_idx] = filtered_segment
# Plot Spectrograms for comparison
fig, axes = plt.subplots(4, 1, figsize=(10, 10))
# Spectrogram of the original chirp signal
axes[0].specgram(chirp_signal, NFFT=256, Fs=Fs, noverlap=250,
scale='dB')
axes[0].set_title('Original Chirp Signal')
# Spectrogram of the low-pass filtered signal
axes[1].specgram(low_freq_signal, NFFT=256, Fs=Fs, noverlap=250,
scale=’Db’)
axes[1].set_title(‘Low-Pass Filtered Signal’)
# Spectrogram of the high-pass filtered signal
axes[2].specgram(high_freq_signal, NFFT=256, Fs=Fs, noverlap=250,
scale='dB')
axes[2].set_title('High-Pass Filtered Signal')
# Spectrogram of the time-varying filtered signal
axes[3].specgram(time_varying_signal, NFFT=256, Fs=Fs, noverlap=250,
scale='dB')
axes[3].set_title('Time-Varying Filtered Signal')
plt.tight_layout()
plt.show()
Results and Analysis
Original Chirp Signal: The spectrogram shows a gradual increase
in frequency from 0 Hz to 500 Hz over time.
Low-pass Filtered Signal: The spectrogram shows only lower
frequencies, with the higher frequencies being attenuated (below 150
Hz).
High-pass Filtered Signal: The spectrogram shows only the
higher frequencies above 350 Hz, with lower frequencies filtered out.
Time-varying Filtered Signal: The spectrogram adapts to the
chirp's frequency, effectively following the frequency sweep of the
original signal while filtering frequencies that fall outside the time-
varying cutoff.
OUTPUT :
Conclusion
This analysis demonstrates how different filtering techniques can affect the
frequency content of a chirp signal. The low-pass and high-pass filters isolate
different portions of the frequency spectrum, while the time-varying filter
adapts to the signal’s changing frequency over time. Spectrograms are useful
in visualizing these changes, providing insight into the impact of each filter
on the signal's frequency characteristic